wdr.py 9.6 KB

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