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.5 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 'Diese Sendung ist für Jugendliche unter 12 Jahren nicht geeignet. Der Clip ist deshalb nur von 20 bis 6 Uhr verfügbar.' in webpage:
  44. raise ExtractorError('This program is only suitable for those aged 12 and older. Video %s is therefore only available between 20 pm and 6 am.' % video_id, expected=True)
  45. if re.search(r'[\?&]rss($|[=&])', url):
  46. doc = parse_xml(webpage)
  47. if doc.tag == 'rss':
  48. return GenericIE()._extract_rss(url, video_id, doc)
  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. }