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.

370 lines
14 KiB

10 years ago
  1. # encoding: 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 (
  7. compat_urllib_parse,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. determine_ext,
  12. float_or_none,
  13. int_or_none,
  14. unified_strdate,
  15. )
  16. class ProSiebenSat1IE(InfoExtractor):
  17. IE_NAME = 'prosiebensat1'
  18. IE_DESC = 'ProSiebenSat.1 Digital'
  19. _VALID_URL = r'https?://(?:www\.)?(?:(?:prosieben|prosiebenmaxx|sixx|sat1|kabeleins|the-voice-of-germany|7tv)\.(?:de|at|ch)|ran\.de|fem\.com)/(?P<id>.+)'
  20. _TESTS = [
  21. {
  22. # Tests changes introduced in https://github.com/rg3/youtube-dl/pull/6242
  23. # in response to fixing https://github.com/rg3/youtube-dl/issues/6215:
  24. # - malformed f4m manifest support
  25. # - proper handling of URLs starting with `https?://` in 2.0 manifests
  26. # - recursive child f4m manifests extraction
  27. 'url': 'http://www.prosieben.de/tv/circus-halligalli/videos/218-staffel-2-episode-18-jahresrueckblick-ganze-folge',
  28. 'info_dict': {
  29. 'id': '2104602',
  30. 'ext': 'flv',
  31. 'title': 'Episode 18 - Staffel 2',
  32. 'description': 'md5:8733c81b702ea472e069bc48bb658fc1',
  33. 'upload_date': '20131231',
  34. 'duration': 5845.04,
  35. },
  36. 'params': {
  37. # rtmp download
  38. 'skip_download': True,
  39. },
  40. },
  41. {
  42. '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',
  43. 'info_dict': {
  44. 'id': '2570327',
  45. 'ext': 'mp4',
  46. 'title': 'Lady-Umstyling für Audrina',
  47. 'description': 'md5:4c16d0c17a3461a0d43ea4084e96319d',
  48. 'upload_date': '20131014',
  49. 'duration': 606.76,
  50. },
  51. 'params': {
  52. # rtmp download
  53. 'skip_download': True,
  54. },
  55. 'skip': 'Seems to be broken',
  56. },
  57. {
  58. 'url': 'http://www.prosiebenmaxx.de/tv/experience/video/144-countdown-fuer-die-autowerkstatt-ganze-folge',
  59. 'info_dict': {
  60. 'id': '2429369',
  61. 'ext': 'mp4',
  62. 'title': 'Countdown für die Autowerkstatt',
  63. 'description': 'md5:809fc051a457b5d8666013bc40698817',
  64. 'upload_date': '20140223',
  65. 'duration': 2595.04,
  66. },
  67. 'params': {
  68. # rtmp download
  69. 'skip_download': True,
  70. },
  71. },
  72. {
  73. 'url': 'http://www.sixx.de/stars-style/video/sexy-laufen-in-ugg-boots-clip',
  74. 'info_dict': {
  75. 'id': '2904997',
  76. 'ext': 'mp4',
  77. 'title': 'Sexy laufen in Ugg Boots',
  78. 'description': 'md5:edf42b8bd5bc4e5da4db4222c5acb7d6',
  79. 'upload_date': '20140122',
  80. 'duration': 245.32,
  81. },
  82. 'params': {
  83. # rtmp download
  84. 'skip_download': True,
  85. },
  86. },
  87. {
  88. 'url': 'http://www.sat1.de/film/der-ruecktritt/video/im-interview-kai-wiesinger-clip',
  89. 'info_dict': {
  90. 'id': '2906572',
  91. 'ext': 'mp4',
  92. 'title': 'Im Interview: Kai Wiesinger',
  93. 'description': 'md5:e4e5370652ec63b95023e914190b4eb9',
  94. 'upload_date': '20140203',
  95. 'duration': 522.56,
  96. },
  97. 'params': {
  98. # rtmp download
  99. 'skip_download': True,
  100. },
  101. },
  102. {
  103. 'url': 'http://www.kabeleins.de/tv/rosins-restaurants/videos/jagd-auf-fertigkost-im-elsthal-teil-2-ganze-folge',
  104. 'info_dict': {
  105. 'id': '2992323',
  106. 'ext': 'mp4',
  107. 'title': 'Jagd auf Fertigkost im Elsthal - Teil 2',
  108. 'description': 'md5:2669cde3febe9bce13904f701e774eb6',
  109. 'upload_date': '20141014',
  110. 'duration': 2410.44,
  111. },
  112. 'params': {
  113. # rtmp download
  114. 'skip_download': True,
  115. },
  116. },
  117. {
  118. 'url': 'http://www.ran.de/fussball/bundesliga/video/schalke-toennies-moechte-raul-zurueck-ganze-folge',
  119. 'info_dict': {
  120. 'id': '3004256',
  121. 'ext': 'mp4',
  122. 'title': 'Schalke: Tönnies möchte Raul zurück',
  123. 'description': 'md5:4b5b271d9bcde223b54390754c8ece3f',
  124. 'upload_date': '20140226',
  125. 'duration': 228.96,
  126. },
  127. 'params': {
  128. # rtmp download
  129. 'skip_download': True,
  130. },
  131. },
  132. {
  133. 'url': 'http://www.the-voice-of-germany.de/video/31-andreas-kuemmert-rocket-man-clip',
  134. 'info_dict': {
  135. 'id': '2572814',
  136. 'ext': 'flv',
  137. 'title': 'Andreas Kümmert: Rocket Man',
  138. 'description': 'md5:6ddb02b0781c6adf778afea606652e38',
  139. 'upload_date': '20131017',
  140. 'duration': 469.88,
  141. },
  142. 'params': {
  143. 'skip_download': True,
  144. },
  145. },
  146. {
  147. 'url': 'http://www.fem.com/wellness/videos/wellness-video-clip-kurztripps-zum-valentinstag.html',
  148. 'info_dict': {
  149. 'id': '2156342',
  150. 'ext': 'flv',
  151. 'title': 'Kurztrips zum Valentinstag',
  152. 'description': 'Romantischer Kurztrip zum Valentinstag? Nina Heinemann verrät, was sich hier wirklich lohnt.',
  153. 'duration': 307.24,
  154. },
  155. 'params': {
  156. 'skip_download': True,
  157. },
  158. },
  159. {
  160. 'url': 'http://www.prosieben.de/tv/joko-gegen-klaas/videos/playlists/episode-8-ganze-folge-playlist',
  161. 'info_dict': {
  162. 'id': '439664',
  163. 'title': 'Episode 8 - Ganze Folge - Playlist',
  164. 'description': 'md5:63b8963e71f481782aeea877658dec84',
  165. },
  166. 'playlist_count': 2,
  167. },
  168. {
  169. 'url': 'http://www.7tv.de/circus-halligalli/615-best-of-circus-halligalli-ganze-folge',
  170. 'info_dict': {
  171. 'id': '4187506',
  172. 'ext': 'flv',
  173. 'title': 'Best of Circus HalliGalli',
  174. 'description': 'md5:8849752efd90b9772c9db6fdf87fb9e9',
  175. 'upload_date': '20151229',
  176. },
  177. 'params': {
  178. 'skip_download': True,
  179. },
  180. },
  181. ]
  182. _CLIPID_REGEXES = [
  183. r'"clip_id"\s*:\s+"(\d+)"',
  184. r'clipid: "(\d+)"',
  185. r'clip[iI]d=(\d+)',
  186. r'clip[iI]d\s*=\s*["\'](\d+)',
  187. r"'itemImageUrl'\s*:\s*'/dynamic/thumbnails/full/\d+/(\d+)",
  188. ]
  189. _TITLE_REGEXES = [
  190. r'<h2 class="subtitle" itemprop="name">\s*(.+?)</h2>',
  191. r'<header class="clearfix">\s*<h3>(.+?)</h3>',
  192. r'<!-- start video -->\s*<h1>(.+?)</h1>',
  193. r'<h1 class="att-name">\s*(.+?)</h1>',
  194. r'<header class="module_header">\s*<h2>([^<]+)</h2>\s*</header>',
  195. r'<h2 class="video-title" itemprop="name">\s*(.+?)</h2>',
  196. r'<div[^>]+id="veeseoTitle"[^>]*>(.+?)</div>',
  197. ]
  198. _DESCRIPTION_REGEXES = [
  199. r'<p itemprop="description">\s*(.+?)</p>',
  200. r'<div class="videoDecription">\s*<p><strong>Beschreibung</strong>: (.+?)</p>',
  201. r'<div class="g-plusone" data-size="medium"></div>\s*</div>\s*</header>\s*(.+?)\s*<footer>',
  202. r'<p class="att-description">\s*(.+?)\s*</p>',
  203. r'<p class="video-description" itemprop="description">\s*(.+?)</p>',
  204. r'<div[^>]+id="veeseoDescription"[^>]*>(.+?)</div>',
  205. ]
  206. _UPLOAD_DATE_REGEXES = [
  207. r'<meta property="og:published_time" content="(.+?)">',
  208. r'<span>\s*(\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}) \|\s*<span itemprop="duration"',
  209. r'<footer>\s*(\d{2}\.\d{2}\.\d{4}) \d{2}:\d{2} Uhr',
  210. r'<span style="padding-left: 4px;line-height:20px; color:#404040">(\d{2}\.\d{2}\.\d{4})</span>',
  211. r'(\d{2}\.\d{2}\.\d{4}) \| \d{2}:\d{2} Min<br/>',
  212. ]
  213. _PAGE_TYPE_REGEXES = [
  214. r'<meta name="page_type" content="([^"]+)">',
  215. r"'itemType'\s*:\s*'([^']*)'",
  216. ]
  217. _PLAYLIST_ID_REGEXES = [
  218. r'content[iI]d=(\d+)',
  219. r"'itemId'\s*:\s*'([^']*)'",
  220. ]
  221. _PLAYLIST_CLIP_REGEXES = [
  222. r'(?s)data-qvt=.+?<a href="([^"]+)"',
  223. ]
  224. def _extract_clip(self, url, webpage):
  225. clip_id = self._html_search_regex(self._CLIPID_REGEXES, webpage, 'clip id')
  226. access_token = 'prosieben'
  227. client_name = 'kolibri-2.0.19-splec4'
  228. client_location = url
  229. videos_api_url = 'http://vas.sim-technik.de/vas/live/v2/videos?%s' % compat_urllib_parse.urlencode({
  230. 'access_token': access_token,
  231. 'client_location': client_location,
  232. 'client_name': client_name,
  233. 'ids': clip_id,
  234. })
  235. video = self._download_json(videos_api_url, clip_id, 'Downloading videos JSON')[0]
  236. if video.get('is_protected') is True:
  237. raise ExtractorError('This video is DRM protected.', expected=True)
  238. duration = float_or_none(video.get('duration'))
  239. source_ids = [source['id'] for source in video['sources']]
  240. source_ids_str = ','.join(map(str, source_ids))
  241. g = '01!8d8F_)r9]4s[qeuXfP%'
  242. client_id = g[:2] + sha1(''.join([clip_id, g, access_token, client_location, g, client_name])
  243. .encode('utf-8')).hexdigest()
  244. sources_api_url = 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources?%s' % (clip_id, compat_urllib_parse.urlencode({
  245. 'access_token': access_token,
  246. 'client_id': client_id,
  247. 'client_location': client_location,
  248. 'client_name': client_name,
  249. }))
  250. sources = self._download_json(sources_api_url, clip_id, 'Downloading sources JSON')
  251. server_id = sources['server_id']
  252. client_id = g[:2] + sha1(''.join([g, clip_id, access_token, server_id,
  253. client_location, source_ids_str, g, client_name])
  254. .encode('utf-8')).hexdigest()
  255. url_api_url = 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources/url?%s' % (clip_id, compat_urllib_parse.urlencode({
  256. 'access_token': access_token,
  257. 'client_id': client_id,
  258. 'client_location': client_location,
  259. 'client_name': client_name,
  260. 'server_id': server_id,
  261. 'source_ids': source_ids_str,
  262. }))
  263. urls = self._download_json(url_api_url, clip_id, 'Downloading urls JSON')
  264. title = self._html_search_regex(self._TITLE_REGEXES, webpage, 'title')
  265. description = self._html_search_regex(self._DESCRIPTION_REGEXES, webpage, 'description', fatal=False)
  266. thumbnail = self._og_search_thumbnail(webpage)
  267. upload_date = unified_strdate(self._html_search_regex(
  268. self._UPLOAD_DATE_REGEXES, webpage, 'upload date', default=None))
  269. formats = []
  270. urls_sources = urls['sources']
  271. if isinstance(urls_sources, dict):
  272. urls_sources = urls_sources.values()
  273. def fix_bitrate(bitrate):
  274. bitrate = int_or_none(bitrate)
  275. if not bitrate:
  276. return None
  277. return (bitrate // 1000) if bitrate % 1000 == 0 else bitrate
  278. for source in urls_sources:
  279. protocol = source['protocol']
  280. source_url = source['url']
  281. if protocol == 'rtmp' or protocol == 'rtmpe':
  282. mobj = re.search(r'^(?P<url>rtmpe?://[^/]+)/(?P<path>.+)$', source_url)
  283. if not mobj:
  284. continue
  285. path = mobj.group('path')
  286. mp4colon_index = path.rfind('mp4:')
  287. app = path[:mp4colon_index]
  288. play_path = path[mp4colon_index:]
  289. formats.append({
  290. 'url': '%s/%s' % (mobj.group('url'), app),
  291. 'app': app,
  292. 'play_path': play_path,
  293. 'player_url': 'http://livepassdl.conviva.com/hf/ver/2.79.0.17083/LivePassModuleMain.swf',
  294. 'page_url': 'http://www.prosieben.de',
  295. 'vbr': fix_bitrate(source['bitrate']),
  296. 'ext': 'mp4',
  297. 'format_id': '%s_%s' % (source['cdn'], source['bitrate']),
  298. })
  299. elif 'f4mgenerator' in source_url or determine_ext(source_url) == 'f4m':
  300. formats.extend(self._extract_f4m_formats(source_url, clip_id))
  301. else:
  302. formats.append({
  303. 'url': source_url,
  304. 'vbr': fix_bitrate(source['bitrate']),
  305. })
  306. self._sort_formats(formats)
  307. return {
  308. 'id': clip_id,
  309. 'title': title,
  310. 'description': description,
  311. 'thumbnail': thumbnail,
  312. 'upload_date': upload_date,
  313. 'duration': duration,
  314. 'formats': formats,
  315. }
  316. def _extract_playlist(self, url, webpage):
  317. playlist_id = self._html_search_regex(
  318. self._PLAYLIST_ID_REGEXES, webpage, 'playlist id')
  319. for regex in self._PLAYLIST_CLIP_REGEXES:
  320. playlist_clips = re.findall(regex, webpage)
  321. if playlist_clips:
  322. title = self._html_search_regex(
  323. self._TITLE_REGEXES, webpage, 'title')
  324. description = self._html_search_regex(
  325. self._DESCRIPTION_REGEXES, webpage, 'description', fatal=False)
  326. entries = [
  327. self.url_result(
  328. re.match('(.+?//.+?)/', url).group(1) + clip_path,
  329. 'ProSiebenSat1')
  330. for clip_path in playlist_clips]
  331. return self.playlist_result(entries, playlist_id, title, description)
  332. def _real_extract(self, url):
  333. video_id = self._match_id(url)
  334. webpage = self._download_webpage(url, video_id)
  335. page_type = self._search_regex(
  336. self._PAGE_TYPE_REGEXES, webpage,
  337. 'page type', default='clip').lower()
  338. if page_type == 'clip':
  339. return self._extract_clip(url, webpage)
  340. elif page_type == 'playlist':
  341. return self._extract_playlist(url, webpage)