wdr.py 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_parse_qs,
  7. compat_urlparse,
  8. )
  9. from ..utils import (
  10. determine_ext,
  11. strip_jsonp,
  12. unified_strdate,
  13. ExtractorError,
  14. )
  15. class WDRIE(InfoExtractor):
  16. _CURRENT_MAUS_URL = r'https?://www.wdrmaus.de/aktuelle-sendung/(wdr|index).php5'
  17. _PAGE_REGEX = r'/mediathek/(?P<media_type>[^/]+)/(?P<type>[^/]+)/(?P<display_id>.+)\.html'
  18. _VALID_URL = r'(?P<page_url>https?://(?:www\d\.)?wdr\d?\.de)' + _PAGE_REGEX + '|' + _CURRENT_MAUS_URL
  19. _JS_URL_REGEX = r'(https?://deviceids-medp.wdr.de/ondemand/\d+/\d+\.js)'
  20. _TESTS = [
  21. {
  22. 'url': 'http://www1.wdr.de/mediathek/video/sendungen/doku-am-freitag/video-geheimnis-aachener-dom-100.html',
  23. 'md5': 'e58c39c3e30077141d258bf588700a7b',
  24. 'info_dict': {
  25. 'id': 'mdb-1058683',
  26. 'ext': 'flv',
  27. 'display_id': 'doku-am-freitag/video-geheimnis-aachener-dom-100',
  28. 'title': 'Geheimnis Aachener Dom',
  29. 'alt_title': 'Doku am Freitag',
  30. 'upload_date': '20160304',
  31. 'description': 'md5:87be8ff14d8dfd7a7ee46f0299b52318',
  32. 'is_live': False,
  33. 'subtitles': {'de': [{
  34. 'url': 'http://ondemand-ww.wdr.de/medp/fsk0/105/1058683/1058683_12220974.xml'
  35. }]},
  36. },
  37. 'skip': 'Page Not Found',
  38. },
  39. {
  40. 'url': 'http://www1.wdr.de/mediathek/audio/wdr3/wdr3-gespraech-am-samstag/audio-schriftstellerin-juli-zeh-100.html',
  41. 'md5': 'f4c1f96d01cf285240f53ea4309663d8',
  42. 'info_dict': {
  43. 'id': 'mdb-1072000',
  44. 'ext': 'mp3',
  45. 'display_id': 'wdr3-gespraech-am-samstag/audio-schriftstellerin-juli-zeh-100',
  46. 'title': 'Schriftstellerin Juli Zeh',
  47. 'alt_title': 'WDR 3 Gespräch am Samstag',
  48. 'upload_date': '20160312',
  49. 'description': 'md5:e127d320bc2b1f149be697ce044a3dd7',
  50. 'is_live': False,
  51. 'subtitles': {}
  52. },
  53. 'skip': 'Page Not Found',
  54. },
  55. {
  56. 'url': 'http://www1.wdr.de/mediathek/video/live/index.html',
  57. 'info_dict': {
  58. 'id': 'mdb-103364',
  59. 'ext': 'mp4',
  60. 'display_id': 'index',
  61. 'title': r're:^WDR Fernsehen im Livestream [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  62. 'alt_title': 'WDR Fernsehen Live',
  63. 'upload_date': None,
  64. 'description': 'md5:ae2ff888510623bf8d4b115f95a9b7c9',
  65. 'is_live': True,
  66. 'subtitles': {}
  67. },
  68. 'params': {
  69. 'skip_download': True, # m3u8 download
  70. },
  71. },
  72. {
  73. 'url': 'http://www1.wdr.de/mediathek/video/sendungen/aktuelle-stunde/aktuelle-stunde-120.html',
  74. 'playlist_mincount': 10,
  75. 'info_dict': {
  76. 'id': 'aktuelle-stunde/aktuelle-stunde-120',
  77. },
  78. },
  79. {
  80. 'url': 'http://www.wdrmaus.de/aktuelle-sendung/index.php5',
  81. 'info_dict': {
  82. 'id': 'mdb-1096487',
  83. 'ext': 'flv',
  84. 'upload_date': 're:^[0-9]{8}$',
  85. 'title': 're:^Die Sendung mit der Maus vom [0-9.]{10}$',
  86. 'description': '- Die Sendung mit der Maus -',
  87. },
  88. 'skip': 'The id changes from week to week because of the new episode'
  89. },
  90. ]
  91. def _real_extract(self, url):
  92. mobj = re.match(self._VALID_URL, url)
  93. url_type = mobj.group('type')
  94. page_url = mobj.group('page_url')
  95. display_id = mobj.group('display_id')
  96. webpage = self._download_webpage(url, display_id)
  97. js_url = self._search_regex(self._JS_URL_REGEX, webpage, 'js_url', default=None)
  98. if not js_url:
  99. entries = [
  100. self.url_result(page_url + href[0], 'WDR')
  101. for href in re.findall(
  102. r'<a href="(%s)"' % self._PAGE_REGEX,
  103. webpage)
  104. ]
  105. if entries: # Playlist page
  106. return self.playlist_result(entries, playlist_id=display_id)
  107. raise ExtractorError('No downloadable streams found', expected=True)
  108. metadata = self._download_json(
  109. js_url, 'metadata', transform_source=strip_jsonp)
  110. metadata_tracker_data = metadata['trackerData']
  111. metadata_media_resource = metadata['mediaResource']
  112. formats = []
  113. # check if the metadata contains a direct URL to a file
  114. metadata_media_alt = metadata_media_resource.get('alt')
  115. if metadata_media_alt:
  116. for tag_name in ['videoURL', 'audioURL']:
  117. if tag_name in metadata_media_alt:
  118. alt_url = metadata_media_alt[tag_name]
  119. if determine_ext(alt_url) == 'm3u8':
  120. m3u_fmt = self._extract_m3u8_formats(
  121. alt_url, display_id, 'mp4', 'm3u8_native',
  122. m3u8_id='hls')
  123. formats.extend(m3u_fmt)
  124. else:
  125. formats.append({
  126. 'url': alt_url
  127. })
  128. # check if there are flash-streams for this video
  129. if 'dflt' in metadata_media_resource and 'videoURL' in metadata_media_resource['dflt']:
  130. video_url = metadata_media_resource['dflt']['videoURL']
  131. if video_url.endswith('.f4m'):
  132. full_video_url = video_url + '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18'
  133. formats.extend(self._extract_f4m_formats(full_video_url, display_id, f4m_id='hds', fatal=False))
  134. elif video_url.endswith('.smil'):
  135. formats.extend(self._extract_smil_formats(video_url, 'stream', fatal=False))
  136. subtitles = {}
  137. caption_url = metadata_media_resource.get('captionURL')
  138. if caption_url:
  139. subtitles['de'] = [{
  140. 'url': caption_url
  141. }]
  142. title = metadata_tracker_data.get('trackerClipTitle')
  143. is_live = url_type == 'live'
  144. if is_live:
  145. title = self._live_title(title)
  146. upload_date = None
  147. elif 'trackerClipAirTime' in metadata_tracker_data:
  148. upload_date = metadata_tracker_data['trackerClipAirTime']
  149. else:
  150. upload_date = self._html_search_meta('DC.Date', webpage, 'upload date')
  151. if upload_date:
  152. upload_date = unified_strdate(upload_date)
  153. self._sort_formats(formats)
  154. return {
  155. 'id': metadata_tracker_data.get('trackerClipId', display_id),
  156. 'display_id': display_id,
  157. 'title': title,
  158. 'alt_title': metadata_tracker_data.get('trackerClipSubcategory'),
  159. 'formats': formats,
  160. 'upload_date': upload_date,
  161. 'description': self._html_search_meta('Description', webpage),
  162. 'is_live': is_live,
  163. 'subtitles': subtitles,
  164. }
  165. class WDRMobileIE(InfoExtractor):
  166. _VALID_URL = r'''(?x)
  167. https?://mobile-ondemand\.wdr\.de/
  168. .*?/fsk(?P<age_limit>[0-9]+)
  169. /[0-9]+/[0-9]+/
  170. (?P<id>[0-9]+)_(?P<title>[0-9]+)'''
  171. IE_NAME = 'wdr:mobile'
  172. _TEST = {
  173. 'url': 'http://mobile-ondemand.wdr.de/CMS2010/mdb/ondemand/weltweit/fsk0/42/421735/421735_4283021.mp4',
  174. 'info_dict': {
  175. 'title': '4283021',
  176. 'id': '421735',
  177. 'ext': 'mp4',
  178. 'age_limit': 0,
  179. },
  180. 'skip': 'Problems with loading data.'
  181. }
  182. def _real_extract(self, url):
  183. mobj = re.match(self._VALID_URL, url)
  184. return {
  185. 'id': mobj.group('id'),
  186. 'title': mobj.group('title'),
  187. 'age_limit': int(mobj.group('age_limit')),
  188. 'url': url,
  189. 'http_headers': {
  190. 'User-Agent': 'mobile',
  191. },
  192. }
  193. class WDRMausIE(InfoExtractor):
  194. _VALID_URL = 'https?://(?:www\.)?wdrmaus\.de/(?:[^/]+/){,2}(?P<id>[^/?#]+)((?<!index)\.php5|/(?:$|[?#]))'
  195. IE_DESC = 'Sendung mit der Maus'
  196. _TESTS = [{
  197. 'url': 'http://www.wdrmaus.de/sachgeschichten/sachgeschichten/achterbahn.php5',
  198. 'md5': '178b432d002162a14ccb3e0876741095',
  199. 'info_dict': {
  200. 'id': 'achterbahn',
  201. 'ext': 'mp4',
  202. 'thumbnail': 're:^http://.+\.jpg',
  203. 'upload_date': '20131001',
  204. 'title': '19.09.2013 - Achterbahn',
  205. }
  206. }]
  207. def _real_extract(self, url):
  208. video_id = self._match_id(url)
  209. webpage = self._download_webpage(url, video_id)
  210. param_code = self._html_search_regex(
  211. r'<a href="\?startVideo=1&amp;([^"]+)"', webpage, 'parameters')
  212. title_date = self._search_regex(
  213. r'<div class="sendedatum"><p>Sendedatum:\s*([0-9\.]+)</p>',
  214. webpage, 'air date')
  215. title_str = self._html_search_regex(
  216. r'<h1>(.*?)</h1>', webpage, 'title')
  217. title = '%s - %s' % (title_date, title_str)
  218. upload_date = unified_strdate(
  219. self._html_search_meta('dc.date', webpage))
  220. fields = compat_parse_qs(param_code)
  221. video_url = fields['firstVideo'][0]
  222. thumbnail = compat_urlparse.urljoin(url, fields['startPicture'][0])
  223. formats = [{
  224. 'format_id': 'rtmp',
  225. 'url': video_url,
  226. }]
  227. jscode = self._download_webpage(
  228. 'http://www.wdrmaus.de/codebase/js/extended-medien.min.js',
  229. video_id, fatal=False,
  230. note='Downloading URL translation table',
  231. errnote='Could not download URL translation table')
  232. if jscode:
  233. for m in re.finditer(
  234. r"stream:\s*'dslSrc=(?P<stream>[^']+)',\s*download:\s*'(?P<dl>[^']+)'\s*\}",
  235. jscode):
  236. if video_url.startswith(m.group('stream')):
  237. http_url = video_url.replace(
  238. m.group('stream'), m.group('dl'))
  239. formats.append({
  240. 'format_id': 'http',
  241. 'url': http_url,
  242. })
  243. break
  244. self._sort_formats(formats)
  245. return {
  246. 'id': video_id,
  247. 'title': title,
  248. 'formats': formats,
  249. 'thumbnail': thumbnail,
  250. 'upload_date': upload_date,
  251. }