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.

251 lines
8.6 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. },
  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. 'user_agent': 'mobile',
  153. }
  154. class WDRMausIE(InfoExtractor):
  155. _VALID_URL = 'http://(?:www\.)?wdrmaus\.de/(?:[^/]+/){,2}(?P<id>[^/?#]+)(?:/index\.php5|(?<!index)\.php5|/(?:$|[?#]))'
  156. IE_DESC = 'Sendung mit der Maus'
  157. _TESTS = [{
  158. 'url': 'http://www.wdrmaus.de/aktuelle-sendung/index.php5',
  159. 'info_dict': {
  160. 'id': 'aktuelle-sendung',
  161. 'ext': 'mp4',
  162. 'thumbnail': 're:^http://.+\.jpg',
  163. 'upload_date': 're:^[0-9]{8}$',
  164. 'title': 're:^[0-9.]{10} - Aktuelle Sendung$',
  165. }
  166. }, {
  167. 'url': 'http://www.wdrmaus.de/sachgeschichten/sachgeschichten/40_jahre_maus.php5',
  168. 'md5': '3b1227ca3ed28d73ec5737c65743b2a3',
  169. 'info_dict': {
  170. 'id': '40_jahre_maus',
  171. 'ext': 'mp4',
  172. 'thumbnail': 're:^http://.+\.jpg',
  173. 'upload_date': '20131007',
  174. 'title': '12.03.2011 - 40 Jahre Maus',
  175. }
  176. }]
  177. def _real_extract(self, url):
  178. video_id = self._match_id(url)
  179. webpage = self._download_webpage(url, video_id)
  180. param_code = self._html_search_regex(
  181. r'<a href="\?startVideo=1&amp;([^"]+)"', webpage, 'parameters')
  182. title_date = self._search_regex(
  183. r'<div class="sendedatum"><p>Sendedatum:\s*([0-9\.]+)</p>',
  184. webpage, 'air date')
  185. title_str = self._html_search_regex(
  186. r'<h1>(.*?)</h1>', webpage, 'title')
  187. title = '%s - %s' % (title_date, title_str)
  188. upload_date = unified_strdate(
  189. self._html_search_meta('dc.date', webpage))
  190. fields = compat_parse_qs(param_code)
  191. video_url = fields['firstVideo'][0]
  192. thumbnail = compat_urlparse.urljoin(url, fields['startPicture'][0])
  193. formats = [{
  194. 'format_id': 'rtmp',
  195. 'url': video_url,
  196. }]
  197. jscode = self._download_webpage(
  198. 'http://www.wdrmaus.de/codebase/js/extended-medien.min.js',
  199. video_id, fatal=False,
  200. note='Downloading URL translation table',
  201. errnote='Could not download URL translation table')
  202. if jscode:
  203. for m in re.finditer(
  204. r"stream:\s*'dslSrc=(?P<stream>[^']+)',\s*download:\s*'(?P<dl>[^']+)'\s*\}",
  205. jscode):
  206. if video_url.startswith(m.group('stream')):
  207. http_url = video_url.replace(
  208. m.group('stream'), m.group('dl'))
  209. formats.append({
  210. 'format_id': 'http',
  211. 'url': http_url,
  212. })
  213. break
  214. self._sort_formats(formats)
  215. return {
  216. 'id': video_id,
  217. 'title': title,
  218. 'formats': formats,
  219. 'thumbnail': thumbnail,
  220. 'upload_date': upload_date,
  221. }