prosiebensat1.py 14 KB

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