]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/ustudio.py
[extractor/youtube] Fix bug in b7c47b743871cdf3e0de75b17e4454d987384bf9
[yt-dlp.git] / yt_dlp / extractor / ustudio.py
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 self._sort_formats(formats)
43
44 webpage = self._download_webpage(url, display_id)
45
46 title = self._og_search_title(webpage)
47 upload_date = unified_strdate(self._search_regex(
48 r'(?s)Uploaded by\s*.+?\s*on\s*<span>([^<]+)</span>',
49 webpage, 'upload date', fatal=False))
50 uploader = self._search_regex(
51 r'Uploaded by\s*<a[^>]*>([^<]+)<',
52 webpage, 'uploader', fatal=False)
53
54 return {
55 'id': video_id,
56 'display_id': display_id,
57 'title': title,
58 'description': self._og_search_description(webpage),
59 'thumbnails': extract('image'),
60 'upload_date': upload_date,
61 'uploader': uploader,
62 'formats': formats,
63 }
64
65
66 class UstudioEmbedIE(InfoExtractor):
67 IE_NAME = 'ustudio:embed'
68 _VALID_URL = r'https?://(?:(?:app|embed)\.)?ustudio\.com/embed/(?P<uid>[^/]+)/(?P<id>[^/]+)'
69 _TEST = {
70 'url': 'http://app.ustudio.com/embed/DeN7VdYRDKhP/Uw7G1kMCe65T',
71 'md5': '47c0be52a09b23a7f40de9469cec58f4',
72 'info_dict': {
73 'id': 'Uw7G1kMCe65T',
74 'ext': 'mp4',
75 'title': '5 Things IT Should Know About Video',
76 'description': 'md5:93d32650884b500115e158c5677d25ad',
77 'uploader_id': 'DeN7VdYRDKhP',
78 }
79 }
80
81 def _real_extract(self, url):
82 uploader_id, video_id = self._match_valid_url(url).groups()
83 video_data = self._download_json(
84 'http://app.ustudio.com/embed/%s/%s/config.json' % (uploader_id, video_id),
85 video_id)['videos'][0]
86 title = video_data['name']
87
88 formats = []
89 for ext, qualities in video_data.get('transcodes', {}).items():
90 for quality in qualities:
91 quality_url = quality.get('url')
92 if not quality_url:
93 continue
94 height = int_or_none(quality.get('height'))
95 formats.append({
96 'format_id': '%s-%dp' % (ext, height) if height else ext,
97 'url': quality_url,
98 'width': int_or_none(quality.get('width')),
99 'height': height,
100 })
101 self._sort_formats(formats)
102
103 thumbnails = []
104 for image in video_data.get('images', []):
105 image_url = image.get('url')
106 if not image_url:
107 continue
108 thumbnails.append({
109 'url': image_url,
110 })
111
112 return {
113 'id': video_id,
114 'title': title,
115 'description': video_data.get('description'),
116 'duration': int_or_none(video_data.get('duration')),
117 'uploader_id': uploader_id,
118 'tags': video_data.get('keywords'),
119 'thumbnails': thumbnails,
120 'formats': formats,
121 }