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.

392 lines
16 KiB

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