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.

190 lines
7.6 KiB

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