wdr.py 10 KB

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