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.

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