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.

191 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. )
  15. class ARDMediathekIE(InfoExtractor):
  16. IE_NAME = 'ARD:mediathek'
  17. _VALID_URL = r'^https?://(?:(?:www\.)?ardmediathek\.de|mediathek\.daserste\.de)/(?:.*/)(?P<video_id>[0-9]+|[^0-9][^/\?]+)[^/\?]*(?:\?.*)?'
  18. _TESTS = [{
  19. 'url': 'http://mediathek.daserste.de/sendungen_a-z/328454_anne-will/22429276_vertrauen-ist-gut-spionieren-ist-besser-geht',
  20. 'file': '22429276.mp4',
  21. 'md5': '469751912f1de0816a9fc9df8336476c',
  22. 'info_dict': {
  23. 'title': 'Vertrauen ist gut, Spionieren ist besser - Geht so deutsch-amerikanische Freundschaft?',
  24. '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',
  25. },
  26. 'skip': 'Blocked outside of Germany',
  27. }, {
  28. 'url': 'http://www.ardmediathek.de/tv/Tatort/Das-Wunder-von-Wolbeck-Video-tgl-ab-20/Das-Erste/Video?documentId=22490580&bcastId=602916',
  29. 'info_dict': {
  30. 'id': '22490580',
  31. 'ext': 'mp4',
  32. 'title': 'Das Wunder von Wolbeck (Video tgl. ab 20 Uhr)',
  33. '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.',
  34. },
  35. 'skip': 'Blocked outside of Germany',
  36. }]
  37. def _real_extract(self, url):
  38. # determine video id from url
  39. m = re.match(self._VALID_URL, url)
  40. numid = re.search(r'documentId=([0-9]+)', url)
  41. if numid:
  42. video_id = numid.group(1)
  43. else:
  44. video_id = m.group('video_id')
  45. urlp = compat_urllib_parse_urlparse(url)
  46. url = urlp._replace(path=compat_urllib_parse.quote(urlp.path.encode('utf-8'))).geturl()
  47. webpage = self._download_webpage(url, video_id)
  48. if '>Der gewünschte Beitrag ist nicht mehr verfügbar.<' in webpage:
  49. raise ExtractorError('Video %s is no longer available' % video_id, expected=True)
  50. title = self._html_search_regex(
  51. [r'<h1(?:\s+class="boxTopHeadline")?>(.*?)</h1>',
  52. r'<meta name="dcterms.title" content="(.*?)"/>',
  53. r'<h4 class="headline">(.*?)</h4>'],
  54. webpage, 'title')
  55. description = self._html_search_meta(
  56. 'dcterms.abstract', webpage, 'description', default=None)
  57. if description is None:
  58. description = self._html_search_meta(
  59. 'description', webpage, 'meta description')
  60. # Thumbnail is sometimes not present.
  61. # It is in the mobile version, but that seems to use a different URL
  62. # structure altogether.
  63. thumbnail = self._og_search_thumbnail(webpage, default=None)
  64. media_streams = re.findall(r'''(?x)
  65. mediaCollection\.addMediaStream\([0-9]+,\s*[0-9]+,\s*"[^"]*",\s*
  66. "([^"]+)"''', webpage)
  67. if media_streams:
  68. QUALITIES = qualities(['lo', 'hi', 'hq'])
  69. formats = []
  70. for furl in set(media_streams):
  71. if furl.endswith('.f4m'):
  72. fid = 'f4m'
  73. else:
  74. fid_m = re.match(r'.*\.([^.]+)\.[^.]+$', furl)
  75. fid = fid_m.group(1) if fid_m else None
  76. formats.append({
  77. 'quality': QUALITIES(fid),
  78. 'format_id': fid,
  79. 'url': furl,
  80. })
  81. else: # request JSON file
  82. media_info = self._download_json(
  83. 'http://www.ardmediathek.de/play/media/%s' % video_id, video_id)
  84. # The second element of the _mediaArray contains the standard http urls
  85. streams = media_info['_mediaArray'][1]['_mediaStreamArray']
  86. if not streams:
  87. if '"fsk"' in webpage:
  88. raise ExtractorError('This video is only available after 20:00')
  89. formats = []
  90. for s in streams:
  91. if type(s['_stream']) == list:
  92. for index, url in enumerate(s['_stream'][::-1]):
  93. quality = s['_quality'] + index
  94. formats.append({
  95. 'quality': quality,
  96. 'url': url,
  97. 'format_id': '%s-%s' % (determine_ext(url), quality)
  98. })
  99. continue
  100. format = {
  101. 'quality': s['_quality'],
  102. 'url': s['_stream'],
  103. }
  104. format['format_id'] = '%s-%s' % (
  105. determine_ext(format['url']), format['quality'])
  106. formats.append(format)
  107. self._sort_formats(formats)
  108. return {
  109. 'id': video_id,
  110. 'title': title,
  111. 'description': description,
  112. 'formats': formats,
  113. 'thumbnail': thumbnail,
  114. }
  115. class ARDIE(InfoExtractor):
  116. _VALID_URL = '(?P<mainurl>https?://(www\.)?daserste\.de/[^?#]+/videos/(?P<display_id>[^/?#]+)-(?P<id>[0-9]+))\.html'
  117. _TEST = {
  118. 'url': 'http://www.daserste.de/information/reportage-dokumentation/dokus/videos/die-story-im-ersten-mission-unter-falscher-flagge-100.html',
  119. 'md5': 'd216c3a86493f9322545e045ddc3eb35',
  120. 'info_dict': {
  121. 'display_id': 'die-story-im-ersten-mission-unter-falscher-flagge',
  122. 'id': '100',
  123. 'ext': 'mp4',
  124. 'duration': 2600,
  125. 'title': 'Die Story im Ersten: Mission unter falscher Flagge',
  126. 'upload_date': '20140804',
  127. 'thumbnail': 're:^https?://.*\.jpg$',
  128. }
  129. }
  130. def _real_extract(self, url):
  131. mobj = re.match(self._VALID_URL, url)
  132. display_id = mobj.group('display_id')
  133. player_url = mobj.group('mainurl') + '~playerXml.xml'
  134. doc = self._download_xml(player_url, display_id)
  135. video_node = doc.find('./video')
  136. upload_date = unified_strdate(video_node.find('./broadcastDate').text)
  137. thumbnail = video_node.find('.//teaserImage//variant/url').text
  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. }