]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/chilloutzone.py
Merge branch 'chilloutzone'
[yt-dlp.git] / youtube_dl / extractor / chilloutzone.py
1 import re
2 import base64
3 import urllib
4 import json
5
6 from .common import InfoExtractor
7
8 video_container = ('.mp4', '.mkv', '.flv')
9
10 class ChilloutzoneIE(InfoExtractor):
11 _VALID_URL = r'(?:https?://)?(?:www\.)?chilloutzone\.net/video/(?P<id>[\w|-]+).html'
12 _TEST = {
13 'url': 'http://www.chilloutzone.net/video/enemene-meck-alle-katzen-weg.html',
14 'md5': 'a76f3457e813ea0037e5244f509e66d1',
15 'info_dict': {
16 'id': 'enemene-meck-alle-katzen-weg',
17 'ext': 'mp4',
18 'title': 'Enemene Meck - Alle Katzen weg',
19 },
20 }
21
22 def _real_extract(self, url):
23 mobj = re.match(self._VALID_URL, url)
24 video_id = mobj.group('id')
25
26 webpage_url = 'http://www.chilloutzone.net/video/' + video_id + '.html'
27
28 # Log that we are starting to download the page
29 self.report_download_webpage(webpage_url)
30 webpage = self._download_webpage(webpage_url, video_id)
31
32 # Log that we are starting to parse the page
33 self.report_extraction(video_id)
34 # Find base64 decoded file info
35 base64_video_info = self._html_search_regex(r'var cozVidData = "(.+?)";', webpage, u'video Data')
36 # decode string and find video file
37 decoded_video_info = base64.b64decode(base64_video_info).decode("utf-8")
38 video_info_dict = json.loads(decoded_video_info)
39 # get video information from dict
40 media_url = video_info_dict['mediaUrl']
41 description = video_info_dict['description']
42 title = video_info_dict['title']
43 native_platform = video_info_dict['nativePlatform']
44 native_video_id = video_info_dict['nativeVideoId']
45 source_priority = video_info_dict['sourcePriority']
46
47
48 # Start video extraction
49 video_url = ''
50 # If nativePlatform is None a fallback mechanism is used (i.e. youtube embed)
51 if native_platform == None:
52 # Look for other video urls
53 video_url = self._html_search_regex(r'<iframe.* src="(.+?)".*', webpage, u'fallback Video URL')
54 if 'youtube' in video_url:
55 self.to_screen(u'Youtube video detected:')
56 return self.url_result(video_url, ie='Youtube')
57
58 # For debugging purposes
59 #print video_info_dict
60 #print native_platform
61 #print native_video_id
62 #print source_priority
63 #print media_url
64
65 # Non Fallback: Decide to use native source (e.g. youtube or vimeo) or
66 # the own CDN
67 if source_priority == 'native':
68 if native_platform == 'youtube':
69 self.to_screen(u'Youtube video detected:')
70 video_url = 'https://www.youtube.com/watch?v=' + native_video_id
71 return self.url_result(video_url, ie='Youtube')
72 if native_platform == 'vimeo':
73 self.to_screen(u'Vimeo video detected:')
74 video_url = 'http://vimeo.com/' + native_video_id
75 return self.url_result(video_url, ie='Vimeo')
76
77 # No redirect, use coz media url
78 video_url = media_url
79 if video_url.endswith('.mp4') == False:
80 self.report_warning(u'Url does not contain a video container')
81 return []
82
83
84 return [{
85 'id': video_id,
86 'url': video_url,
87 'ext': 'mp4',
88 'title': title,
89 'description': description,
90 }]
91
92
93