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.

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