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