prosiebensat1.py 21 KB

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