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.

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