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.

335 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. ]
  175. _DESCRIPTION_REGEXES = [
  176. r'<p itemprop="description">\s*(.+?)</p>',
  177. r'<div class="videoDecription">\s*<p><strong>Beschreibung</strong>: (.+?)</p>',
  178. r'<div class="g-plusone" data-size="medium"></div>\s*</div>\s*</header>\s*(.+?)\s*<footer>',
  179. r'<p class="att-description">\s*(.+?)\s*</p>',
  180. ]
  181. _UPLOAD_DATE_REGEXES = [
  182. r'<meta property="og:published_time" content="(.+?)">',
  183. r'<span>\s*(\d{2}\.\d{2}\.\d{4} \d{2}:\d{2}) \|\s*<span itemprop="duration"',
  184. r'<footer>\s*(\d{2}\.\d{2}\.\d{4}) \d{2}:\d{2} Uhr',
  185. r'<span style="padding-left: 4px;line-height:20px; color:#404040">(\d{2}\.\d{2}\.\d{4})</span>',
  186. r'(\d{2}\.\d{2}\.\d{4}) \| \d{2}:\d{2} Min<br/>',
  187. ]
  188. _PAGE_TYPE_REGEXES = [
  189. r'<meta name="page_type" content="([^"]+)">',
  190. r"'itemType'\s*:\s*'([^']*)'",
  191. ]
  192. _PLAYLIST_ID_REGEXES = [
  193. r'content[iI]d=(\d+)',
  194. r"'itemId'\s*:\s*'([^']*)'",
  195. ]
  196. _PLAYLIST_CLIP_REGEXES = [
  197. r'(?s)data-qvt=.+?<a href="([^"]+)"',
  198. ]
  199. def _extract_clip(self, url, webpage):
  200. clip_id = self._html_search_regex(self._CLIPID_REGEXES, webpage, 'clip id')
  201. access_token = 'testclient'
  202. client_name = 'kolibri-1.2.5'
  203. client_location = url
  204. videos_api_url = 'http://vas.sim-technik.de/vas/live/v2/videos?%s' % compat_urllib_parse.urlencode({
  205. 'access_token': access_token,
  206. 'client_location': client_location,
  207. 'client_name': client_name,
  208. 'ids': clip_id,
  209. })
  210. videos = self._download_json(videos_api_url, clip_id, 'Downloading videos JSON')
  211. duration = float(videos[0]['duration'])
  212. source_ids = [source['id'] for source in videos[0]['sources']]
  213. source_ids_str = ','.join(map(str, source_ids))
  214. g = '01!8d8F_)r9]4s[qeuXfP%'
  215. client_id = g[:2] + sha1(''.join([clip_id, g, access_token, client_location, g, client_name])
  216. .encode('utf-8')).hexdigest()
  217. sources_api_url = 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources?%s' % (clip_id, compat_urllib_parse.urlencode({
  218. 'access_token': access_token,
  219. 'client_id': client_id,
  220. 'client_location': client_location,
  221. 'client_name': client_name,
  222. }))
  223. sources = self._download_json(sources_api_url, clip_id, 'Downloading sources JSON')
  224. server_id = sources['server_id']
  225. client_id = g[:2] + sha1(''.join([g, clip_id, access_token, server_id,
  226. client_location, source_ids_str, g, client_name])
  227. .encode('utf-8')).hexdigest()
  228. url_api_url = 'http://vas.sim-technik.de/vas/live/v2/videos/%s/sources/url?%s' % (clip_id, compat_urllib_parse.urlencode({
  229. 'access_token': access_token,
  230. 'client_id': client_id,
  231. 'client_location': client_location,
  232. 'client_name': client_name,
  233. 'server_id': server_id,
  234. 'source_ids': source_ids_str,
  235. }))
  236. urls = self._download_json(url_api_url, clip_id, 'Downloading urls JSON')
  237. title = self._html_search_regex(self._TITLE_REGEXES, webpage, 'title')
  238. description = self._html_search_regex(self._DESCRIPTION_REGEXES, webpage, 'description', fatal=False)
  239. thumbnail = self._og_search_thumbnail(webpage)
  240. upload_date = unified_strdate(self._html_search_regex(
  241. self._UPLOAD_DATE_REGEXES, webpage, 'upload date', default=None))
  242. formats = []
  243. urls_sources = urls['sources']
  244. if isinstance(urls_sources, dict):
  245. urls_sources = urls_sources.values()
  246. def fix_bitrate(bitrate):
  247. bitrate = int_or_none(bitrate)
  248. if not bitrate:
  249. return None
  250. return (bitrate // 1000) if bitrate % 1000 == 0 else bitrate
  251. for source in urls_sources:
  252. protocol = source['protocol']
  253. if protocol == 'rtmp' or protocol == 'rtmpe':
  254. mobj = re.search(r'^(?P<url>rtmpe?://[^/]+/(?P<app>[^/]+))/(?P<playpath>.+)$', source['url'])
  255. if not mobj:
  256. continue
  257. formats.append({
  258. 'url': mobj.group('url'),
  259. 'app': mobj.group('app'),
  260. 'play_path': mobj.group('playpath'),
  261. 'player_url': 'http://livepassdl.conviva.com/hf/ver/2.79.0.17083/LivePassModuleMain.swf',
  262. 'page_url': 'http://www.prosieben.de',
  263. 'vbr': fix_bitrate(source['bitrate']),
  264. 'ext': 'mp4',
  265. 'format_id': '%s_%s' % (source['cdn'], source['bitrate']),
  266. })
  267. else:
  268. formats.append({
  269. 'url': source['url'],
  270. 'vbr': fix_bitrate(source['bitrate']),
  271. })
  272. self._sort_formats(formats)
  273. return {
  274. 'id': clip_id,
  275. 'title': title,
  276. 'description': description,
  277. 'thumbnail': thumbnail,
  278. 'upload_date': upload_date,
  279. 'duration': duration,
  280. 'formats': formats,
  281. }
  282. def _extract_playlist(self, url, webpage):
  283. playlist_id = self._html_search_regex(
  284. self._PLAYLIST_ID_REGEXES, webpage, 'playlist id')
  285. for regex in self._PLAYLIST_CLIP_REGEXES:
  286. playlist_clips = re.findall(regex, webpage)
  287. if playlist_clips:
  288. title = self._html_search_regex(
  289. self._TITLE_REGEXES, webpage, 'title')
  290. description = self._html_search_regex(
  291. self._DESCRIPTION_REGEXES, webpage, 'description', fatal=False)
  292. entries = [
  293. self.url_result(
  294. re.match('(.+?//.+?)/', url).group(1) + clip_path,
  295. 'ProSiebenSat1')
  296. for clip_path in playlist_clips]
  297. return self.playlist_result(entries, playlist_id, title, description)
  298. def _real_extract(self, url):
  299. video_id = self._match_id(url)
  300. webpage = self._download_webpage(url, video_id)
  301. page_type = self._search_regex(
  302. self._PAGE_TYPE_REGEXES, webpage,
  303. 'page type', default='clip').lower()
  304. if page_type == 'clip':
  305. return self._extract_clip(url, webpage)
  306. elif page_type == 'playlist':
  307. return self._extract_playlist(url, webpage)