wdr.py 13 KB

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