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.

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