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.

316 lines
11 KiB

10 years ago
10 years ago
10 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(r'<a href="/?(.+?%s\.html)" rel="nofollow"' % self._PLAYER_REGEX, webpage)
  104. ]
  105. if entries: # Playlist page
  106. return self.playlist_result(entries, page_id)
  107. # Overview page
  108. entries = []
  109. for page_num in itertools.count(2):
  110. hrefs = re.findall(
  111. r'<li class="mediathekvideo"\s*>\s*<img[^>]*>\s*<a href="(/mediathek/video/[^"]+)"',
  112. webpage)
  113. entries.extend(
  114. self.url_result(page_url + href, 'WDR')
  115. for href in hrefs)
  116. next_url_m = re.search(
  117. r'<li class="nextToLast">\s*<a href="([^"]+)"', webpage)
  118. if not next_url_m:
  119. break
  120. next_url = page_url + next_url_m.group(1)
  121. webpage = self._download_webpage(
  122. next_url, page_id,
  123. note='Downloading playlist page %d' % page_num)
  124. return self.playlist_result(entries, page_id)
  125. flashvars = compat_parse_qs(
  126. self._html_search_regex(r'<param name="flashvars" value="([^"]+)"', webpage, 'flashvars'))
  127. page_id = flashvars['trackerClipId'][0]
  128. video_url = flashvars['dslSrc'][0]
  129. title = flashvars['trackerClipTitle'][0]
  130. thumbnail = flashvars['startPicture'][0] if 'startPicture' in flashvars else None
  131. is_live = flashvars.get('isLive', ['0'])[0] == '1'
  132. if is_live:
  133. title = self._live_title(title)
  134. if 'trackerClipAirTime' in flashvars:
  135. upload_date = flashvars['trackerClipAirTime'][0]
  136. else:
  137. upload_date = self._html_search_meta('DC.Date', webpage, 'upload date')
  138. if upload_date:
  139. upload_date = unified_strdate(upload_date)
  140. formats = []
  141. preference = qualities(['S', 'M', 'L', 'XL'])
  142. if video_url.endswith('.f4m'):
  143. f4m_formats = self._extract_f4m_formats(video_url + '?hdcore=3.2.0&plugin=aasp-3.2.0.77.18', page_id, f4m_id='hds', fatal=False)
  144. if f4m_formats:
  145. formats.extend(f4m_formats)
  146. elif video_url.endswith('.smil'):
  147. smil_formats = self._extract_smil_formats(video_url, page_id, False, {
  148. 'hdcore': '3.3.0',
  149. 'plugin': 'aasp-3.3.0.99.43',
  150. })
  151. if smil_formats:
  152. formats.extend(smil_formats)
  153. else:
  154. formats.append({
  155. 'url': video_url,
  156. 'http_headers': {
  157. 'User-Agent': 'mobile',
  158. },
  159. })
  160. m3u8_url = self._search_regex(r'rel="adaptiv"[^>]+href="([^"]+)"', webpage, 'm3u8 url', default=None)
  161. if m3u8_url:
  162. m3u8_formats = self._extract_m3u8_formats(m3u8_url, page_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False)
  163. if m3u8_formats:
  164. formats.extend(m3u8_formats)
  165. direct_urls = re.findall(r'rel="web(S|M|L|XL)"[^>]+href="([^"]+)"', webpage)
  166. if direct_urls:
  167. for quality, video_url in direct_urls:
  168. formats.append({
  169. 'url': video_url,
  170. 'preference': preference(quality),
  171. 'http_headers': {
  172. 'User-Agent': 'mobile',
  173. },
  174. })
  175. self._sort_formats(formats)
  176. description = self._html_search_meta('Description', webpage, 'description')
  177. return {
  178. 'id': page_id,
  179. 'formats': formats,
  180. 'title': title,
  181. 'description': description,
  182. 'thumbnail': thumbnail,
  183. 'upload_date': upload_date,
  184. 'is_live': is_live
  185. }
  186. class WDRMobileIE(InfoExtractor):
  187. _VALID_URL = r'''(?x)
  188. https?://mobile-ondemand\.wdr\.de/
  189. .*?/fsk(?P<age_limit>[0-9]+)
  190. /[0-9]+/[0-9]+/
  191. (?P<id>[0-9]+)_(?P<title>[0-9]+)'''
  192. IE_NAME = 'wdr:mobile'
  193. _TEST = {
  194. 'url': 'http://mobile-ondemand.wdr.de/CMS2010/mdb/ondemand/weltweit/fsk0/42/421735/421735_4283021.mp4',
  195. 'info_dict': {
  196. 'title': '4283021',
  197. 'id': '421735',
  198. 'ext': 'mp4',
  199. 'age_limit': 0,
  200. },
  201. 'skip': 'Problems with loading data.'
  202. }
  203. def _real_extract(self, url):
  204. mobj = re.match(self._VALID_URL, url)
  205. return {
  206. 'id': mobj.group('id'),
  207. 'title': mobj.group('title'),
  208. 'age_limit': int(mobj.group('age_limit')),
  209. 'url': url,
  210. 'http_headers': {
  211. 'User-Agent': 'mobile',
  212. },
  213. }
  214. class WDRMausIE(InfoExtractor):
  215. _VALID_URL = 'http://(?:www\.)?wdrmaus\.de/(?:[^/]+/){,2}(?P<id>[^/?#]+)(?:/index\.php5|(?<!index)\.php5|/(?:$|[?#]))'
  216. IE_DESC = 'Sendung mit der Maus'
  217. _TESTS = [{
  218. 'url': 'http://www.wdrmaus.de/aktuelle-sendung/index.php5',
  219. 'info_dict': {
  220. 'id': 'aktuelle-sendung',
  221. 'ext': 'mp4',
  222. 'thumbnail': 're:^http://.+\.jpg',
  223. 'upload_date': 're:^[0-9]{8}$',
  224. 'title': 're:^[0-9.]{10} - Aktuelle Sendung$',
  225. }
  226. }, {
  227. 'url': 'http://www.wdrmaus.de/sachgeschichten/sachgeschichten/40_jahre_maus.php5',
  228. 'md5': '3b1227ca3ed28d73ec5737c65743b2a3',
  229. 'info_dict': {
  230. 'id': '40_jahre_maus',
  231. 'ext': 'mp4',
  232. 'thumbnail': 're:^http://.+\.jpg',
  233. 'upload_date': '20131007',
  234. 'title': '12.03.2011 - 40 Jahre Maus',
  235. }
  236. }]
  237. def _real_extract(self, url):
  238. video_id = self._match_id(url)
  239. webpage = self._download_webpage(url, video_id)
  240. param_code = self._html_search_regex(
  241. r'<a href="\?startVideo=1&amp;([^"]+)"', webpage, 'parameters')
  242. title_date = self._search_regex(
  243. r'<div class="sendedatum"><p>Sendedatum:\s*([0-9\.]+)</p>',
  244. webpage, 'air date')
  245. title_str = self._html_search_regex(
  246. r'<h1>(.*?)</h1>', webpage, 'title')
  247. title = '%s - %s' % (title_date, title_str)
  248. upload_date = unified_strdate(
  249. self._html_search_meta('dc.date', webpage))
  250. fields = compat_parse_qs(param_code)
  251. video_url = fields['firstVideo'][0]
  252. thumbnail = compat_urlparse.urljoin(url, fields['startPicture'][0])
  253. formats = [{
  254. 'format_id': 'rtmp',
  255. 'url': video_url,
  256. }]
  257. jscode = self._download_webpage(
  258. 'http://www.wdrmaus.de/codebase/js/extended-medien.min.js',
  259. video_id, fatal=False,
  260. note='Downloading URL translation table',
  261. errnote='Could not download URL translation table')
  262. if jscode:
  263. for m in re.finditer(
  264. r"stream:\s*'dslSrc=(?P<stream>[^']+)',\s*download:\s*'(?P<dl>[^']+)'\s*\}",
  265. jscode):
  266. if video_url.startswith(m.group('stream')):
  267. http_url = video_url.replace(
  268. m.group('stream'), m.group('dl'))
  269. formats.append({
  270. 'format_id': 'http',
  271. 'url': http_url,
  272. })
  273. break
  274. self._sort_formats(formats)
  275. return {
  276. 'id': video_id,
  277. 'title': title,
  278. 'formats': formats,
  279. 'thumbnail': thumbnail,
  280. 'upload_date': upload_date,
  281. }