2
0

wdr.py 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. js_to_json,
  8. strip_jsonp,
  9. unified_strdate,
  10. ExtractorError,
  11. )
  12. class WDRIE(InfoExtractor):
  13. _CURRENT_MAUS_URL = r'https?://(?:www\.)wdrmaus.de/(?:[^/]+/){1,2}[^/?#]+\.php5'
  14. _PAGE_REGEX = r'/mediathek/(?P<media_type>[^/]+)/(?P<type>[^/]+)/(?P<display_id>.+)\.html'
  15. _VALID_URL = r'(?P<page_url>https?://(?:www\d\.)?wdr\d?\.de)' + _PAGE_REGEX + '|' + _CURRENT_MAUS_URL
  16. _TESTS = [
  17. {
  18. 'url': 'http://www1.wdr.de/mediathek/video/sendungen/doku-am-freitag/video-geheimnis-aachener-dom-100.html',
  19. # HDS download, MD5 is unstable
  20. 'info_dict': {
  21. 'id': 'mdb-1058683',
  22. 'ext': 'flv',
  23. 'display_id': 'doku-am-freitag/video-geheimnis-aachener-dom-100',
  24. 'title': 'Geheimnis Aachener Dom',
  25. 'alt_title': 'Doku am Freitag',
  26. 'upload_date': '20160304',
  27. 'description': 'md5:87be8ff14d8dfd7a7ee46f0299b52318',
  28. 'is_live': False,
  29. 'subtitles': {'de': [{
  30. 'url': 'http://ondemand-ww.wdr.de/medp/fsk0/105/1058683/1058683_12220974.xml'
  31. }]},
  32. },
  33. },
  34. {
  35. 'url': 'http://www1.wdr.de/mediathek/audio/wdr3/wdr3-gespraech-am-samstag/audio-schriftstellerin-juli-zeh-100.html',
  36. 'md5': 'f4c1f96d01cf285240f53ea4309663d8',
  37. 'info_dict': {
  38. 'id': 'mdb-1072000',
  39. 'ext': 'mp3',
  40. 'display_id': 'wdr3-gespraech-am-samstag/audio-schriftstellerin-juli-zeh-100',
  41. 'title': 'Schriftstellerin Juli Zeh',
  42. 'alt_title': 'WDR 3 Gespräch am Samstag',
  43. 'upload_date': '20160312',
  44. 'description': 'md5:e127d320bc2b1f149be697ce044a3dd7',
  45. 'is_live': False,
  46. 'subtitles': {}
  47. },
  48. },
  49. {
  50. 'url': 'http://www1.wdr.de/mediathek/video/live/index.html',
  51. 'info_dict': {
  52. 'id': 'mdb-103364',
  53. 'ext': 'mp4',
  54. 'display_id': 'index',
  55. 'title': r're:^WDR Fernsehen im Livestream [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  56. 'alt_title': 'WDR Fernsehen Live',
  57. 'upload_date': None,
  58. 'description': 'md5:ae2ff888510623bf8d4b115f95a9b7c9',
  59. 'is_live': True,
  60. 'subtitles': {}
  61. },
  62. 'params': {
  63. 'skip_download': True, # m3u8 download
  64. },
  65. },
  66. {
  67. 'url': 'http://www1.wdr.de/mediathek/video/sendungen/aktuelle-stunde/aktuelle-stunde-120.html',
  68. 'playlist_mincount': 8,
  69. 'info_dict': {
  70. 'id': 'aktuelle-stunde/aktuelle-stunde-120',
  71. },
  72. },
  73. {
  74. 'url': 'http://www.wdrmaus.de/aktuelle-sendung/index.php5',
  75. 'info_dict': {
  76. 'id': 'mdb-1096487',
  77. 'ext': 'flv',
  78. 'upload_date': 're:^[0-9]{8}$',
  79. 'title': 're:^Die Sendung mit der Maus vom [0-9.]{10}$',
  80. 'description': '- Die Sendung mit der Maus -',
  81. },
  82. 'skip': 'The id changes from week to week because of the new episode'
  83. },
  84. {
  85. 'url': 'http://www.wdrmaus.de/sachgeschichten/sachgeschichten/achterbahn.php5',
  86. # HDS download, MD5 is unstable
  87. 'info_dict': {
  88. 'id': 'mdb-186083',
  89. 'ext': 'flv',
  90. 'upload_date': '20130919',
  91. 'title': 'Sachgeschichte - Achterbahn ',
  92. 'description': '- Die Sendung mit der Maus -',
  93. },
  94. },
  95. ]
  96. def _real_extract(self, url):
  97. mobj = re.match(self._VALID_URL, url)
  98. url_type = mobj.group('type')
  99. page_url = mobj.group('page_url')
  100. display_id = mobj.group('display_id')
  101. webpage = self._download_webpage(url, display_id)
  102. # for wdr.de the data-extension is in a tag with the class "mediaLink"
  103. # for wdrmaus its in a link to the page in a multiline "videoLink"-tag
  104. json_metadata = self._html_search_regex(
  105. r'class=(?:"mediaLink\b[^"]*"[^>]+|"videoLink\b[^"]*"[\s]*>\n[^\n]*)data-extension="([^"]+)"',
  106. webpage, 'media link', default=None, flags=re.MULTILINE)
  107. if not json_metadata:
  108. entries = [
  109. self.url_result(page_url + href[0], 'WDR')
  110. for href in re.findall(
  111. r'<a href="(%s)"[^>]+data-extension=' % self._PAGE_REGEX,
  112. webpage)
  113. ]
  114. if entries: # Playlist page
  115. return self.playlist_result(entries, playlist_id=display_id)
  116. raise ExtractorError('No downloadable streams found', expected=True)
  117. media_link_obj = self._parse_json(json_metadata, display_id,
  118. transform_source=js_to_json)
  119. jsonp_url = media_link_obj['mediaObj']['url']
  120. metadata = self._download_json(
  121. jsonp_url, 'metadata', transform_source=strip_jsonp)
  122. metadata_tracker_data = metadata['trackerData']
  123. metadata_media_resource = metadata['mediaResource']
  124. formats = []
  125. # check if the metadata contains a direct URL to a file
  126. metadata_media_alt = metadata_media_resource.get('alt')
  127. if metadata_media_alt:
  128. for tag_name in ['videoURL', 'audioURL']:
  129. if tag_name in metadata_media_alt:
  130. alt_url = metadata_media_alt[tag_name]
  131. if determine_ext(alt_url) == 'm3u8':
  132. m3u_fmt = self._extract_m3u8_formats(
  133. alt_url, display_id, 'mp4', 'm3u8_native',
  134. m3u8_id='hls')
  135. formats.extend(m3u_fmt)
  136. else:
  137. formats.append({
  138. 'url': alt_url
  139. })
  140. # check if there are flash-streams for this video
  141. if 'dflt' in metadata_media_resource and 'videoURL' in metadata_media_resource['dflt']:
  142. video_url = metadata_media_resource['dflt']['videoURL']
  143. if video_url.endswith('.f4m'):
  144. full_video_url = video_url + '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18'
  145. formats.extend(self._extract_f4m_formats(full_video_url, display_id, f4m_id='hds', fatal=False))
  146. elif video_url.endswith('.smil'):
  147. formats.extend(self._extract_smil_formats(video_url, 'stream', fatal=False))
  148. subtitles = {}
  149. caption_url = metadata_media_resource.get('captionURL')
  150. if caption_url:
  151. subtitles['de'] = [{
  152. 'url': caption_url
  153. }]
  154. title = metadata_tracker_data.get('trackerClipTitle')
  155. is_live = url_type == 'live'
  156. if is_live:
  157. title = self._live_title(title)
  158. upload_date = None
  159. elif 'trackerClipAirTime' in metadata_tracker_data:
  160. upload_date = metadata_tracker_data['trackerClipAirTime']
  161. else:
  162. upload_date = self._html_search_meta('DC.Date', webpage, 'upload date')
  163. if upload_date:
  164. upload_date = unified_strdate(upload_date)
  165. self._sort_formats(formats)
  166. return {
  167. 'id': metadata_tracker_data.get('trackerClipId', display_id),
  168. 'display_id': display_id,
  169. 'title': title,
  170. 'alt_title': metadata_tracker_data.get('trackerClipSubcategory'),
  171. 'formats': formats,
  172. 'upload_date': upload_date,
  173. 'description': self._html_search_meta('Description', webpage),
  174. 'is_live': is_live,
  175. 'subtitles': subtitles,
  176. }
  177. class WDRMobileIE(InfoExtractor):
  178. _VALID_URL = r'''(?x)
  179. https?://mobile-ondemand\.wdr\.de/
  180. .*?/fsk(?P<age_limit>[0-9]+)
  181. /[0-9]+/[0-9]+/
  182. (?P<id>[0-9]+)_(?P<title>[0-9]+)'''
  183. IE_NAME = 'wdr:mobile'
  184. _TEST = {
  185. 'url': 'http://mobile-ondemand.wdr.de/CMS2010/mdb/ondemand/weltweit/fsk0/42/421735/421735_4283021.mp4',
  186. 'info_dict': {
  187. 'title': '4283021',
  188. 'id': '421735',
  189. 'ext': 'mp4',
  190. 'age_limit': 0,
  191. },
  192. 'skip': 'Problems with loading data.'
  193. }
  194. def _real_extract(self, url):
  195. mobj = re.match(self._VALID_URL, url)
  196. return {
  197. 'id': mobj.group('id'),
  198. 'title': mobj.group('title'),
  199. 'age_limit': int(mobj.group('age_limit')),
  200. 'url': url,
  201. 'http_headers': {
  202. 'User-Agent': 'mobile',
  203. },
  204. }