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.

310 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(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. formats.extend(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. elif video_url.endswith('.smil'):
  145. formats.extend(self._extract_smil_formats(video_url, page_id, False, {
  146. 'hdcore': '3.3.0',
  147. 'plugin': 'aasp-3.3.0.99.43',
  148. }))
  149. else:
  150. formats.append({
  151. 'url': video_url,
  152. 'http_headers': {
  153. 'User-Agent': 'mobile',
  154. },
  155. })
  156. m3u8_url = self._search_regex(r'rel="adaptiv"[^>]+href="([^"]+)"', webpage, 'm3u8 url', default=None)
  157. if m3u8_url:
  158. formats.extend(self._extract_m3u8_formats(m3u8_url, page_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  159. direct_urls = re.findall(r'rel="web(S|M|L|XL)"[^>]+href="([^"]+)"', webpage)
  160. if direct_urls:
  161. for quality, video_url in direct_urls:
  162. formats.append({
  163. 'url': video_url,
  164. 'preference': preference(quality),
  165. 'http_headers': {
  166. 'User-Agent': 'mobile',
  167. },
  168. })
  169. self._sort_formats(formats)
  170. description = self._html_search_meta('Description', webpage, 'description')
  171. return {
  172. 'id': page_id,
  173. 'formats': formats,
  174. 'title': title,
  175. 'description': description,
  176. 'thumbnail': thumbnail,
  177. 'upload_date': upload_date,
  178. 'is_live': is_live
  179. }
  180. class WDRMobileIE(InfoExtractor):
  181. _VALID_URL = r'''(?x)
  182. https?://mobile-ondemand\.wdr\.de/
  183. .*?/fsk(?P<age_limit>[0-9]+)
  184. /[0-9]+/[0-9]+/
  185. (?P<id>[0-9]+)_(?P<title>[0-9]+)'''
  186. IE_NAME = 'wdr:mobile'
  187. _TEST = {
  188. 'url': 'http://mobile-ondemand.wdr.de/CMS2010/mdb/ondemand/weltweit/fsk0/42/421735/421735_4283021.mp4',
  189. 'info_dict': {
  190. 'title': '4283021',
  191. 'id': '421735',
  192. 'ext': 'mp4',
  193. 'age_limit': 0,
  194. },
  195. 'skip': 'Problems with loading data.'
  196. }
  197. def _real_extract(self, url):
  198. mobj = re.match(self._VALID_URL, url)
  199. return {
  200. 'id': mobj.group('id'),
  201. 'title': mobj.group('title'),
  202. 'age_limit': int(mobj.group('age_limit')),
  203. 'url': url,
  204. 'http_headers': {
  205. 'User-Agent': 'mobile',
  206. },
  207. }
  208. class WDRMausIE(InfoExtractor):
  209. _VALID_URL = 'http://(?:www\.)?wdrmaus\.de/(?:[^/]+/){,2}(?P<id>[^/?#]+)(?:/index\.php5|(?<!index)\.php5|/(?:$|[?#]))'
  210. IE_DESC = 'Sendung mit der Maus'
  211. _TESTS = [{
  212. 'url': 'http://www.wdrmaus.de/aktuelle-sendung/index.php5',
  213. 'info_dict': {
  214. 'id': 'aktuelle-sendung',
  215. 'ext': 'mp4',
  216. 'thumbnail': 're:^http://.+\.jpg',
  217. 'upload_date': 're:^[0-9]{8}$',
  218. 'title': 're:^[0-9.]{10} - Aktuelle Sendung$',
  219. }
  220. }, {
  221. 'url': 'http://www.wdrmaus.de/sachgeschichten/sachgeschichten/40_jahre_maus.php5',
  222. 'md5': '3b1227ca3ed28d73ec5737c65743b2a3',
  223. 'info_dict': {
  224. 'id': '40_jahre_maus',
  225. 'ext': 'mp4',
  226. 'thumbnail': 're:^http://.+\.jpg',
  227. 'upload_date': '20131007',
  228. 'title': '12.03.2011 - 40 Jahre Maus',
  229. }
  230. }]
  231. def _real_extract(self, url):
  232. video_id = self._match_id(url)
  233. webpage = self._download_webpage(url, video_id)
  234. param_code = self._html_search_regex(
  235. r'<a href="\?startVideo=1&amp;([^"]+)"', webpage, 'parameters')
  236. title_date = self._search_regex(
  237. r'<div class="sendedatum"><p>Sendedatum:\s*([0-9\.]+)</p>',
  238. webpage, 'air date')
  239. title_str = self._html_search_regex(
  240. r'<h1>(.*?)</h1>', webpage, 'title')
  241. title = '%s - %s' % (title_date, title_str)
  242. upload_date = unified_strdate(
  243. self._html_search_meta('dc.date', webpage))
  244. fields = compat_parse_qs(param_code)
  245. video_url = fields['firstVideo'][0]
  246. thumbnail = compat_urlparse.urljoin(url, fields['startPicture'][0])
  247. formats = [{
  248. 'format_id': 'rtmp',
  249. 'url': video_url,
  250. }]
  251. jscode = self._download_webpage(
  252. 'http://www.wdrmaus.de/codebase/js/extended-medien.min.js',
  253. video_id, fatal=False,
  254. note='Downloading URL translation table',
  255. errnote='Could not download URL translation table')
  256. if jscode:
  257. for m in re.finditer(
  258. r"stream:\s*'dslSrc=(?P<stream>[^']+)',\s*download:\s*'(?P<dl>[^']+)'\s*\}",
  259. jscode):
  260. if video_url.startswith(m.group('stream')):
  261. http_url = video_url.replace(
  262. m.group('stream'), m.group('dl'))
  263. formats.append({
  264. 'format_id': 'http',
  265. 'url': http_url,
  266. })
  267. break
  268. self._sort_formats(formats)
  269. return {
  270. 'id': video_id,
  271. 'title': title,
  272. 'formats': formats,
  273. 'thumbnail': thumbnail,
  274. 'upload_date': upload_date,
  275. }