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.

321 lines
11 KiB

11 years ago
11 years ago
11 years ago
10 years ago
  1. # -*- coding: utf-8 -*-
  2. from __future__ import unicode_literals
  3. import itertools
  4. import re
  5. from .common import InfoExtractor
  6. from ..compat import (
  7. compat_parse_qs,
  8. compat_urlparse,
  9. )
  10. from ..utils import (
  11. unified_strdate,
  12. qualities,
  13. )
  14. class WDRIE(InfoExtractor):
  15. _PLAYER_REGEX = '-(?:video|audio)player(?:_size-[LMS])?'
  16. _VALID_URL = r'(?P<url>https?://www\d?\.(?:wdr\d?|funkhauseuropa)\.de/)(?P<id>.+?)(?P<player>%s)?\.html' % _PLAYER_REGEX
  17. _TESTS = [
  18. {
  19. 'url': 'http://www1.wdr.de/mediathek/video/sendungen/servicezeit/videoservicezeit560-videoplayer_size-L.html',
  20. 'info_dict': {
  21. 'id': 'mdb-362427',
  22. 'ext': 'flv',
  23. 'title': 'Servicezeit',
  24. 'description': 'md5:c8f43e5e815eeb54d0b96df2fba906cb',
  25. 'upload_date': '20140310',
  26. 'is_live': False
  27. },
  28. 'params': {
  29. 'skip_download': True,
  30. },
  31. 'skip': 'Page Not Found',
  32. },
  33. {
  34. 'url': 'http://www1.wdr.de/themen/av/videomargaspiegelisttot101-videoplayer.html',
  35. 'info_dict': {
  36. 'id': 'mdb-363194',
  37. 'ext': 'flv',
  38. 'title': 'Marga Spiegel ist tot',
  39. 'description': 'md5:2309992a6716c347891c045be50992e4',
  40. 'upload_date': '20140311',
  41. 'is_live': False
  42. },
  43. 'params': {
  44. 'skip_download': True,
  45. },
  46. 'skip': 'Page Not Found',
  47. },
  48. {
  49. 'url': 'http://www1.wdr.de/themen/kultur/audioerlebtegeschichtenmargaspiegel100-audioplayer.html',
  50. 'md5': '83e9e8fefad36f357278759870805898',
  51. 'info_dict': {
  52. 'id': 'mdb-194332',
  53. 'ext': 'mp3',
  54. 'title': 'Erlebte Geschichten: Marga Spiegel (29.11.2009)',
  55. 'description': 'md5:2309992a6716c347891c045be50992e4',
  56. 'upload_date': '20091129',
  57. 'is_live': False
  58. },
  59. },
  60. {
  61. 'url': 'http://www.funkhauseuropa.de/av/audioflaviacoelhoamaramar100-audioplayer.html',
  62. 'md5': '99a1443ff29af19f6c52cf6f4dc1f4aa',
  63. 'info_dict': {
  64. 'id': 'mdb-478135',
  65. 'ext': 'mp3',
  66. 'title': 'Flavia Coelho: Amar é Amar',
  67. 'description': 'md5:7b29e97e10dfb6e265238b32fa35b23a',
  68. 'upload_date': '20140717',
  69. 'is_live': False
  70. },
  71. 'skip': 'Page Not Found',
  72. },
  73. {
  74. 'url': 'http://www1.wdr.de/mediathek/video/sendungen/quarks_und_co/filterseite-quarks-und-co100.html',
  75. 'playlist_mincount': 146,
  76. 'info_dict': {
  77. 'id': 'mediathek/video/sendungen/quarks_und_co/filterseite-quarks-und-co100',
  78. }
  79. },
  80. {
  81. 'url': 'http://www1.wdr.de/mediathek/video/livestream/index.html',
  82. 'info_dict': {
  83. 'id': 'mdb-103364',
  84. 'title': 're:^WDR Fernsehen Live [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}$',
  85. 'description': 'md5:ae2ff888510623bf8d4b115f95a9b7c9',
  86. 'ext': 'flv',
  87. 'upload_date': '20150101',
  88. 'is_live': True
  89. },
  90. 'params': {
  91. 'skip_download': True,
  92. },
  93. }
  94. ]
  95. def _real_extract(self, url):
  96. mobj = re.match(self._VALID_URL, url)
  97. page_url = mobj.group('url')
  98. page_id = mobj.group('id')
  99. webpage = self._download_webpage(url, page_id)
  100. if mobj.group('player') is None:
  101. entries = [
  102. self.url_result(page_url + href, 'WDR')
  103. for href in re.findall(
  104. r'<a href="/?(.+?%s\.html)" rel="nofollow"' % self._PLAYER_REGEX,
  105. webpage)
  106. ]
  107. if entries: # Playlist page
  108. return self.playlist_result(entries, page_id)
  109. # Overview page
  110. entries = []
  111. for page_num in itertools.count(2):
  112. hrefs = re.findall(
  113. r'<li class="mediathekvideo"\s*>\s*<img[^>]*>\s*<a href="(/mediathek/video/[^"]+)"',
  114. webpage)
  115. entries.extend(
  116. self.url_result(page_url + href, 'WDR')
  117. for href in hrefs)
  118. next_url_m = re.search(
  119. r'<li class="nextToLast">\s*<a href="([^"]+)"', webpage)
  120. if not next_url_m:
  121. break
  122. next_url = page_url + next_url_m.group(1)
  123. webpage = self._download_webpage(
  124. next_url, page_id,
  125. note='Downloading playlist page %d' % page_num)
  126. return self.playlist_result(entries, page_id)
  127. flashvars = compat_parse_qs(self._html_search_regex(
  128. r'<param name="flashvars" value="([^"]+)"', webpage, 'flashvars'))
  129. page_id = flashvars['trackerClipId'][0]
  130. video_url = flashvars['dslSrc'][0]
  131. title = flashvars['trackerClipTitle'][0]
  132. thumbnail = flashvars['startPicture'][0] if 'startPicture' in flashvars else None
  133. is_live = flashvars.get('isLive', ['0'])[0] == '1'
  134. if is_live:
  135. title = self._live_title(title)
  136. if 'trackerClipAirTime' in flashvars:
  137. upload_date = flashvars['trackerClipAirTime'][0]
  138. else:
  139. upload_date = self._html_search_meta(
  140. 'DC.Date', webpage, 'upload date')
  141. if upload_date:
  142. upload_date = unified_strdate(upload_date)
  143. formats = []
  144. preference = qualities(['S', 'M', 'L', 'XL'])
  145. if video_url.endswith('.f4m'):
  146. formats.extend(self._extract_f4m_formats(
  147. video_url + '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18', page_id,
  148. f4m_id='hds', fatal=False))
  149. elif video_url.endswith('.smil'):
  150. formats.extend(self._extract_smil_formats(
  151. video_url, page_id, False, {
  152. 'hdcore': '3.3.0',
  153. 'plugin': 'aasp-3.3.0.99.43',
  154. }))
  155. else:
  156. formats.append({
  157. 'url': video_url,
  158. 'http_headers': {
  159. 'User-Agent': 'mobile',
  160. },
  161. })
  162. m3u8_url = self._search_regex(
  163. r'rel="adaptiv"[^>]+href="([^"]+)"',
  164. webpage, 'm3u8 url', default=None)
  165. if m3u8_url:
  166. formats.extend(self._extract_m3u8_formats(
  167. m3u8_url, page_id, 'mp4', 'm3u8_native',
  168. m3u8_id='hls', fatal=False))
  169. direct_urls = re.findall(
  170. r'rel="web(S|M|L|XL)"[^>]+href="([^"]+)"', webpage)
  171. if direct_urls:
  172. for quality, video_url in direct_urls:
  173. formats.append({
  174. 'url': video_url,
  175. 'preference': preference(quality),
  176. 'http_headers': {
  177. 'User-Agent': 'mobile',
  178. },
  179. })
  180. self._sort_formats(formats)
  181. description = self._html_search_meta('Description', webpage, 'description')
  182. return {
  183. 'id': page_id,
  184. 'formats': formats,
  185. 'title': title,
  186. 'description': description,
  187. 'thumbnail': thumbnail,
  188. 'upload_date': upload_date,
  189. 'is_live': is_live
  190. }
  191. class WDRMobileIE(InfoExtractor):
  192. _VALID_URL = r'''(?x)
  193. https?://mobile-ondemand\.wdr\.de/
  194. .*?/fsk(?P<age_limit>[0-9]+)
  195. /[0-9]+/[0-9]+/
  196. (?P<id>[0-9]+)_(?P<title>[0-9]+)'''
  197. IE_NAME = 'wdr:mobile'
  198. _TEST = {
  199. 'url': 'http://mobile-ondemand.wdr.de/CMS2010/mdb/ondemand/weltweit/fsk0/42/421735/421735_4283021.mp4',
  200. 'info_dict': {
  201. 'title': '4283021',
  202. 'id': '421735',
  203. 'ext': 'mp4',
  204. 'age_limit': 0,
  205. },
  206. 'skip': 'Problems with loading data.'
  207. }
  208. def _real_extract(self, url):
  209. mobj = re.match(self._VALID_URL, url)
  210. return {
  211. 'id': mobj.group('id'),
  212. 'title': mobj.group('title'),
  213. 'age_limit': int(mobj.group('age_limit')),
  214. 'url': url,
  215. 'http_headers': {
  216. 'User-Agent': 'mobile',
  217. },
  218. }
  219. class WDRMausIE(InfoExtractor):
  220. _VALID_URL = r'https?://(?:www\.)?wdrmaus\.de/(?:[^/]+/){,2}(?P<id>[^/?#]+)(?:/index\.php5|(?<!index)\.php5|/(?:$|[?#]))'
  221. IE_DESC = 'Sendung mit der Maus'
  222. _TESTS = [{
  223. 'url': 'http://www.wdrmaus.de/aktuelle-sendung/index.php5',
  224. 'info_dict': {
  225. 'id': 'aktuelle-sendung',
  226. 'ext': 'mp4',
  227. 'thumbnail': 're:^http://.+\.jpg',
  228. 'upload_date': 're:^[0-9]{8}$',
  229. 'title': 're:^[0-9.]{10} - Aktuelle Sendung$',
  230. }
  231. }, {
  232. 'url': 'http://www.wdrmaus.de/sachgeschichten/sachgeschichten/40_jahre_maus.php5',
  233. 'md5': '3b1227ca3ed28d73ec5737c65743b2a3',
  234. 'info_dict': {
  235. 'id': '40_jahre_maus',
  236. 'ext': 'mp4',
  237. 'thumbnail': 're:^http://.+\.jpg',
  238. 'upload_date': '20131007',
  239. 'title': '12.03.2011 - 40 Jahre Maus',
  240. }
  241. }]
  242. def _real_extract(self, url):
  243. video_id = self._match_id(url)
  244. webpage = self._download_webpage(url, video_id)
  245. param_code = self._html_search_regex(
  246. r'<a href="\?startVideo=1&amp;([^"]+)"', webpage, 'parameters')
  247. title_date = self._search_regex(
  248. r'<div class="sendedatum"><p>Sendedatum:\s*([0-9\.]+)</p>',
  249. webpage, 'air date')
  250. title_str = self._html_search_regex(
  251. r'<h1>(.*?)</h1>', webpage, 'title')
  252. title = '%s - %s' % (title_date, title_str)
  253. upload_date = unified_strdate(
  254. self._html_search_meta('dc.date', webpage))
  255. fields = compat_parse_qs(param_code)
  256. video_url = fields['firstVideo'][0]
  257. thumbnail = compat_urlparse.urljoin(url, fields['startPicture'][0])
  258. formats = [{
  259. 'format_id': 'rtmp',
  260. 'url': video_url,
  261. }]
  262. jscode = self._download_webpage(
  263. 'http://www.wdrmaus.de/codebase/js/extended-medien.min.js',
  264. video_id, fatal=False,
  265. note='Downloading URL translation table',
  266. errnote='Could not download URL translation table')
  267. if jscode:
  268. for m in re.finditer(
  269. r"stream:\s*'dslSrc=(?P<stream>[^']+)',\s*download:\s*'(?P<dl>[^']+)'\s*\}",
  270. jscode):
  271. if video_url.startswith(m.group('stream')):
  272. http_url = video_url.replace(
  273. m.group('stream'), m.group('dl'))
  274. formats.append({
  275. 'format_id': 'http',
  276. 'url': http_url,
  277. })
  278. break
  279. self._sort_formats(formats)
  280. return {
  281. 'id': video_id,
  282. 'title': title,
  283. 'formats': formats,
  284. 'thumbnail': thumbnail,
  285. 'upload_date': upload_date,
  286. }