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.

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