]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/chilloutzone.py
[youtube] Improve signature caching
[yt-dlp.git] / yt_dlp / extractor / chilloutzone.py
1 import json
2
3 from .common import InfoExtractor
4 from .youtube import YoutubeIE
5 from ..compat import compat_b64decode
6 from ..utils import (
7 clean_html,
8 ExtractorError
9 )
10
11
12 class ChilloutzoneIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:www\.)?chilloutzone\.net/video/(?P<id>[\w|-]+)\.html'
14 _TESTS = [{
15 'url': 'http://www.chilloutzone.net/video/enemene-meck-alle-katzen-weg.html',
16 'md5': 'a76f3457e813ea0037e5244f509e66d1',
17 'info_dict': {
18 'id': 'enemene-meck-alle-katzen-weg',
19 'ext': 'mp4',
20 'title': 'Enemene Meck - Alle Katzen weg',
21 'description': 'Ist das der Umkehrschluss des Niesenden Panda-Babys?',
22 },
23 }, {
24 'note': 'Video hosted at YouTube',
25 'url': 'http://www.chilloutzone.net/video/eine-sekunde-bevor.html',
26 'info_dict': {
27 'id': '1YVQaAgHyRU',
28 'ext': 'mp4',
29 'title': '16 Photos Taken 1 Second Before Disaster',
30 'description': 'md5:58a8fcf6a459fe0a08f54140f0ad1814',
31 'uploader': 'BuzzFeedVideo',
32 'uploader_id': 'BuzzFeedVideo',
33 'upload_date': '20131105',
34 },
35 }, {
36 'note': 'Video hosted at Vimeo',
37 'url': 'http://www.chilloutzone.net/video/icon-blending.html',
38 'md5': '2645c678b8dc4fefcc0e1b60db18dac1',
39 'info_dict': {
40 'id': '85523671',
41 'ext': 'mp4',
42 'title': 'The Sunday Times - Icons',
43 'description': 're:(?s)^Watch the making of - makingoficons.com.{300,}',
44 'uploader': 'Us',
45 'uploader_id': 'usfilms',
46 'upload_date': '20140131'
47 },
48 }]
49
50 def _real_extract(self, url):
51 mobj = self._match_valid_url(url)
52 video_id = mobj.group('id')
53
54 webpage = self._download_webpage(url, video_id)
55
56 base64_video_info = self._html_search_regex(
57 r'var cozVidData = "(.+?)";', webpage, 'video data')
58 decoded_video_info = compat_b64decode(base64_video_info).decode('utf-8')
59 video_info_dict = json.loads(decoded_video_info)
60
61 # get video information from dict
62 video_url = video_info_dict['mediaUrl']
63 description = clean_html(video_info_dict.get('description'))
64 title = video_info_dict['title']
65 native_platform = video_info_dict['nativePlatform']
66 native_video_id = video_info_dict['nativeVideoId']
67 source_priority = video_info_dict['sourcePriority']
68
69 # If nativePlatform is None a fallback mechanism is used (i.e. youtube embed)
70 if native_platform is None:
71 youtube_url = YoutubeIE._extract_url(webpage)
72 if youtube_url:
73 return self.url_result(youtube_url, ie=YoutubeIE.ie_key())
74
75 # Non Fallback: Decide to use native source (e.g. youtube or vimeo) or
76 # the own CDN
77 if source_priority == 'native':
78 if native_platform == 'youtube':
79 return self.url_result(native_video_id, ie='Youtube')
80 if native_platform == 'vimeo':
81 return self.url_result(
82 'http://vimeo.com/' + native_video_id, ie='Vimeo')
83
84 if not video_url:
85 raise ExtractorError('No video found')
86
87 return {
88 'id': video_id,
89 'url': video_url,
90 'ext': 'mp4',
91 'title': title,
92 'description': description,
93 }