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.

253 lines
9.5 KiB

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