]>
Commit | Line | Data |
---|---|---|
1 | from .common import InfoExtractor | |
2 | from ..utils import ( | |
3 | int_or_none, | |
4 | unified_strdate, | |
5 | unescapeHTML, | |
6 | ) | |
7 | ||
8 | ||
9 | class UstudioIE(InfoExtractor): | |
10 | IE_NAME = 'ustudio' | |
11 | _VALID_URL = r'https?://(?:(?:www|v1)\.)?ustudio\.com/video/(?P<id>[^/]+)/(?P<display_id>[^/?#&]+)' | |
12 | _TEST = { | |
13 | 'url': 'http://ustudio.com/video/Uxu2my9bgSph/san_francisco_golden_gate_bridge', | |
14 | 'md5': '58bbfca62125378742df01fc2abbdef6', | |
15 | 'info_dict': { | |
16 | 'id': 'Uxu2my9bgSph', | |
17 | 'display_id': 'san_francisco_golden_gate_bridge', | |
18 | 'ext': 'mp4', | |
19 | 'title': 'San Francisco: Golden Gate Bridge', | |
20 | 'description': 'md5:23925500697f2c6d4830e387ba51a9be', | |
21 | 'thumbnail': r're:^https?://.*\.jpg$', | |
22 | 'upload_date': '20111107', | |
23 | 'uploader': 'Tony Farley', | |
24 | } | |
25 | } | |
26 | ||
27 | def _real_extract(self, url): | |
28 | video_id, display_id = self._match_valid_url(url).groups() | |
29 | ||
30 | config = self._download_xml( | |
31 | 'http://v1.ustudio.com/embed/%s/ustudio/config.xml' % video_id, | |
32 | display_id) | |
33 | ||
34 | def extract(kind): | |
35 | return [{ | |
36 | 'url': unescapeHTML(item.attrib['url']), | |
37 | 'width': int_or_none(item.get('width')), | |
38 | 'height': int_or_none(item.get('height')), | |
39 | } for item in config.findall('./qualities/quality/%s' % kind) if item.get('url')] | |
40 | ||
41 | formats = extract('video') | |
42 | ||
43 | webpage = self._download_webpage(url, display_id) | |
44 | ||
45 | title = self._og_search_title(webpage) | |
46 | upload_date = unified_strdate(self._search_regex( | |
47 | r'(?s)Uploaded by\s*.+?\s*on\s*<span>([^<]+)</span>', | |
48 | webpage, 'upload date', fatal=False)) | |
49 | uploader = self._search_regex( | |
50 | r'Uploaded by\s*<a[^>]*>([^<]+)<', | |
51 | webpage, 'uploader', fatal=False) | |
52 | ||
53 | return { | |
54 | 'id': video_id, | |
55 | 'display_id': display_id, | |
56 | 'title': title, | |
57 | 'description': self._og_search_description(webpage), | |
58 | 'thumbnails': extract('image'), | |
59 | 'upload_date': upload_date, | |
60 | 'uploader': uploader, | |
61 | 'formats': formats, | |
62 | } | |
63 | ||
64 | ||
65 | class UstudioEmbedIE(InfoExtractor): | |
66 | IE_NAME = 'ustudio:embed' | |
67 | _VALID_URL = r'https?://(?:(?:app|embed)\.)?ustudio\.com/embed/(?P<uid>[^/]+)/(?P<id>[^/]+)' | |
68 | _TEST = { | |
69 | 'url': 'http://app.ustudio.com/embed/DeN7VdYRDKhP/Uw7G1kMCe65T', | |
70 | 'md5': '47c0be52a09b23a7f40de9469cec58f4', | |
71 | 'info_dict': { | |
72 | 'id': 'Uw7G1kMCe65T', | |
73 | 'ext': 'mp4', | |
74 | 'title': '5 Things IT Should Know About Video', | |
75 | 'description': 'md5:93d32650884b500115e158c5677d25ad', | |
76 | 'uploader_id': 'DeN7VdYRDKhP', | |
77 | } | |
78 | } | |
79 | ||
80 | def _real_extract(self, url): | |
81 | uploader_id, video_id = self._match_valid_url(url).groups() | |
82 | video_data = self._download_json( | |
83 | 'http://app.ustudio.com/embed/%s/%s/config.json' % (uploader_id, video_id), | |
84 | video_id)['videos'][0] | |
85 | title = video_data['name'] | |
86 | ||
87 | formats = [] | |
88 | for ext, qualities in video_data.get('transcodes', {}).items(): | |
89 | for quality in qualities: | |
90 | quality_url = quality.get('url') | |
91 | if not quality_url: | |
92 | continue | |
93 | height = int_or_none(quality.get('height')) | |
94 | formats.append({ | |
95 | 'format_id': '%s-%dp' % (ext, height) if height else ext, | |
96 | 'url': quality_url, | |
97 | 'width': int_or_none(quality.get('width')), | |
98 | 'height': height, | |
99 | }) | |
100 | ||
101 | thumbnails = [] | |
102 | for image in video_data.get('images', []): | |
103 | image_url = image.get('url') | |
104 | if not image_url: | |
105 | continue | |
106 | thumbnails.append({ | |
107 | 'url': image_url, | |
108 | }) | |
109 | ||
110 | return { | |
111 | 'id': video_id, | |
112 | 'title': title, | |
113 | 'description': video_data.get('description'), | |
114 | 'duration': int_or_none(video_data.get('duration')), | |
115 | 'uploader_id': uploader_id, | |
116 | 'tags': video_data.get('keywords'), | |
117 | 'thumbnails': thumbnails, | |
118 | 'formats': formats, | |
119 | } |