]>
Commit | Line | Data |
---|---|---|
4a9540b6 PH |
1 | from __future__ import unicode_literals |
2 | ||
46a073bf AS |
3 | import re |
4 | import base64 | |
46a073bf AS |
5 | import json |
6 | ||
7 | from .common import InfoExtractor | |
d914d9d1 PH |
8 | from ..utils import ( |
9 | clean_html, | |
10 | ExtractorError | |
11 | ) | |
46a073bf | 12 | |
46a073bf AS |
13 | |
14 | class ChilloutzoneIE(InfoExtractor): | |
4a9540b6 | 15 | _VALID_URL = r'https?://(?:www\.)?chilloutzone\.net/video/(?P<id>[\w|-]+)\.html' |
8bc6c8e3 | 16 | _TESTS = [{ |
cd8662de AS |
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', | |
4a9540b6 | 23 | 'description': 'Ist das der Umkehrschluss des Niesenden Panda-Babys?', |
cd8662de | 24 | }, |
8bc6c8e3 PH |
25 | }, { |
26 | 'note': 'Video hosted at YouTube', | |
27 | 'url': 'http://www.chilloutzone.net/video/eine-sekunde-bevor.html', | |
28 | 'info_dict': { | |
29 | 'id': '1YVQaAgHyRU', | |
30 | 'ext': 'mp4', | |
31 | 'title': '16 Photos Taken 1 Second Before Disaster', | |
32 | 'description': 'md5:58a8fcf6a459fe0a08f54140f0ad1814', | |
33 | 'uploader': 'BuzzFeedVideo', | |
34 | 'uploader_id': 'BuzzFeedVideo', | |
35 | 'upload_date': '20131105', | |
36 | }, | |
37 | }, { | |
38 | 'note': 'Video hosted at Vimeo', | |
39 | 'url': 'http://www.chilloutzone.net/video/icon-blending.html', | |
40 | 'md5': '2645c678b8dc4fefcc0e1b60db18dac1', | |
41 | 'info_dict': { | |
42 | 'id': '85523671', | |
43 | 'ext': 'mp4', | |
44 | 'title': 'The Sunday Times - Icons', | |
89658351 | 45 | 'description': 'md5:3e1c0dc6047498d6728dcdaad0891762', |
8bc6c8e3 PH |
46 | 'uploader': 'Us', |
47 | 'uploader_id': 'usfilms', | |
48 | 'upload_date': '20140131' | |
49 | }, | |
50 | }] | |
46a073bf AS |
51 | |
52 | def _real_extract(self, url): | |
53 | mobj = re.match(self._VALID_URL, url) | |
cd8662de AS |
54 | video_id = mobj.group('id') |
55 | ||
4a9540b6 | 56 | webpage = self._download_webpage(url, video_id) |
cd8662de | 57 | |
4a9540b6 PH |
58 | base64_video_info = self._html_search_regex( |
59 | r'var cozVidData = "(.+?)";', webpage, 'video data') | |
cd8662de AS |
60 | decoded_video_info = base64.b64decode(base64_video_info).decode("utf-8") |
61 | video_info_dict = json.loads(decoded_video_info) | |
4a9540b6 | 62 | |
cd8662de | 63 | # get video information from dict |
4a9540b6 PH |
64 | video_url = video_info_dict['mediaUrl'] |
65 | description = clean_html(video_info_dict.get('description')) | |
cd8662de AS |
66 | title = video_info_dict['title'] |
67 | native_platform = video_info_dict['nativePlatform'] | |
68 | native_video_id = video_info_dict['nativeVideoId'] | |
69 | source_priority = video_info_dict['sourcePriority'] | |
70 | ||
cd8662de | 71 | # If nativePlatform is None a fallback mechanism is used (i.e. youtube embed) |
4a9540b6 PH |
72 | if native_platform is None: |
73 | youtube_url = self._html_search_regex( | |
74 | r'<iframe.* src="((?:https?:)?//(?:[^.]+\.)?youtube\.com/.+?)"', | |
75 | webpage, 'fallback video URL', default=None) | |
76 | if youtube_url is not None: | |
77 | return self.url_result(youtube_url, ie='Youtube') | |
cd8662de AS |
78 | |
79 | # Non Fallback: Decide to use native source (e.g. youtube or vimeo) or | |
80 | # the own CDN | |
81 | if source_priority == 'native': | |
82 | if native_platform == 'youtube': | |
c1e672d1 | 83 | return self.url_result(native_video_id, ie='Youtube') |
46a073bf | 84 | if native_platform == 'vimeo': |
4a9540b6 PH |
85 | return self.url_result( |
86 | 'http://vimeo.com/' + native_video_id, ie='Vimeo') | |
46a073bf | 87 | |
4a9540b6 PH |
88 | if not video_url: |
89 | raise ExtractorError('No video found') | |
46a073bf | 90 | |
4a9540b6 PH |
91 | return { |
92 | 'id': video_id, | |
93 | 'url': video_url, | |
94 | 'ext': 'mp4', | |
95 | 'title': title, | |
cd8662de | 96 | 'description': description, |
4a9540b6 | 97 | } |