You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
3.3 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..compat import compat_urlparse
  5. from ..utils import (
  6. fix_xml_ampersands,
  7. float_or_none,
  8. xpath_with_ns,
  9. xpath_text,
  10. )
  11. class KarriereVideosIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?karrierevideos\.at(?:/[^/]+)+/(?P<id>[^/]+)'
  13. _TESTS = [{
  14. 'url': 'http://www.karrierevideos.at/berufsvideos/mittlere-hoehere-schulen/altenpflegerin',
  15. 'info_dict': {
  16. 'id': '32c91',
  17. 'ext': 'flv',
  18. 'title': 'AltenpflegerIn',
  19. 'description': 'md5:dbadd1259fde2159a9b28667cb664ae2',
  20. 'thumbnail': r're:^http://.*\.png',
  21. },
  22. 'params': {
  23. # rtmp download
  24. 'skip_download': True,
  25. }
  26. }, {
  27. # broken ampersands
  28. 'url': 'http://www.karrierevideos.at/orientierung/vaeterkarenz-und-neue-chancen-fuer-muetter-baby-was-nun',
  29. 'info_dict': {
  30. 'id': '5sniu',
  31. 'ext': 'flv',
  32. 'title': 'Väterkarenz und neue Chancen für Mütter - "Baby - was nun?"',
  33. 'description': 'md5:97092c6ad1fd7d38e9d6a5fdeb2bcc33',
  34. 'thumbnail': r're:^http://.*\.png',
  35. },
  36. 'params': {
  37. # rtmp download
  38. 'skip_download': True,
  39. }
  40. }]
  41. def _real_extract(self, url):
  42. video_id = self._match_id(url)
  43. webpage = self._download_webpage(url, video_id)
  44. title = (self._html_search_meta('title', webpage, default=None)
  45. or self._search_regex(r'<h1 class="title">([^<]+)</h1>', webpage, 'video title'))
  46. video_id = self._search_regex(
  47. r'/config/video/(.+?)\.xml', webpage, 'video id')
  48. # Server returns malformed headers
  49. # Force Accept-Encoding: * to prevent gzipped results
  50. playlist = self._download_xml(
  51. 'http://www.karrierevideos.at/player-playlist.xml.php?p=%s' % video_id,
  52. video_id, transform_source=fix_xml_ampersands,
  53. headers={'Accept-Encoding': '*'})
  54. NS_MAP = {
  55. 'jwplayer': 'http://developer.longtailvideo.com/trac/wiki/FlashFormats'
  56. }
  57. def ns(path):
  58. return xpath_with_ns(path, NS_MAP)
  59. item = playlist.find('./tracklist/item')
  60. video_file = xpath_text(
  61. item, ns('./jwplayer:file'), 'video url', fatal=True)
  62. streamer = xpath_text(
  63. item, ns('./jwplayer:streamer'), 'streamer', fatal=True)
  64. uploader = xpath_text(
  65. item, ns('./jwplayer:author'), 'uploader')
  66. duration = float_or_none(
  67. xpath_text(item, ns('./jwplayer:duration'), 'duration'))
  68. description = self._html_search_regex(
  69. r'(?s)<div class="leadtext">(.+?)</div>',
  70. webpage, 'description')
  71. thumbnail = self._html_search_meta(
  72. 'thumbnail', webpage, 'thumbnail')
  73. if thumbnail:
  74. thumbnail = compat_urlparse.urljoin(url, thumbnail)
  75. return {
  76. 'id': video_id,
  77. 'url': streamer.replace('rtmpt', 'rtmp'),
  78. 'play_path': 'mp4:%s' % video_file,
  79. 'ext': 'flv',
  80. 'title': title,
  81. 'description': description,
  82. 'thumbnail': thumbnail,
  83. 'uploader': uploader,
  84. 'duration': duration,
  85. }