]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/cultureunplugged.py
[downloader/http] Randomize HTTP chunk size
[youtube-dl] / youtube_dl / extractor / cultureunplugged.py
1 from __future__ import unicode_literals
2
3 import re
4 import time
5
6 from .common import InfoExtractor
7 from ..utils import (
8     int_or_none,
9     HEADRequest,
10 )
11
12
13 class CultureUnpluggedIE(InfoExtractor):
14     _VALID_URL = r'https?://(?:www\.)?cultureunplugged\.com/documentary/watch-online/play/(?P<id>\d+)(?:/(?P<display_id>[^/]+))?'
15     _TESTS = [{
16         'url': 'http://www.cultureunplugged.com/documentary/watch-online/play/53662/The-Next--Best-West',
17         'md5': 'ac6c093b089f7d05e79934dcb3d228fc',
18         'info_dict': {
19             'id': '53662',
20             'display_id': 'The-Next--Best-West',
21             'ext': 'mp4',
22             'title': 'The Next, Best West',
23             'description': 'md5:0423cd00833dea1519cf014e9d0903b1',
24             'thumbnail': r're:^https?://.*\.jpg$',
25             'creator': 'Coldstream Creative',
26             'duration': 2203,
27             'view_count': int,
28         }
29     }, {
30         'url': 'http://www.cultureunplugged.com/documentary/watch-online/play/53662',
31         'only_matching': True,
32     }]
33
34     def _real_extract(self, url):
35         mobj = re.match(self._VALID_URL, url)
36         video_id = mobj.group('id')
37         display_id = mobj.group('display_id') or video_id
38
39         # request setClientTimezone.php to get PHPSESSID cookie which is need to get valid json data in the next request
40         self._request_webpage(HEADRequest(
41             'http://www.cultureunplugged.com/setClientTimezone.php?timeOffset=%d' % -(time.timezone / 3600)), display_id)
42         movie_data = self._download_json(
43             'http://www.cultureunplugged.com/movie-data/cu-%s.json' % video_id, display_id)
44
45         video_url = movie_data['url']
46         title = movie_data['title']
47
48         description = movie_data.get('synopsis')
49         creator = movie_data.get('producer')
50         duration = int_or_none(movie_data.get('duration'))
51         view_count = int_or_none(movie_data.get('views'))
52
53         thumbnails = [{
54             'url': movie_data['%s_thumb' % size],
55             'id': size,
56             'preference': preference,
57         } for preference, size in enumerate((
58             'small', 'large')) if movie_data.get('%s_thumb' % size)]
59
60         return {
61             'id': video_id,
62             'display_id': display_id,
63             'url': video_url,
64             'title': title,
65             'description': description,
66             'creator': creator,
67             'duration': duration,
68             'view_count': view_count,
69             'thumbnails': thumbnails,
70         }