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.

188 lines
7.2 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from .generic import GenericIE
  6. from ..utils import (
  7. determine_ext,
  8. ExtractorError,
  9. qualities,
  10. int_or_none,
  11. parse_duration,
  12. unified_strdate,
  13. xpath_text,
  14. parse_xml,
  15. )
  16. class ARDMediathekIE(InfoExtractor):
  17. IE_NAME = 'ARD:mediathek'
  18. _VALID_URL = r'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.daserste\.de)/(?:.*/)(?P<video_id>[0-9]+|[^0-9][^/\?]+)[^/\?]*(?:\?.*)?'
  19. _TESTS = [{
  20. 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht',
  21. 'only_matching': True,
  22. }, {
  23. 'url': 'http://www.ardmediathek.de/tv/Tatort/Das-Wunder-von-Wolbeck-Video-tgl-ab-20/Das-Erste/Video?documentId=22490580&bcastId=602916',
  24. 'info_dict': {
  25. 'id': '22490580',
  26. 'ext': 'mp4',
  27. 'title': 'Das Wunder von Wolbeck (Video tgl. ab 20 Uhr)',
  28. 'description': 'Auf einem restaurierten Hof bei Wolbeck wird der Heilpraktiker Raffael Lembeck eines morgens von seiner Frau Stella tot aufgefunden. Das Opfer war offensichtlich in seiner Praxis zu Fall gekommen und ist dann verblutet, erklärt Prof. Boerne am Tatort.',
  29. },
  30. 'skip': 'Blocked outside of Germany',
  31. }]
  32. def _real_extract(self, url):
  33. # determine video id from url
  34. m = re.match(self._VALID_URL, url)
  35. numid = re.search(r'documentId=([0-9]+)', url)
  36. if numid:
  37. video_id = numid.group(1)
  38. else:
  39. video_id = m.group('video_id')
  40. webpage = self._download_webpage(url, video_id)
  41. if '>Der gewünschte Beitrag ist nicht mehr verfügbar.<' in webpage:
  42. raise ExtractorError('Video %s is no longer available' % video_id, expected=True)
  43. if re.search(r'[\?&]rss($|[=&])', url):
  44. doc = parse_xml(webpage)
  45. if doc.tag == 'rss':
  46. return GenericIE()._extract_rss(url, video_id, doc)
  47. title = self._html_search_regex(
  48. [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
  49. r'<meta name="dcterms.title" content="(.*?)"/>',
  50. r'<h4 class="headline">(.*?)</h4>'],
  51. webpage, 'title')
  52. description = self._html_search_meta(
  53. 'dcterms.abstract', webpage, 'description', default=None)
  54. if description is None:
  55. description = self._html_search_meta(
  56. 'description', webpage, 'meta description')
  57. # Thumbnail is sometimes not present.
  58. # It is in the mobile version, but that seems to use a different URL
  59. # structure altogether.
  60. thumbnail = self._og_search_thumbnail(webpage, default=None)
  61. media_streams = re.findall(r'''(?x)
  62. mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
  63. "([^"]+)"''', webpage)
  64. if media_streams:
  65. QUALITIES = qualities(['lo', 'hi', 'hq'])
  66. formats = []
  67. for furl in set(media_streams):
  68. if furl.endswith('.f4m'):
  69. fid = 'f4m'
  70. else:
  71. fid_m = re.match(r'.*\.([^.]+)\.[^.]+$', furl)
  72. fid = fid_m.group(1) if fid_m else None
  73. formats.append({
  74. 'quality': QUALITIES(fid),
  75. 'format_id': fid,
  76. 'url': furl,
  77. })
  78. else: # request JSON file
  79. media_info = self._download_json(
  80. 'http://www.ardmediathek.de/play/media/%s' % video_id, video_id)
  81. # The second element of the _mediaArray contains the standard http urls
  82. streams = media_info['_mediaArray'][1]['_mediaStreamArray']
  83. if not streams:
  84. if '"fsk"' in webpage:
  85. raise ExtractorError('This video is only available after 20:00')
  86. formats = []
  87. for s in streams:
  88. if type(s['_stream']) == list:
  89. for index, url in enumerate(s['_stream'][::-1]):
  90. quality = s['_quality'] + index
  91. formats.append({
  92. 'quality': quality,
  93. 'url': url,
  94. 'format_id': '%s-%s' % (determine_ext(url), quality)
  95. })
  96. continue
  97. format = {
  98. 'quality': s['_quality'],
  99. 'url': s['_stream'],
  100. }
  101. format['format_id'] = '%s-%s' % (
  102. determine_ext(format['url']), format['quality'])
  103. formats.append(format)
  104. self._sort_formats(formats)
  105. return {
  106. 'id': video_id,
  107. 'title': title,
  108. 'description': description,
  109. 'formats': formats,
  110. 'thumbnail': thumbnail,
  111. }
  112. class ARDIE(InfoExtractor):
  113. _VALID_URL = '(?P<mainurl>https?://(www\.)?daserste\.de/[^?#]+/videos/(?P<display_id>[^/?#]+)-(?P<id>[0-9]+))\.html'
  114. _TEST = {
  115. 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html',
  116. 'md5': 'd216c3a86493f9322545e045ddc3eb35',
  117. 'info_dict': {
  118. 'display_id': 'die-story-im-ersten-mission-unter-falscher-flagge',
  119. 'id': '100',
  120. 'ext': 'mp4',
  121. 'duration': 2600,
  122. 'title': 'Die Story im Ersten: Mission unter falscher Flagge',
  123. 'upload_date': '20140804',
  124. 'thumbnail': 're:^https?://.*\.jpg$',
  125. }
  126. }
  127. def _real_extract(self, url):
  128. mobj = re.match(self._VALID_URL, url)
  129. display_id = mobj.group('display_id')
  130. player_url = mobj.group('mainurl') + '~playerXml.xml'
  131. doc = self._download_xml(player_url, display_id)
  132. video_node = doc.find('./video')
  133. upload_date = unified_strdate(xpath_text(
  134. video_node, './broadcastDate'))
  135. thumbnail = xpath_text(video_node, './/teaserImage//variant/url')
  136. formats = []
  137. for a in video_node.findall('.//asset'):
  138. f = {
  139. 'format_id': a.attrib['type'],
  140. 'width': int_or_none(a.find('./frameWidth').text),
  141. 'height': int_or_none(a.find('./frameHeight').text),
  142. 'vbr': int_or_none(a.find('./bitrateVideo').text),
  143. 'abr': int_or_none(a.find('./bitrateAudio').text),
  144. 'vcodec': a.find('./codecVideo').text,
  145. 'tbr': int_or_none(a.find('./totalBitrate').text),
  146. }
  147. if a.find('./serverPrefix').text:
  148. f['url'] = a.find('./serverPrefix').text
  149. f['playpath'] = a.find('./fileName').text
  150. else:
  151. f['url'] = a.find('./fileName').text
  152. formats.append(f)
  153. self._sort_formats(formats)
  154. return {
  155. 'id': mobj.group('id'),
  156. 'formats': formats,
  157. 'display_id': display_id,
  158. 'title': video_node.find('./title').text,
  159. 'duration': parse_duration(video_node.find('./duration').text),
  160. 'upload_date': upload_date,
  161. 'thumbnail': thumbnail,
  162. }