wdr.py 13 KB

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