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.

330 lines
12 KiB

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