wdr.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  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. js_to_json,
  12. strip_jsonp,
  13. unified_strdate,
  14. ExtractorError,
  15. )
  16. class WDRIE(InfoExtractor):
  17. _CURRENT_MAUS_URL = r'https?://www.wdrmaus.de/aktuelle-sendung/(wdr|index).php5'
  18. _PAGE_REGEX = r'/mediathek/(?P<media_type>[^/]+)/(?P<type>[^/]+)/(?P<display_id>.+)\.html'
  19. _VALID_URL = r'(?P<page_url>https?://(?:www\d\.)?wdr\d?\.de)' + _PAGE_REGEX + '|' + _CURRENT_MAUS_URL
  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. # for wdr.de the data-extension is in a tag with the class "mediaLink"
  98. # for wdrmaus its in a link to the page in a multiline "videoLink"-tag
  99. json_metadata = self._html_search_regex(
  100. r'class=(?:"mediaLink\b[^"]*"[^>]+|"videoLink\b[^"]*"[\s]*>\n[^\n]*)data-extension="([^"]+)"',
  101. webpage, 'media link', default=None, flags=re.MULTILINE)
  102. if not json_metadata:
  103. entries = [
  104. self.url_result(page_url + href[0], 'WDR')
  105. for href in re.findall(
  106. r'<a href="(%s)"' % self._PAGE_REGEX,
  107. webpage)
  108. ]
  109. if entries: # Playlist page
  110. return self.playlist_result(entries, playlist_id=display_id)
  111. raise ExtractorError('No downloadable streams found', expected=True)
  112. media_link_obj = self._parse_json(json_metadata, display_id,
  113. transform_source=js_to_json)
  114. jsonp_url = media_link_obj['mediaObj']['url']
  115. metadata = self._download_json(
  116. jsonp_url, 'metadata', transform_source=strip_jsonp)
  117. metadata_tracker_data = metadata['trackerData']
  118. metadata_media_resource = metadata['mediaResource']
  119. formats = []
  120. # check if the metadata contains a direct URL to a file
  121. metadata_media_alt = metadata_media_resource.get('alt')
  122. if metadata_media_alt:
  123. for tag_name in ['videoURL', 'audioURL']:
  124. if tag_name in metadata_media_alt:
  125. alt_url = metadata_media_alt[tag_name]
  126. if determine_ext(alt_url) == 'm3u8':
  127. m3u_fmt = self._extract_m3u8_formats(
  128. alt_url, display_id, 'mp4', 'm3u8_native',
  129. m3u8_id='hls')
  130. formats.extend(m3u_fmt)
  131. else:
  132. formats.append({
  133. 'url': alt_url
  134. })
  135. # check if there are flash-streams for this video
  136. if 'dflt' in metadata_media_resource and 'videoURL' in metadata_media_resource['dflt']:
  137. video_url = metadata_media_resource['dflt']['videoURL']
  138. if video_url.endswith('.f4m'):
  139. full_video_url = video_url + '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18'
  140. formats.extend(self._extract_f4m_formats(full_video_url, display_id, f4m_id='hds', fatal=False))
  141. elif video_url.endswith('.smil'):
  142. formats.extend(self._extract_smil_formats(video_url, 'stream', fatal=False))
  143. subtitles = {}
  144. caption_url = metadata_media_resource.get('captionURL')
  145. if caption_url:
  146. subtitles['de'] = [{
  147. 'url': caption_url
  148. }]
  149. title = metadata_tracker_data.get('trackerClipTitle')
  150. is_live = url_type == 'live'
  151. if is_live:
  152. title = self._live_title(title)
  153. upload_date = None
  154. elif 'trackerClipAirTime' in metadata_tracker_data:
  155. upload_date = metadata_tracker_data['trackerClipAirTime']
  156. else:
  157. upload_date = self._html_search_meta('DC.Date', webpage, 'upload date')
  158. if upload_date:
  159. upload_date = unified_strdate(upload_date)
  160. self._sort_formats(formats)
  161. return {
  162. 'id': metadata_tracker_data.get('trackerClipId', display_id),
  163. 'display_id': display_id,
  164. 'title': title,
  165. 'alt_title': metadata_tracker_data.get('trackerClipSubcategory'),
  166. 'formats': formats,
  167. 'upload_date': upload_date,
  168. 'description': self._html_search_meta('Description', webpage),
  169. 'is_live': is_live,
  170. 'subtitles': subtitles,
  171. }
  172. class WDRMobileIE(InfoExtractor):
  173. _VALID_URL = r'''(?x)
  174. https?://mobile-ondemand\.wdr\.de/
  175. .*?/fsk(?P<age_limit>[0-9]+)
  176. /[0-9]+/[0-9]+/
  177. (?P<id>[0-9]+)_(?P<title>[0-9]+)'''
  178. IE_NAME = 'wdr:mobile'
  179. _TEST = {
  180. 'url': 'http://mobile-ondemand.wdr.de/CMS2010/mdb/ondemand/weltweit/fsk0/42/421735/421735_4283021.mp4',
  181. 'info_dict': {
  182. 'title': '4283021',
  183. 'id': '421735',
  184. 'ext': 'mp4',
  185. 'age_limit': 0,
  186. },
  187. 'skip': 'Problems with loading data.'
  188. }
  189. def _real_extract(self, url):
  190. mobj = re.match(self._VALID_URL, url)
  191. return {
  192. 'id': mobj.group('id'),
  193. 'title': mobj.group('title'),
  194. 'age_limit': int(mobj.group('age_limit')),
  195. 'url': url,
  196. 'http_headers': {
  197. 'User-Agent': 'mobile',
  198. },
  199. }
  200. class WDRMausIE(InfoExtractor):
  201. _VALID_URL = 'https?://(?:www\.)?wdrmaus\.de/(?:[^/]+/){,2}(?P<id>[^/?#]+)((?<!index)\.php5|/(?:$|[?#]))'
  202. IE_DESC = 'Sendung mit der Maus'
  203. _TESTS = [{
  204. 'url': 'http://www.wdrmaus.de/sachgeschichten/sachgeschichten/achterbahn.php5',
  205. 'md5': '178b432d002162a14ccb3e0876741095',
  206. 'info_dict': {
  207. 'id': 'achterbahn',
  208. 'ext': 'mp4',
  209. 'thumbnail': 're:^http://.+\.jpg',
  210. 'upload_date': '20131001',
  211. 'title': '19.09.2013 - Achterbahn',
  212. }
  213. }]
  214. def _real_extract(self, url):
  215. video_id = self._match_id(url)
  216. webpage = self._download_webpage(url, video_id)
  217. param_code = self._html_search_regex(
  218. r'<a href="\?startVideo=1&amp;([^"]+)"', webpage, 'parameters')
  219. title_date = self._search_regex(
  220. r'<div class="sendedatum"><p>Sendedatum:\s*([0-9\.]+)</p>',
  221. webpage, 'air date')
  222. title_str = self._html_search_regex(
  223. r'<h1>(.*?)</h1>', webpage, 'title')
  224. title = '%s - %s' % (title_date, title_str)
  225. upload_date = unified_strdate(
  226. self._html_search_meta('dc.date', webpage))
  227. fields = compat_parse_qs(param_code)
  228. video_url = fields['firstVideo'][0]
  229. thumbnail = compat_urlparse.urljoin(url, fields['startPicture'][0])
  230. formats = [{
  231. 'format_id': 'rtmp',
  232. 'url': video_url,
  233. }]
  234. jscode = self._download_webpage(
  235. 'http://www.wdrmaus.de/codebase/js/extended-medien.min.js',
  236. video_id, fatal=False,
  237. note='Downloading URL translation table',
  238. errnote='Could not download URL translation table')
  239. if jscode:
  240. for m in re.finditer(
  241. r"stream:\s*'dslSrc=(?P<stream>[^']+)',\s*download:\s*'(?P<dl>[^']+)'\s*\}",
  242. jscode):
  243. if video_url.startswith(m.group('stream')):
  244. http_url = video_url.replace(
  245. m.group('stream'), m.group('dl'))
  246. formats.append({
  247. 'format_id': 'http',
  248. 'url': http_url,
  249. })
  250. break
  251. self._sort_formats(formats)
  252. return {
  253. 'id': video_id,
  254. 'title': title,
  255. 'formats': formats,
  256. 'thumbnail': thumbnail,
  257. 'upload_date': upload_date,
  258. }