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.

265 lines
9.8 KiB

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