prosiebensat1.py 21 KB

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