]>
Commit | Line | Data |
---|---|---|
341ca8d7 | 1 | from .common import InfoExtractor |
4ccabf93 | 2 | from ..utils import ( |
3 | ExtractorError, | |
4 | int_or_none, | |
5 | parse_iso8601, | |
6 | ) | |
341ca8d7 PH |
7 | |
8 | ||
9 | class TriluliluIE(InfoExtractor): | |
4ccabf93 | 10 | _VALID_URL = r'https?://(?:(?:www|m)\.)?trilulilu\.ro/(?:[^/]+/)?(?P<id>[^/#\?]+)' |
11 | _TESTS = [{ | |
12 | 'url': 'http://www.trilulilu.ro/big-buck-bunny-1', | |
13 | 'md5': '68da087b676a6196a413549212f60cc6', | |
b3034f9d | 14 | 'info_dict': { |
2caf182f | 15 | 'id': 'ae2899e124140b', |
b3034f9d PH |
16 | 'ext': 'mp4', |
17 | 'title': 'Big Buck Bunny', | |
18 | 'description': ':) pentru copilul din noi', | |
4ccabf93 | 19 | 'uploader_id': 'chipy', |
20 | 'upload_date': '20120304', | |
21 | 'timestamp': 1330830647, | |
22 | 'uploader': 'chipy', | |
23 | 'view_count': int, | |
24 | 'like_count': int, | |
25 | 'comment_count': int, | |
341ca8d7 | 26 | }, |
4ccabf93 | 27 | }, { |
28 | 'url': 'http://www.trilulilu.ro/adena-ft-morreti-inocenta', | |
29 | 'md5': '929dfb8729dc71750463af88bbbbf4a4', | |
30 | 'info_dict': { | |
31 | 'id': 'f299710e3c91c5', | |
32 | 'ext': 'mp4', | |
33 | 'title': 'Adena ft. Morreti - Inocenta', | |
34 | 'description': 'pop music', | |
35 | 'uploader_id': 'VEVOmixt', | |
36 | 'upload_date': '20151204', | |
37 | 'uploader': 'VEVOmixt', | |
38 | 'timestamp': 1449187937, | |
39 | 'view_count': int, | |
40 | 'like_count': int, | |
41 | 'comment_count': int, | |
42 | }, | |
43 | }] | |
341ca8d7 PH |
44 | |
45 | def _real_extract(self, url): | |
2caf182f | 46 | display_id = self._match_id(url) |
4ccabf93 | 47 | media_info = self._download_json('http://m.trilulilu.ro/%s?format=json' % display_id, display_id) |
71d9fe78 | 48 | |
02e3952f | 49 | age_limit = 0 |
50 | errors = media_info.get('errors', {}) | |
51 | if errors.get('friends'): | |
52 | raise ExtractorError('This video is private.', expected=True) | |
53 | elif errors.get('geoblock'): | |
54 | raise ExtractorError('This video is not available in your country.', expected=True) | |
55 | elif errors.get('xxx_unlogged'): | |
56 | age_limit = 18 | |
57 | ||
71d9fe78 | 58 | media_class = media_info.get('class') |
59 | if media_class not in ('video', 'audio'): | |
60 | raise ExtractorError('not a video or an audio') | |
61 | ||
4ccabf93 | 62 | user = media_info.get('user', {}) |
2caf182f | 63 | |
4ccabf93 | 64 | thumbnail = media_info.get('cover_url') |
65 | if thumbnail: | |
66 | thumbnail.format(width='1600', height='1200') | |
341ca8d7 | 67 | |
71d9fe78 | 68 | # TODO: get correct ext for audio files |
69 | stream_type = media_info.get('stream_type') | |
70 | formats = [{ | |
71 | 'url': media_info['href'], | |
72 | 'ext': stream_type, | |
73 | }] | |
74 | if media_info.get('is_hd'): | |
75 | formats.append({ | |
76 | 'format_id': 'hd', | |
77 | 'url': media_info['hrefhd'], | |
4ccabf93 | 78 | 'ext': stream_type, |
71d9fe78 | 79 | }) |
4ccabf93 | 80 | if media_class == 'audio': |
81 | formats[0]['vcodec'] = 'none' | |
71d9fe78 | 82 | else: |
83 | formats[0]['format_id'] = 'sd' | |
341ca8d7 | 84 | |
fb7abb31 | 85 | return { |
4ccabf93 | 86 | 'id': media_info['identifier'].split('|')[1], |
2caf182f | 87 | 'display_id': display_id, |
341ca8d7 | 88 | 'formats': formats, |
4ccabf93 | 89 | 'title': media_info['title'], |
90 | 'description': media_info.get('description'), | |
341ca8d7 | 91 | 'thumbnail': thumbnail, |
4ccabf93 | 92 | 'uploader_id': user.get('username'), |
93 | 'uploader': user.get('fullname'), | |
94 | 'timestamp': parse_iso8601(media_info.get('published'), ' '), | |
95 | 'duration': int_or_none(media_info.get('duration')), | |
96 | 'view_count': int_or_none(media_info.get('count_views')), | |
97 | 'like_count': int_or_none(media_info.get('count_likes')), | |
98 | 'comment_count': int_or_none(media_info.get('count_comments')), | |
02e3952f | 99 | 'age_limit': age_limit, |
341ca8d7 | 100 | } |