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.

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