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