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.

500 lines
21 KiB

  1. # coding: 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. _GEO_COUNTRIES = ['DE']
  16. _ACCESS_ID = None
  17. _SUPPORTED_PROTOCOLS = 'dash:clear,hls:clear,progressive:clear'
  18. _V4_BASE_URL = 'https://vas-v4.p7s1video.net/4.0/get'
  19. def _extract_video_info(self, url, clip_id):
  20. client_location = url
  21. video = self._download_json(
  22. 'http://vas.sim-technik.de/vas/live/v2/videos',
  23. clip_id, 'Downloading videos JSON', query={
  24. 'access_token': self._TOKEN,
  25. 'client_location': client_location,
  26. 'client_name': self._CLIENT_NAME,
  27. 'ids': clip_id,
  28. })[0]
  29. if video.get('is_protected') is True:
  30. raise ExtractorError('This video is DRM protected.', expected=True)
  31. formats = []
  32. if self._ACCESS_ID:
  33. raw_ct = self._ENCRYPTION_KEY + clip_id + self._IV + self._ACCESS_ID
  34. server_token = (self._download_json(
  35. self._V4_BASE_URL + 'protocols', clip_id,
  36. 'Downloading protocols JSON',
  37. headers=self.geo_verification_headers(), query={
  38. 'access_id': self._ACCESS_ID,
  39. 'client_token': sha1((raw_ct).encode()).hexdigest(),
  40. 'video_id': clip_id,
  41. }, fatal=False) or {}).get('server_token')
  42. if server_token:
  43. urls = (self._download_json(
  44. self._V4_BASE_URL + 'urls', clip_id, 'Downloading urls JSON', query={
  45. 'access_id': self._ACCESS_ID,
  46. 'client_token': sha1((raw_ct + server_token + self._SUPPORTED_PROTOCOLS).encode()).hexdigest(),
  47. 'protocols': self._SUPPORTED_PROTOCOLS,
  48. 'server_token': server_token,
  49. 'video_id': clip_id,
  50. }, fatal=False) or {}).get('urls') or {}
  51. for protocol, variant in urls.items():
  52. source_url = variant.get('clear', {}).get('url')
  53. if not source_url:
  54. continue
  55. if protocol == 'dash':
  56. formats.extend(self._extract_mpd_formats(
  57. source_url, clip_id, mpd_id=protocol, fatal=False))
  58. elif protocol == 'hls':
  59. formats.extend(self._extract_m3u8_formats(
  60. source_url, clip_id, 'mp4', 'm3u8_native',
  61. m3u8_id=protocol, fatal=False))
  62. else:
  63. formats.append({
  64. 'url': source_url,
  65. 'format_id': protocol,
  66. })
  67. if not formats:
  68. source_ids = [compat_str(source['id']) for source in video['sources']]
  69. client_id = self._SALT[:2] + sha1(''.join([clip_id, self._SALT, self._TOKEN, client_location, self._SALT, self._CLIENT_NAME]).encode('utf-8')).hexdigest()
  70. sources = self._download_json(
  71. 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources' % clip_id,
  72. clip_id, 'Downloading sources JSON', query={
  73. 'access_token': self._TOKEN,
  74. 'client_id': client_id,
  75. 'client_location': client_location,
  76. 'client_name': self._CLIENT_NAME,
  77. })
  78. server_id = sources['server_id']
  79. def fix_bitrate(bitrate):
  80. bitrate = int_or_none(bitrate)
  81. if not bitrate:
  82. return None
  83. return (bitrate // 1000) if bitrate % 1000 == 0 else bitrate
  84. for source_id in source_ids:
  85. 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()
  86. urls = self._download_json(
  87. 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources/url' % clip_id,
  88. clip_id, 'Downloading urls JSON', fatal=False, query={
  89. 'access_token': self._TOKEN,
  90. 'client_id': client_id,
  91. 'client_location': client_location,
  92. 'client_name': self._CLIENT_NAME,
  93. 'server_id': server_id,
  94. 'source_ids': source_id,
  95. })
  96. if not urls:
  97. continue
  98. if urls.get('status_code') != 0:
  99. raise ExtractorError('This video is unavailable', expected=True)
  100. urls_sources = urls['sources']
  101. if isinstance(urls_sources, dict):
  102. urls_sources = urls_sources.values()
  103. for source in urls_sources:
  104. source_url = source.get('url')
  105. if not source_url:
  106. continue
  107. protocol = source.get('protocol')
  108. mimetype = source.get('mimetype')
  109. if mimetype == 'application/f4m+xml' or 'f4mgenerator' in source_url or determine_ext(source_url) == 'f4m':
  110. formats.extend(self._extract_f4m_formats(
  111. source_url, clip_id, f4m_id='hds', fatal=False))
  112. elif mimetype == 'application/x-mpegURL':
  113. formats.extend(self._extract_m3u8_formats(
  114. source_url, clip_id, 'mp4', 'm3u8_native',
  115. m3u8_id='hls', fatal=False))
  116. elif mimetype == 'application/dash+xml':
  117. formats.extend(self._extract_mpd_formats(
  118. source_url, clip_id, mpd_id='dash', fatal=False))
  119. else:
  120. tbr = fix_bitrate(source['bitrate'])
  121. if protocol in ('rtmp', 'rtmpe'):
  122. mobj = re.search(r'^(?P<url>rtmpe?://[^/]+)/(?P<path>.+)$', source_url)
  123. if not mobj:
  124. continue
  125. path = mobj.group('path')
  126. mp4colon_index = path.rfind('mp4:')
  127. app = path[:mp4colon_index]
  128. play_path = path[mp4colon_index:]
  129. formats.append({
  130. 'url': '%s/%s' % (mobj.group('url'), app),
  131. 'app': app,
  132. 'play_path': play_path,
  133. 'player_url': 'http://livepassdl.conviva.com/hf/ver/2.79.0.17083/LivePassModuleMain.swf',
  134. 'page_url': 'http://www.prosieben.de',
  135. 'tbr': tbr,
  136. 'ext': 'flv',
  137. 'format_id': 'rtmp%s' % ('-%d' % tbr if tbr else ''),
  138. })
  139. else:
  140. formats.append({
  141. 'url': source_url,
  142. 'tbr': tbr,
  143. 'format_id': 'http%s' % ('-%d' % tbr if tbr else ''),
  144. })
  145. self._sort_formats(formats)
  146. return {
  147. 'duration': float_or_none(video.get('duration')),
  148. 'formats': formats,
  149. }
  150. class ProSiebenSat1IE(ProSiebenSat1BaseIE):
  151. IE_NAME = 'prosiebensat1'
  152. IE_DESC = 'ProSiebenSat.1 Digital'
  153. _VALID_URL = r'''(?x)
  154. https?://
  155. (?:www\.)?
  156. (?:
  157. (?:beta\.)?
  158. (?:
  159. prosieben(?:maxx)?|sixx|sat1(?:gold)?|kabeleins(?:doku)?|the-voice-of-germany|7tv|advopedia
  160. )\.(?:de|at|ch)|
  161. ran\.de|fem\.com|advopedia\.de|galileo\.tv/video
  162. )
  163. /(?P<id>.+)
  164. '''
  165. _TESTS = [
  166. {
  167. # Tests changes introduced in https://github.com/ytdl-org/youtube-dl/pull/6242
  168. # in response to fixing https://github.com/ytdl-org/youtube-dl/issues/6215:
  169. # - malformed f4m manifest support
  170. # - proper handling of URLs starting with `https?://` in 2.0 manifests
  171. # - recursive child f4m manifests extraction
  172. 'url': 'http://www.prosieben.de/tv/circus-halligalli/videos/218-staffel-2-episode-18-jahresrueckblick-ganze-folge',
  173. 'info_dict': {
  174. 'id': '2104602',
  175. 'ext': 'mp4',
  176. 'title': 'Episode 18 - Staffel 2',
  177. 'description': 'md5:8733c81b702ea472e069bc48bb658fc1',
  178. 'upload_date': '20131231',
  179. 'duration': 5845.04,
  180. },
  181. },
  182. {
  183. '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',
  184. 'info_dict': {
  185. 'id': '2570327',
  186. 'ext': 'mp4',
  187. 'title': 'Lady-Umstyling für Audrina',
  188. 'description': 'md5:4c16d0c17a3461a0d43ea4084e96319d',
  189. 'upload_date': '20131014',
  190. 'duration': 606.76,
  191. },
  192. 'params': {
  193. # rtmp download
  194. 'skip_download': True,
  195. },
  196. 'skip': 'Seems to be broken',
  197. },
  198. {
  199. 'url': 'http://www.prosiebenmaxx.de/tv/experience/video/144-countdown-fuer-die-autowerkstatt-ganze-folge',
  200. 'info_dict': {
  201. 'id': '2429369',
  202. 'ext': 'mp4',
  203. 'title': 'Countdown für die Autowerkstatt',
  204. 'description': 'md5:809fc051a457b5d8666013bc40698817',
  205. 'upload_date': '20140223',
  206. 'duration': 2595.04,
  207. },
  208. 'params': {
  209. # rtmp download
  210. 'skip_download': True,
  211. },
  212. 'skip': 'This video is unavailable',
  213. },
  214. {
  215. 'url': 'http://www.sixx.de/stars-style/video/sexy-laufen-in-ugg-boots-clip',
  216. 'info_dict': {
  217. 'id': '2904997',
  218. 'ext': 'mp4',
  219. 'title': 'Sexy laufen in Ugg Boots',
  220. 'description': 'md5:edf42b8bd5bc4e5da4db4222c5acb7d6',
  221. 'upload_date': '20140122',
  222. 'duration': 245.32,
  223. },
  224. 'params': {
  225. # rtmp download
  226. 'skip_download': True,
  227. },
  228. 'skip': 'This video is unavailable',
  229. },
  230. {
  231. 'url': 'http://www.sat1.de/film/der-ruecktritt/video/im-interview-kai-wiesinger-clip',
  232. 'info_dict': {
  233. 'id': '2906572',
  234. 'ext': 'mp4',
  235. 'title': 'Im Interview: Kai Wiesinger',
  236. 'description': 'md5:e4e5370652ec63b95023e914190b4eb9',
  237. 'upload_date': '20140203',
  238. 'duration': 522.56,
  239. },
  240. 'params': {
  241. # rtmp download
  242. 'skip_download': True,
  243. },
  244. 'skip': 'This video is unavailable',
  245. },
  246. {
  247. 'url': 'http://www.kabeleins.de/tv/rosins-restaurants/videos/jagd-auf-fertigkost-im-elsthal-teil-2-ganze-folge',
  248. 'info_dict': {
  249. 'id': '2992323',
  250. 'ext': 'mp4',
  251. 'title': 'Jagd auf Fertigkost im Elsthal - Teil 2',
  252. 'description': 'md5:2669cde3febe9bce13904f701e774eb6',
  253. 'upload_date': '20141014',
  254. 'duration': 2410.44,
  255. },
  256. 'params': {
  257. # rtmp download
  258. 'skip_download': True,
  259. },
  260. 'skip': 'This video is unavailable',
  261. },
  262. {
  263. 'url': 'http://www.ran.de/fussball/bundesliga/video/schalke-toennies-moechte-raul-zurueck-ganze-folge',
  264. 'info_dict': {
  265. 'id': '3004256',
  266. 'ext': 'mp4',
  267. 'title': 'Schalke: Tönnies möchte Raul zurück',
  268. 'description': 'md5:4b5b271d9bcde223b54390754c8ece3f',
  269. 'upload_date': '20140226',
  270. 'duration': 228.96,
  271. },
  272. 'params': {
  273. # rtmp download
  274. 'skip_download': True,
  275. },
  276. 'skip': 'This video is unavailable',
  277. },
  278. {
  279. 'url': 'http://www.the-voice-of-germany.de/video/31-andreas-kuemmert-rocket-man-clip',
  280. 'info_dict': {
  281. 'id': '2572814',
  282. 'ext': 'mp4',
  283. 'title': 'Andreas Kümmert: Rocket Man',
  284. 'description': 'md5:6ddb02b0781c6adf778afea606652e38',
  285. 'upload_date': '20131017',
  286. 'duration': 469.88,
  287. },
  288. 'params': {
  289. 'skip_download': True,
  290. },
  291. },
  292. {
  293. 'url': 'http://www.fem.com/wellness/videos/wellness-video-clip-kurztripps-zum-valentinstag.html',
  294. 'info_dict': {
  295. 'id': '2156342',
  296. 'ext': 'mp4',
  297. 'title': 'Kurztrips zum Valentinstag',
  298. 'description': 'Romantischer Kurztrip zum Valentinstag? Nina Heinemann verrät, was sich hier wirklich lohnt.',
  299. 'duration': 307.24,
  300. },
  301. 'params': {
  302. 'skip_download': True,
  303. },
  304. },
  305. {
  306. 'url': 'http://www.prosieben.de/tv/joko-gegen-klaas/videos/playlists/episode-8-ganze-folge-playlist',
  307. 'info_dict': {
  308. 'id': '439664',
  309. 'title': 'Episode 8 - Ganze Folge - Playlist',
  310. 'description': 'md5:63b8963e71f481782aeea877658dec84',
  311. },
  312. 'playlist_count': 2,
  313. 'skip': 'This video is unavailable',
  314. },
  315. {
  316. 'url': 'http://www.7tv.de/circus-halligalli/615-best-of-circus-halligalli-ganze-folge',
  317. 'info_dict': {
  318. 'id': '4187506',
  319. 'ext': 'mp4',
  320. 'title': 'Best of Circus HalliGalli',
  321. 'description': 'md5:8849752efd90b9772c9db6fdf87fb9e9',
  322. 'upload_date': '20151229',
  323. },
  324. 'params': {
  325. 'skip_download': True,
  326. },
  327. },
  328. {
  329. # title in <h2 class="subtitle">
  330. 'url': 'http://www.prosieben.de/stars/oscar-award/videos/jetzt-erst-enthuellt-das-geheimnis-von-emma-stones-oscar-robe-clip',
  331. 'info_dict': {
  332. 'id': '4895826',
  333. 'ext': 'mp4',
  334. 'title': 'Jetzt erst enthüllt: Das Geheimnis von Emma Stones Oscar-Robe',
  335. 'description': 'md5:e5ace2bc43fadf7b63adc6187e9450b9',
  336. 'upload_date': '20170302',
  337. },
  338. 'params': {
  339. 'skip_download': True,
  340. },
  341. 'skip': 'geo restricted to Germany',
  342. },
  343. {
  344. # geo restricted to Germany
  345. 'url': 'http://www.kabeleinsdoku.de/tv/mayday-alarm-im-cockpit/video/102-notlandung-im-hudson-river-ganze-folge',
  346. 'only_matching': True,
  347. },
  348. {
  349. # geo restricted to Germany
  350. 'url': 'http://www.sat1gold.de/tv/edel-starck/video/11-staffel-1-episode-1-partner-wider-willen-ganze-folge',
  351. 'only_matching': True,
  352. },
  353. {
  354. # geo restricted to Germany
  355. 'url': 'https://www.galileo.tv/video/diese-emojis-werden-oft-missverstanden',
  356. 'only_matching': True,
  357. },
  358. {
  359. 'url': 'http://www.sat1gold.de/tv/edel-starck/playlist/die-gesamte-1-staffel',
  360. 'only_matching': True,
  361. },
  362. {
  363. 'url': 'http://www.advopedia.de/videos/lenssen-klaert-auf/lenssen-klaert-auf-folge-8-staffel-3-feiertage-und-freie-tage',
  364. 'only_matching': True,
  365. },
  366. ]
  367. _TOKEN = 'prosieben'
  368. _SALT = '01!8d8F_)r9]4s[qeuXfP%'
  369. _CLIENT_NAME = 'kolibri-2.0.19-splec4'
  370. _ACCESS_ID = 'x_prosiebenmaxx-de'
  371. _ENCRYPTION_KEY = 'Eeyeey9oquahthainoofashoyoikosag'
  372. _IV = 'Aeluchoc6aevechuipiexeeboowedaok'
  373. _CLIPID_REGEXES = [
  374. r'"clip_id"\s*:\s+"(\d+)"',
  375. r'clipid: "(\d+)"',
  376. r'clip[iI]d=(\d+)',
  377. r'clip[iI][dD]\s*=\s*["\'](\d+)',
  378. r"'itemImageUrl'\s*:\s*'/dynamic/thumbnails/full/\d+/(\d+)",
  379. r'proMamsId&quot;\s*:\s*&quot;(\d+)',
  380. r'proMamsId"\s*:\s*"(\d+)',
  381. ]
  382. _TITLE_REGEXES = [
  383. r'<h2 class="subtitle" itemprop="name">\s*(.+?)</h2>',
  384. r'<header class="clearfix">\s*<h3>(.+?)</h3>',
  385. r'<!-- start video -->\s*<h1>(.+?)</h1>',
  386. r'<h1 class="att-name">\s*(.+?)</h1>',
  387. r'<header class="module_header">\s*<h2>([^<]+)</h2>\s*</header>',
  388. r'<h2 class="video-title" itemprop="name">\s*(.+?)</h2>',
  389. r'<div[^>]+id="veeseoTitle"[^>]*>(.+?)</div>',
  390. r'<h2[^>]+class="subtitle"[^>]*>([^<]+)</h2>',
  391. ]
  392. _DESCRIPTION_REGEXES = [
  393. r'<p itemprop="description">\s*(.+?)</p>',
  394. r'<div class="videoDecription">\s*<p><strong>Beschreibung</strong>: (.+?)</p>',
  395. r'<div class="g-plusone" data-size="medium"></div>\s*</div>\s*</header>\s*(.+?)\s*<footer>',
  396. r'<p class="att-description">\s*(.+?)\s*</p>',
  397. r'<p class="video-description" itemprop="description">\s*(.+?)</p>',
  398. r'<div[^>]+id="veeseoDescription"[^>]*>(.+?)</div>',
  399. ]
  400. _UPLOAD_DATE_REGEXES = [
  401. r'<meta property="og:published_time" content="(.+?)">',
  402. r'<span>\s*(\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}) \|\s*<span itemprop="duration"',
  403. r'<footer>\s*(\d{2}\.\d{2}\.\d{4}) \d{2}:\d{2} Uhr',
  404. r'<span style="padding-left: 4px;line-height:20px; color:#404040">(\d{2}\.\d{2}\.\d{4})</span>',
  405. r'(\d{2}\.\d{2}\.\d{4}) \| \d{2}:\d{2} Min<br/>',
  406. ]
  407. _PAGE_TYPE_REGEXES = [
  408. r'<meta name="page_type" content="([^"]+)">',
  409. r"'itemType'\s*:\s*'([^']*)'",
  410. ]
  411. _PLAYLIST_ID_REGEXES = [
  412. r'content[iI]d=(\d+)',
  413. r"'itemId'\s*:\s*'([^']*)'",
  414. ]
  415. _PLAYLIST_CLIP_REGEXES = [
  416. r'(?s)data-qvt=.+?<a href="([^"]+)"',
  417. ]
  418. def _extract_clip(self, url, webpage):
  419. clip_id = self._html_search_regex(
  420. self._CLIPID_REGEXES, webpage, 'clip id')
  421. title = self._html_search_regex(
  422. self._TITLE_REGEXES, webpage, 'title',
  423. default=None) or self._og_search_title(webpage)
  424. info = self._extract_video_info(url, clip_id)
  425. description = self._html_search_regex(
  426. self._DESCRIPTION_REGEXES, webpage, 'description', default=None)
  427. if description is None:
  428. description = self._og_search_description(webpage)
  429. thumbnail = self._og_search_thumbnail(webpage)
  430. upload_date = unified_strdate(self._html_search_regex(
  431. self._UPLOAD_DATE_REGEXES, webpage, 'upload date', default=None))
  432. info.update({
  433. 'id': clip_id,
  434. 'title': title,
  435. 'description': description,
  436. 'thumbnail': thumbnail,
  437. 'upload_date': upload_date,
  438. })
  439. return info
  440. def _extract_playlist(self, url, webpage):
  441. playlist_id = self._html_search_regex(
  442. self._PLAYLIST_ID_REGEXES, webpage, 'playlist id')
  443. playlist = self._parse_json(
  444. self._search_regex(
  445. r'var\s+contentResources\s*=\s*(\[.+?\]);\s*</script',
  446. webpage, 'playlist'),
  447. playlist_id)
  448. entries = []
  449. for item in playlist:
  450. clip_id = item.get('id') or item.get('upc')
  451. if not clip_id:
  452. continue
  453. info = self._extract_video_info(url, clip_id)
  454. info.update({
  455. 'id': clip_id,
  456. 'title': item.get('title') or item.get('teaser', {}).get('headline'),
  457. 'description': item.get('teaser', {}).get('description'),
  458. 'thumbnail': item.get('poster'),
  459. 'duration': float_or_none(item.get('duration')),
  460. 'series': item.get('tvShowTitle'),
  461. 'uploader': item.get('broadcastPublisher'),
  462. })
  463. entries.append(info)
  464. return self.playlist_result(entries, playlist_id)
  465. def _real_extract(self, url):
  466. video_id = self._match_id(url)
  467. webpage = self._download_webpage(url, video_id)
  468. page_type = self._search_regex(
  469. self._PAGE_TYPE_REGEXES, webpage,
  470. 'page type', default='clip').lower()
  471. if page_type == 'clip':
  472. return self._extract_clip(url, webpage)
  473. elif page_type == 'playlist':
  474. return self._extract_playlist(url, webpage)
  475. else:
  476. raise ExtractorError(
  477. 'Unsupported page type %s' % page_type, expected=True)