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.

354 lines
14 KiB

10 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from hashlib import sha1
  5. from .common import InfoExtractor
  6. from ..compat import (
  7. compat_urllib_parse,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. determine_ext,
  12. float_or_none,
  13. int_or_none,
  14. unified_strdate,
  15. )
  16. class ProSiebenSat1IE(InfoExtractor):
  17. IE_NAME = 'prosiebensat1'
  18. IE_DESC = 'ProSiebenSat.1 Digital'
  19. _VALID_URL = r'https?://(?:www\.)?(?:(?:prosieben|prosiebenmaxx|sixx|sat1|kabeleins|the-voice-of-germany)\.(?:de|at|ch)|ran\.de|fem\.com)/(?P<id>.+)'
  20. _TESTS = [
  21. {
  22. # Tests changes introduced in https://github.com/rg3/youtube-dl/pull/6242
  23. # in response to fixing https://github.com/rg3/youtube-dl/issues/6215:
  24. # - malformed f4m manifest support
  25. # - proper handling of URLs starting with `https?://` in 2.0 manifests
  26. # - recursive child f4m manifests extraction
  27. 'url': 'http://www.prosieben.de/tv/circus-halligalli/videos/218-staffel-2-episode-18-jahresrueckblick-ganze-folge',
  28. 'info_dict': {
  29. 'id': '2104602',
  30. 'ext': 'mp4',
  31. 'title': 'Episode 18 - Staffel 2',
  32. 'description': 'md5:8733c81b702ea472e069bc48bb658fc1',
  33. 'upload_date': '20131231',
  34. 'duration': 5845.04,
  35. },
  36. 'params': {
  37. # rtmp download
  38. 'skip_download': True,
  39. },
  40. },
  41. {
  42. 'url': 'http://www.prosieben.de/videokatalog/Gesellschaft/Leben/Trends/video-Lady-Umstyling-f%C3%BCr-Audrina-Rebekka-Audrina-Fergen-billig-aussehen-Battal-Modica-700544.html',
  43. 'info_dict': {
  44. 'id': '2570327',
  45. 'ext': 'mp4',
  46. 'title': 'Lady-Umstyling für Audrina',
  47. 'description': 'md5:4c16d0c17a3461a0d43ea4084e96319d',
  48. 'upload_date': '20131014',
  49. 'duration': 606.76,
  50. },
  51. 'params': {
  52. # rtmp download
  53. 'skip_download': True,
  54. },
  55. 'skip': 'Seems to be broken',
  56. },
  57. {
  58. 'url': 'http://www.prosiebenmaxx.de/tv/experience/video/144-countdown-fuer-die-autowerkstatt-ganze-folge',
  59. 'info_dict': {
  60. 'id': '2429369',
  61. 'ext': 'mp4',
  62. 'title': 'Countdown für die Autowerkstatt',
  63. 'description': 'md5:809fc051a457b5d8666013bc40698817',
  64. 'upload_date': '20140223',
  65. 'duration': 2595.04,
  66. },
  67. 'params': {
  68. # rtmp download
  69. 'skip_download': True,
  70. },
  71. },
  72. {
  73. 'url': 'http://www.sixx.de/stars-style/video/sexy-laufen-in-ugg-boots-clip',
  74. 'info_dict': {
  75. 'id': '2904997',
  76. 'ext': 'mp4',
  77. 'title': 'Sexy laufen in Ugg Boots',
  78. 'description': 'md5:edf42b8bd5bc4e5da4db4222c5acb7d6',
  79. 'upload_date': '20140122',
  80. 'duration': 245.32,
  81. },
  82. 'params': {
  83. # rtmp download
  84. 'skip_download': True,
  85. },
  86. },
  87. {
  88. 'url': 'http://www.sat1.de/film/der-ruecktritt/video/im-interview-kai-wiesinger-clip',
  89. 'info_dict': {
  90. 'id': '2906572',
  91. 'ext': 'mp4',
  92. 'title': 'Im Interview: Kai Wiesinger',
  93. 'description': 'md5:e4e5370652ec63b95023e914190b4eb9',
  94. 'upload_date': '20140203',
  95. 'duration': 522.56,
  96. },
  97. 'params': {
  98. # rtmp download
  99. 'skip_download': True,
  100. },
  101. },
  102. {
  103. 'url': 'http://www.kabeleins.de/tv/rosins-restaurants/videos/jagd-auf-fertigkost-im-elsthal-teil-2-ganze-folge',
  104. 'info_dict': {
  105. 'id': '2992323',
  106. 'ext': 'mp4',
  107. 'title': 'Jagd auf Fertigkost im Elsthal - Teil 2',
  108. 'description': 'md5:2669cde3febe9bce13904f701e774eb6',
  109. 'upload_date': '20141014',
  110. 'duration': 2410.44,
  111. },
  112. 'params': {
  113. # rtmp download
  114. 'skip_download': True,
  115. },
  116. },
  117. {
  118. 'url': 'http://www.ran.de/fussball/bundesliga/video/schalke-toennies-moechte-raul-zurueck-ganze-folge',
  119. 'info_dict': {
  120. 'id': '3004256',
  121. 'ext': 'mp4',
  122. 'title': 'Schalke: Tönnies möchte Raul zurück',
  123. 'description': 'md5:4b5b271d9bcde223b54390754c8ece3f',
  124. 'upload_date': '20140226',
  125. 'duration': 228.96,
  126. },
  127. 'params': {
  128. # rtmp download
  129. 'skip_download': True,
  130. },
  131. },
  132. {
  133. 'url': 'http://www.the-voice-of-germany.de/video/31-andreas-kuemmert-rocket-man-clip',
  134. 'info_dict': {
  135. 'id': '2572814',
  136. 'ext': 'mp4',
  137. 'title': 'Andreas Kümmert: Rocket Man',
  138. 'description': 'md5:6ddb02b0781c6adf778afea606652e38',
  139. 'upload_date': '20131017',
  140. 'duration': 469.88,
  141. },
  142. 'params': {
  143. # rtmp download
  144. 'skip_download': True,
  145. },
  146. },
  147. {
  148. 'url': 'http://www.fem.com/wellness/videos/wellness-video-clip-kurztripps-zum-valentinstag.html',
  149. 'info_dict': {
  150. 'id': '2156342',
  151. 'ext': 'mp4',
  152. 'title': 'Kurztrips zum Valentinstag',
  153. 'description': 'Romantischer Kurztrip zum Valentinstag? Wir verraten, was sich hier wirklich lohnt.',
  154. 'duration': 307.24,
  155. },
  156. 'params': {
  157. # rtmp download
  158. 'skip_download': True,
  159. },
  160. },
  161. {
  162. 'url': 'http://www.prosieben.de/tv/joko-gegen-klaas/videos/playlists/episode-8-ganze-folge-playlist',
  163. 'info_dict': {
  164. 'id': '439664',
  165. 'title': 'Episode 8 - Ganze Folge - Playlist',
  166. 'description': 'md5:63b8963e71f481782aeea877658dec84',
  167. },
  168. 'playlist_count': 2,
  169. },
  170. ]
  171. _CLIPID_REGEXES = [
  172. r'"clip_id"\s*:\s+"(\d+)"',
  173. r'clipid: "(\d+)"',
  174. r'clip[iI]d=(\d+)',
  175. r"'itemImageUrl'\s*:\s*'/dynamic/thumbnails/full/\d+/(\d+)",
  176. ]
  177. _TITLE_REGEXES = [
  178. r'<h2 class="subtitle" itemprop="name">\s*(.+?)</h2>',
  179. r'<header class="clearfix">\s*<h3>(.+?)</h3>',
  180. r'<!-- start video -->\s*<h1>(.+?)</h1>',
  181. r'<h1 class="att-name">\s*(.+?)</h1>',
  182. r'<header class="module_header">\s*<h2>([^<]+)</h2>\s*</header>',
  183. ]
  184. _DESCRIPTION_REGEXES = [
  185. r'<p itemprop="description">\s*(.+?)</p>',
  186. r'<div class="videoDecription">\s*<p><strong>Beschreibung</strong>: (.+?)</p>',
  187. r'<div class="g-plusone" data-size="medium"></div>\s*</div>\s*</header>\s*(.+?)\s*<footer>',
  188. r'<p class="att-description">\s*(.+?)\s*</p>',
  189. ]
  190. _UPLOAD_DATE_REGEXES = [
  191. r'<meta property="og:published_time" content="(.+?)">',
  192. r'<span>\s*(\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}) \|\s*<span itemprop="duration"',
  193. r'<footer>\s*(\d{2}\.\d{2}\.\d{4}) \d{2}:\d{2} Uhr',
  194. r'<span style="padding-left: 4px;line-height:20px; color:#404040">(\d{2}\.\d{2}\.\d{4})</span>',
  195. r'(\d{2}\.\d{2}\.\d{4}) \| \d{2}:\d{2} Min<br/>',
  196. ]
  197. _PAGE_TYPE_REGEXES = [
  198. r'<meta name="page_type" content="([^"]+)">',
  199. r"'itemType'\s*:\s*'([^']*)'",
  200. ]
  201. _PLAYLIST_ID_REGEXES = [
  202. r'content[iI]d=(\d+)',
  203. r"'itemId'\s*:\s*'([^']*)'",
  204. ]
  205. _PLAYLIST_CLIP_REGEXES = [
  206. r'(?s)data-qvt=.+?<a href="([^"]+)"',
  207. ]
  208. def _extract_clip(self, url, webpage):
  209. clip_id = self._html_search_regex(self._CLIPID_REGEXES, webpage, 'clip id')
  210. access_token = 'prosieben'
  211. client_name = 'kolibri-2.0.19-splec4'
  212. client_location = url
  213. videos_api_url = 'http://vas.sim-technik.de/vas/live/v2/videos?%s' % compat_urllib_parse.urlencode({
  214. 'access_token': access_token,
  215. 'client_location': client_location,
  216. 'client_name': client_name,
  217. 'ids': clip_id,
  218. })
  219. video = self._download_json(videos_api_url, clip_id, 'Downloading videos JSON')[0]
  220. if video.get('is_protected') is True:
  221. raise ExtractorError('This video is DRM protected.', expected=True)
  222. duration = float_or_none(video.get('duration'))
  223. source_ids = [source['id'] for source in video['sources']]
  224. source_ids_str = ','.join(map(str, source_ids))
  225. g = '01!8d8F_)r9]4s[qeuXfP%'
  226. client_id = g[:2] + sha1(''.join([clip_id, g, access_token, client_location, g, client_name])
  227. .encode('utf-8')).hexdigest()
  228. sources_api_url = 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources?%s' % (clip_id, compat_urllib_parse.urlencode({
  229. 'access_token': access_token,
  230. 'client_id': client_id,
  231. 'client_location': client_location,
  232. 'client_name': client_name,
  233. }))
  234. sources = self._download_json(sources_api_url, clip_id, 'Downloading sources JSON')
  235. server_id = sources['server_id']
  236. client_id = g[:2] + sha1(''.join([g, clip_id, access_token, server_id,
  237. client_location, source_ids_str, g, client_name])
  238. .encode('utf-8')).hexdigest()
  239. url_api_url = 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources/url?%s' % (clip_id, compat_urllib_parse.urlencode({
  240. 'access_token': access_token,
  241. 'client_id': client_id,
  242. 'client_location': client_location,
  243. 'client_name': client_name,
  244. 'server_id': server_id,
  245. 'source_ids': source_ids_str,
  246. }))
  247. urls = self._download_json(url_api_url, clip_id, 'Downloading urls JSON')
  248. title = self._html_search_regex(self._TITLE_REGEXES, webpage, 'title')
  249. description = self._html_search_regex(self._DESCRIPTION_REGEXES, webpage, 'description', fatal=False)
  250. thumbnail = self._og_search_thumbnail(webpage)
  251. upload_date = unified_strdate(self._html_search_regex(
  252. self._UPLOAD_DATE_REGEXES, webpage, 'upload date', default=None))
  253. formats = []
  254. urls_sources = urls['sources']
  255. if isinstance(urls_sources, dict):
  256. urls_sources = urls_sources.values()
  257. def fix_bitrate(bitrate):
  258. bitrate = int_or_none(bitrate)
  259. if not bitrate:
  260. return None
  261. return (bitrate // 1000) if bitrate % 1000 == 0 else bitrate
  262. for source in urls_sources:
  263. protocol = source['protocol']
  264. source_url = source['url']
  265. if protocol == 'rtmp' or protocol == 'rtmpe':
  266. mobj = re.search(r'^(?P<url>rtmpe?://[^/]+)/(?P<path>.+)$', source_url)
  267. if not mobj:
  268. continue
  269. path = mobj.group('path')
  270. mp4colon_index = path.rfind('mp4:')
  271. app = path[:mp4colon_index]
  272. play_path = path[mp4colon_index:]
  273. formats.append({
  274. 'url': '%s/%s' % (mobj.group('url'), app),
  275. 'app': app,
  276. 'play_path': play_path,
  277. 'player_url': 'http://livepassdl.conviva.com/hf/ver/2.79.0.17083/LivePassModuleMain.swf',
  278. 'page_url': 'http://www.prosieben.de',
  279. 'vbr': fix_bitrate(source['bitrate']),
  280. 'ext': 'mp4',
  281. 'format_id': '%s_%s' % (source['cdn'], source['bitrate']),
  282. })
  283. elif 'f4mgenerator' in source_url or determine_ext(source_url) == 'f4m':
  284. formats.extend(self._extract_f4m_formats(source_url, clip_id))
  285. else:
  286. formats.append({
  287. 'url': source_url,
  288. 'vbr': fix_bitrate(source['bitrate']),
  289. })
  290. self._sort_formats(formats)
  291. return {
  292. 'id': clip_id,
  293. 'title': title,
  294. 'description': description,
  295. 'thumbnail': thumbnail,
  296. 'upload_date': upload_date,
  297. 'duration': duration,
  298. 'formats': formats,
  299. }
  300. def _extract_playlist(self, url, webpage):
  301. playlist_id = self._html_search_regex(
  302. self._PLAYLIST_ID_REGEXES, webpage, 'playlist id')
  303. for regex in self._PLAYLIST_CLIP_REGEXES:
  304. playlist_clips = re.findall(regex, webpage)
  305. if playlist_clips:
  306. title = self._html_search_regex(
  307. self._TITLE_REGEXES, webpage, 'title')
  308. description = self._html_search_regex(
  309. self._DESCRIPTION_REGEXES, webpage, 'description', fatal=False)
  310. entries = [
  311. self.url_result(
  312. re.match('(.+?//.+?)/', url).group(1) + clip_path,
  313. 'ProSiebenSat1')
  314. for clip_path in playlist_clips]
  315. return self.playlist_result(entries, playlist_id, title, description)
  316. def _real_extract(self, url):
  317. video_id = self._match_id(url)
  318. webpage = self._download_webpage(url, video_id)
  319. page_type = self._search_regex(
  320. self._PAGE_TYPE_REGEXES, webpage,
  321. 'page type', default='clip').lower()
  322. if page_type == 'clip':
  323. return self._extract_clip(url, webpage)
  324. elif page_type == 'playlist':
  325. return self._extract_playlist(url, webpage)