wdr.py 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_str,
  7. compat_urlparse,
  8. )
  9. from ..utils import (
  10. determine_ext,
  11. ExtractorError,
  12. js_to_json,
  13. strip_jsonp,
  14. try_get,
  15. unified_strdate,
  16. update_url_query,
  17. urlhandle_detect_ext,
  18. )
  19. class WDRIE(InfoExtractor):
  20. _VALID_URL = r'https?://deviceids-medp\.wdr\.de/ondemand/\d+/(?P<id>\d+)\.js'
  21. _TEST = {
  22. 'url': 'http://deviceids-medp.wdr.de/ondemand/155/1557833.js',
  23. 'info_dict': {
  24. 'id': 'mdb-1140188',
  25. 'display_id': 'dfb-team-geht-gut-gelaunt-ins-spiel-gegen-polen-100',
  26. 'ext': 'mp4',
  27. 'title': 'DFB-Team geht gut gelaunt ins Spiel gegen Polen',
  28. 'description': 'Vor dem zweiten Gruppenspiel gegen Polen herrscht gute Stimmung im deutschen Team. Insbesondere Bastian Schweinsteiger strotzt vor Optimismus nach seinem Tor gegen die Ukraine.',
  29. 'upload_date': '20160615',
  30. },
  31. 'skip': 'Geo-restricted to Germany',
  32. }
  33. def _real_extract(self, url):
  34. video_id = self._match_id(url)
  35. metadata = self._download_json(
  36. url, video_id, transform_source=strip_jsonp)
  37. is_live = metadata.get('mediaType') == 'live'
  38. tracker_data = metadata['trackerData']
  39. media_resource = metadata['mediaResource']
  40. formats = []
  41. # check if the metadata contains a direct URL to a file
  42. for kind, media_resource in media_resource.items():
  43. if kind not in ('dflt', 'alt'):
  44. continue
  45. for tag_name, medium_url in media_resource.items():
  46. if tag_name not in ('videoURL', 'audioURL'):
  47. continue
  48. ext = determine_ext(medium_url)
  49. if ext == 'm3u8':
  50. formats.extend(self._extract_m3u8_formats(
  51. medium_url, video_id, 'mp4', 'm3u8_native',
  52. m3u8_id='hls'))
  53. elif ext == 'f4m':
  54. manifest_url = update_url_query(
  55. medium_url, {'hdcore': '3.2.0', 'plugin': 'aasp-3.2.0.77.18'})
  56. formats.extend(self._extract_f4m_formats(
  57. manifest_url, video_id, f4m_id='hds', fatal=False))
  58. elif ext == 'smil':
  59. formats.extend(self._extract_smil_formats(
  60. medium_url, 'stream', fatal=False))
  61. else:
  62. a_format = {
  63. 'url': medium_url
  64. }
  65. if ext == 'unknown_video':
  66. urlh = self._request_webpage(
  67. medium_url, video_id, note='Determining extension')
  68. ext = urlhandle_detect_ext(urlh)
  69. a_format['ext'] = ext
  70. formats.append(a_format)
  71. self._sort_formats(formats)
  72. subtitles = {}
  73. caption_url = media_resource.get('captionURL')
  74. if caption_url:
  75. subtitles['de'] = [{
  76. 'url': caption_url,
  77. 'ext': 'ttml',
  78. }]
  79. title = tracker_data['trackerClipTitle']
  80. return {
  81. 'id': tracker_data.get('trackerClipId', video_id),
  82. 'title': self._live_title(title) if is_live else title,
  83. 'alt_title': tracker_data.get('trackerClipSubcategory'),
  84. 'formats': formats,
  85. 'subtitles': subtitles,
  86. 'upload_date': unified_strdate(tracker_data.get('trackerClipAirTime')),
  87. 'is_live': is_live,
  88. }
  89. class WDRPageIE(InfoExtractor):
  90. _CURRENT_MAUS_URL = r'https?://(?:www\.)wdrmaus.de/(?:[^/]+/){1,2}[^/?#]+\.php5'
  91. _PAGE_REGEX = r'/(?:mediathek/)?(?:[^/]+/)*(?P<display_id>[^/]+)\.html'
  92. _VALID_URL = r'https?://(?:www\d?\.)?(?:wdr\d?|sportschau)\.de' + _PAGE_REGEX + '|' + _CURRENT_MAUS_URL
  93. _TESTS = [
  94. {
  95. 'url': 'http://www1.wdr.de/mediathek/video/sendungen/doku-am-freitag/video-geheimnis-aachener-dom-100.html',
  96. # HDS download, MD5 is unstable
  97. 'info_dict': {
  98. 'id': 'mdb-1058683',
  99. 'ext': 'flv',
  100. 'display_id': 'doku-am-freitag/video-geheimnis-aachener-dom-100',
  101. 'title': 'Geheimnis Aachener Dom',
  102. 'alt_title': 'Doku am Freitag',
  103. 'upload_date': '20160304',
  104. 'description': 'md5:87be8ff14d8dfd7a7ee46f0299b52318',
  105. 'is_live': False,
  106. 'subtitles': {'de': [{
  107. 'url': 'http://ondemand-ww.wdr.de/medp/fsk0/105/1058683/1058683_12220974.xml',
  108. 'ext': 'ttml',
  109. }]},
  110. },
  111. 'skip': 'HTTP Error 404: Not Found',
  112. },
  113. {
  114. 'url': 'http://www1.wdr.de/mediathek/audio/wdr3/wdr3-gespraech-am-samstag/audio-schriftstellerin-juli-zeh-100.html',
  115. 'md5': 'f4c1f96d01cf285240f53ea4309663d8',
  116. 'info_dict': {
  117. 'id': 'mdb-1072000',
  118. 'ext': 'mp3',
  119. 'display_id': 'wdr3-gespraech-am-samstag/audio-schriftstellerin-juli-zeh-100',
  120. 'title': 'Schriftstellerin Juli Zeh',
  121. 'alt_title': 'WDR 3 Gespräch am Samstag',
  122. 'upload_date': '20160312',
  123. 'description': 'md5:e127d320bc2b1f149be697ce044a3dd7',
  124. 'is_live': False,
  125. 'subtitles': {}
  126. },
  127. 'skip': 'HTTP Error 404: Not Found',
  128. },
  129. {
  130. 'url': 'http://www1.wdr.de/mediathek/video/live/index.html',
  131. 'info_dict': {
  132. 'id': 'mdb-1406149',
  133. 'ext': 'mp4',
  134. 'title': r're:^WDR Fernsehen im Livestream \(nur in Deutschland erreichbar\) [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  135. 'alt_title': 'WDR Fernsehen Live',
  136. 'upload_date': '20150101',
  137. 'is_live': True,
  138. },
  139. 'params': {
  140. 'skip_download': True, # m3u8 download
  141. },
  142. },
  143. {
  144. 'url': 'http://www1.wdr.de/mediathek/video/sendungen/aktuelle-stunde/aktuelle-stunde-120.html',
  145. 'playlist_mincount': 7,
  146. 'info_dict': {
  147. 'id': 'aktuelle-stunde-120',
  148. },
  149. },
  150. {
  151. 'url': 'http://www.wdrmaus.de/aktuelle-sendung/index.php5',
  152. 'info_dict': {
  153. 'id': 'mdb-1552552',
  154. 'ext': 'mp4',
  155. 'upload_date': 're:^[0-9]{8}$',
  156. 'title': 're:^Die Sendung mit der Maus vom [0-9.]{10}$',
  157. },
  158. 'skip': 'The id changes from week to week because of the new episode'
  159. },
  160. {
  161. 'url': 'http://www.wdrmaus.de/filme/sachgeschichten/achterbahn.php5',
  162. 'md5': '803138901f6368ee497b4d195bb164f2',
  163. 'info_dict': {
  164. 'id': 'mdb-186083',
  165. 'ext': 'mp4',
  166. 'upload_date': '20130919',
  167. 'title': 'Sachgeschichte - Achterbahn ',
  168. },
  169. },
  170. {
  171. 'url': 'http://www1.wdr.de/radio/player/radioplayer116~_layout-popupVersion.html',
  172. # Live stream, MD5 unstable
  173. 'info_dict': {
  174. 'id': 'mdb-869971',
  175. 'ext': 'mp4',
  176. 'title': r're:^COSMO Livestream [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  177. 'upload_date': '20160101',
  178. },
  179. 'params': {
  180. 'skip_download': True, # m3u8 download
  181. }
  182. },
  183. {
  184. 'url': 'http://www.sportschau.de/handballem2018/handball-nationalmannschaft-em-stolperstein-vorrunde-100.html',
  185. 'info_dict': {
  186. 'id': 'mdb-1556012',
  187. 'ext': 'mp4',
  188. 'title': 'DHB-Vizepräsident Bob Hanning - "Die Weltspitze ist extrem breit"',
  189. 'upload_date': '20180111',
  190. },
  191. 'params': {
  192. 'skip_download': True,
  193. },
  194. },
  195. {
  196. 'url': 'http://www.sportschau.de/handballem2018/audio-vorschau---die-handball-em-startet-mit-grossem-favoritenfeld-100.html',
  197. 'only_matching': True,
  198. }
  199. ]
  200. def _real_extract(self, url):
  201. mobj = re.match(self._VALID_URL, url)
  202. display_id = mobj.group('display_id')
  203. webpage = self._download_webpage(url, display_id)
  204. entries = []
  205. # Article with several videos
  206. # for wdr.de the data-extension is in a tag with the class "mediaLink"
  207. # for wdr.de radio players, in a tag with the class "wdrrPlayerPlayBtn"
  208. # for wdrmaus, in a tag with the class "videoButton" (previously a link
  209. # to the page in a multiline "videoLink"-tag)
  210. for mobj in re.finditer(
  211. r'''(?sx)class=
  212. (?:
  213. (["\'])(?:mediaLink|wdrrPlayerPlayBtn|videoButton)\b.*?\1[^>]+|
  214. (["\'])videoLink\b.*?\2[\s]*>\n[^\n]*
  215. )data-extension=(["\'])(?P<data>(?:(?!\3).)+)\3
  216. ''', webpage):
  217. media_link_obj = self._parse_json(
  218. mobj.group('data'), display_id, transform_source=js_to_json,
  219. fatal=False)
  220. if not media_link_obj:
  221. continue
  222. jsonp_url = try_get(
  223. media_link_obj, lambda x: x['mediaObj']['url'], compat_str)
  224. if jsonp_url:
  225. entries.append(self.url_result(jsonp_url, ie=WDRIE.ie_key()))
  226. # Playlist (e.g. https://www1.wdr.de/mediathek/video/sendungen/aktuelle-stunde/aktuelle-stunde-120.html)
  227. if not entries:
  228. entries = [
  229. self.url_result(
  230. compat_urlparse.urljoin(url, mobj.group('href')),
  231. ie=WDRPageIE.ie_key())
  232. for mobj in re.finditer(
  233. r'<a[^>]+\bhref=(["\'])(?P<href>(?:(?!\1).)+)\1[^>]+\bdata-extension=',
  234. webpage) if re.match(self._PAGE_REGEX, mobj.group('href'))
  235. ]
  236. return self.playlist_result(entries, playlist_id=display_id)
  237. class WDRElefantIE(InfoExtractor):
  238. _VALID_URL = r'https?://(?:www\.)wdrmaus\.de/elefantenseite/#(?P<id>.+)'
  239. _TEST = {
  240. 'url': 'http://www.wdrmaus.de/elefantenseite/#folge_ostern_2015',
  241. 'info_dict': {
  242. 'title': 'Folge Oster-Spezial 2015',
  243. 'id': 'mdb-1088195',
  244. 'ext': 'mp4',
  245. 'age_limit': None,
  246. 'upload_date': '20150406'
  247. },
  248. 'params': {
  249. 'skip_download': True,
  250. },
  251. }
  252. def _real_extract(self, url):
  253. display_id = self._match_id(url)
  254. # Table of Contents seems to always be at this address, so fetch it directly.
  255. # The website fetches configurationJS.php5, which links to tableOfContentsJS.php5.
  256. table_of_contents = self._download_json(
  257. 'https://www.wdrmaus.de/elefantenseite/data/tableOfContentsJS.php5',
  258. display_id)
  259. if display_id not in table_of_contents:
  260. raise ExtractorError(
  261. 'No entry in site\'s table of contents for this URL. '
  262. 'Is the fragment part of the URL (after the #) correct?',
  263. expected=True)
  264. xml_metadata_path = table_of_contents[display_id]['xmlPath']
  265. xml_metadata = self._download_xml(
  266. 'https://www.wdrmaus.de/elefantenseite/' + xml_metadata_path,
  267. display_id)
  268. zmdb_url_element = xml_metadata.find('./movie/zmdb_url')
  269. if zmdb_url_element is None:
  270. raise ExtractorError(
  271. '%s is not a video' % display_id, expected=True)
  272. return self.url_result(zmdb_url_element.text, ie=WDRIE.ie_key())
  273. class WDRMobileIE(InfoExtractor):
  274. _VALID_URL = r'''(?x)
  275. https?://mobile-ondemand\.wdr\.de/
  276. .*?/fsk(?P<age_limit>[0-9]+)
  277. /[0-9]+/[0-9]+/
  278. (?P<id>[0-9]+)_(?P<title>[0-9]+)'''
  279. IE_NAME = 'wdr:mobile'
  280. _TEST = {
  281. 'url': 'http://mobile-ondemand.wdr.de/CMS2010/mdb/ondemand/weltweit/fsk0/42/421735/421735_4283021.mp4',
  282. 'info_dict': {
  283. 'title': '4283021',
  284. 'id': '421735',
  285. 'ext': 'mp4',
  286. 'age_limit': 0,
  287. },
  288. 'skip': 'Problems with loading data.'
  289. }
  290. def _real_extract(self, url):
  291. mobj = re.match(self._VALID_URL, url)
  292. return {
  293. 'id': mobj.group('id'),
  294. 'title': mobj.group('title'),
  295. 'age_limit': int(mobj.group('age_limit')),
  296. 'url': url,
  297. 'http_headers': {
  298. 'User-Agent': 'mobile',
  299. },
  300. }