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.

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