logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

prosiebensat1.py (21578B)


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