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.

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