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.

193 lines
7.7 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. urlp = compat_urllib_parse_urlparse(url)
  47. url = urlp._replace(path=compat_urllib_parse.quote(urlp.path.encode('utf-8'))).geturl()
  48. webpage = self._download_webpage(url, video_id)
  49. if '>Der gewünschte Beitrag ist nicht mehr verfügbar.<' in webpage:
  50. raise ExtractorError('Video %s is no longer available' % video_id, expected=True)
  51. title = self._html_search_regex(
  52. [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
  53. r'<meta name="dcterms.title" content="(.*?)"/>',
  54. r'<h4 class="headline">(.*?)</h4>'],
  55. webpage, 'title')
  56. description = self._html_search_meta(
  57. 'dcterms.abstract', webpage, 'description', default=None)
  58. if description is None:
  59. description = self._html_search_meta(
  60. 'description', webpage, 'meta description')
  61. # Thumbnail is sometimes not present.
  62. # It is in the mobile version, but that seems to use a different URL
  63. # structure altogether.
  64. thumbnail = self._og_search_thumbnail(webpage, default=None)
  65. media_streams = re.findall(r'''(?x)
  66. mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
  67. "([^"]+)"''', webpage)
  68. if media_streams:
  69. QUALITIES = qualities(['lo', 'hi', 'hq'])
  70. formats = []
  71. for furl in set(media_streams):
  72. if furl.endswith('.f4m'):
  73. fid = 'f4m'
  74. else:
  75. fid_m = re.match(r'.*\.([^.]+)\.[^.]+$', furl)
  76. fid = fid_m.group(1) if fid_m else None
  77. formats.append({
  78. 'quality': QUALITIES(fid),
  79. 'format_id': fid,
  80. 'url': furl,
  81. })
  82. else: # request JSON file
  83. media_info = self._download_json(
  84. 'http://www.ardmediathek.de/play/media/%s' % video_id, video_id)
  85. # The second element of the _mediaArray contains the standard http urls
  86. streams = media_info['_mediaArray'][1]['_mediaStreamArray']
  87. if not streams:
  88. if '"fsk"' in webpage:
  89. raise ExtractorError('This video is only available after 20:00')
  90. formats = []
  91. for s in streams:
  92. if type(s['_stream']) == list:
  93. for index, url in enumerate(s['_stream'][::-1]):
  94. quality = s['_quality'] + index
  95. formats.append({
  96. 'quality': quality,
  97. 'url': url,
  98. 'format_id': '%s-%s' % (determine_ext(url), quality)
  99. })
  100. continue
  101. format = {
  102. 'quality': s['_quality'],
  103. 'url': s['_stream'],
  104. }
  105. format['format_id'] = '%s-%s' % (
  106. determine_ext(format['url']), format['quality'])
  107. formats.append(format)
  108. self._sort_formats(formats)
  109. return {
  110. 'id': video_id,
  111. 'title': title,
  112. 'description': description,
  113. 'formats': formats,
  114. 'thumbnail': thumbnail,
  115. }
  116. class ARDIE(InfoExtractor):
  117. _VALID_URL = '(?P<mainurl>https?://(www\.)?daserste\.de/[^?#]+/videos/(?P<display_id>[^/?#]+)-(?P<id>[0-9]+))\.html'
  118. _TEST = {
  119. 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html',
  120. 'md5': 'd216c3a86493f9322545e045ddc3eb35',
  121. 'info_dict': {
  122. 'display_id': 'die-story-im-ersten-mission-unter-falscher-flagge',
  123. 'id': '100',
  124. 'ext': 'mp4',
  125. 'duration': 2600,
  126. 'title': 'Die Story im Ersten: Mission unter falscher Flagge',
  127. 'upload_date': '20140804',
  128. 'thumbnail': 're:^https?://.*\.jpg$',
  129. }
  130. }
  131. def _real_extract(self, url):
  132. mobj = re.match(self._VALID_URL, url)
  133. display_id = mobj.group('display_id')
  134. player_url = mobj.group('mainurl') + '~playerXml.xml'
  135. doc = self._download_xml(player_url, display_id)
  136. video_node = doc.find('./video')
  137. upload_date = unified_strdate(xpath_text(
  138. video_node, './broadcastDate'))
  139. thumbnail = xpath_text(video_node, './/teaserImage//variant/url')
  140. formats = []
  141. for a in video_node.findall('.//asset'):
  142. f = {
  143. 'format_id': a.attrib['type'],
  144. 'width': int_or_none(a.find('./frameWidth').text),
  145. 'height': int_or_none(a.find('./frameHeight').text),
  146. 'vbr': int_or_none(a.find('./bitrateVideo').text),
  147. 'abr': int_or_none(a.find('./bitrateAudio').text),
  148. 'vcodec': a.find('./codecVideo').text,
  149. 'tbr': int_or_none(a.find('./totalBitrate').text),
  150. }
  151. if a.find('./serverPrefix').text:
  152. f['url'] = a.find('./serverPrefix').text
  153. f['playpath'] = a.find('./fileName').text
  154. else:
  155. f['url'] = a.find('./fileName').text
  156. formats.append(f)
  157. self._sort_formats(formats)
  158. return {
  159. 'id': mobj.group('id'),
  160. 'formats': formats,
  161. 'display_id': display_id,
  162. 'title': video_node.find('./title').text,
  163. 'duration': parse_duration(video_node.find('./duration').text),
  164. 'upload_date': upload_date,
  165. 'thumbnail': thumbnail,
  166. }