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.

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