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.

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