]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/chilloutzone.py
Merge remote-tracking branch 'upstream/master'
[yt-dlp.git] / youtube_dl / extractor / chilloutzone.py
1 from __future__ import unicode_literals
2
3 import re
4 import base64
5 import json
6
7 from .common import InfoExtractor
8 from ..utils import (
9 clean_html,
10 ExtractorError
11 )
12
13
14 class ChilloutzoneIE(InfoExtractor):
15 _VALID_URL = r'https?://(?:www\.)?chilloutzone\.net/video/(?P<id>[\w|-]+)\.html'
16 _TEST = {
17 'url': 'http://www.chilloutzone.net/video/enemene-meck-alle-katzen-weg.html',
18 'md5': 'a76f3457e813ea0037e5244f509e66d1',
19 'info_dict': {
20 'id': 'enemene-meck-alle-katzen-weg',
21 'ext': 'mp4',
22 'title': 'Enemene Meck - Alle Katzen weg',
23 'description': 'Ist das der Umkehrschluss des Niesenden Panda-Babys?',
24 },
25 }
26
27 def _real_extract(self, url):
28 mobj = re.match(self._VALID_URL, url)
29 video_id = mobj.group('id')
30
31 webpage = self._download_webpage(url, video_id)
32
33 base64_video_info = self._html_search_regex(
34 r'var cozVidData = "(.+?)";', webpage, 'video data')
35 decoded_video_info = base64.b64decode(base64_video_info).decode("utf-8")
36 video_info_dict = json.loads(decoded_video_info)
37
38 # get video information from dict
39 video_url = video_info_dict['mediaUrl']
40 description = clean_html(video_info_dict.get('description'))
41 title = video_info_dict['title']
42 native_platform = video_info_dict['nativePlatform']
43 native_video_id = video_info_dict['nativeVideoId']
44 source_priority = video_info_dict['sourcePriority']
45
46 # If nativePlatform is None a fallback mechanism is used (i.e. youtube embed)
47 if native_platform is None:
48 youtube_url = self._html_search_regex(
49 r'<iframe.* src="((?:https?:)?//(?:[^.]+\.)?youtube\.com/.+?)"',
50 webpage, 'fallback video URL', default=None)
51 if youtube_url is not None:
52 return self.url_result(youtube_url, ie='Youtube')
53
54 # Non Fallback: Decide to use native source (e.g. youtube or vimeo) or
55 # the own CDN
56 if source_priority == 'native':
57 if native_platform == 'youtube':
58 return self.url_result(video_id, ie='Youtube')
59 if native_platform == 'vimeo':
60 return self.url_result(
61 'http://vimeo.com/' + native_video_id, ie='Vimeo')
62
63 if not video_url:
64 raise ExtractorError('No video found')
65
66 return {
67 'id': video_id,
68 'url': video_url,
69 'ext': 'mp4',
70 'title': title,
71 'description': description,
72 }