]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/ustudio.py
Merge branch 'kusi' of https://github.com/mutantmonkey/youtube-dl into mutantmonkey...
[yt-dlp.git] / youtube_dl / extractor / ustudio.py
1 from __future__ import unicode_literals
2
3 import re
4
5 from .common import InfoExtractor
6 from ..utils import (
7 int_or_none,
8 unified_strdate,
9 )
10
11
12 class UstudioIE(InfoExtractor):
13 _VALID_URL = r'https?://(?:(?:www|v1)\.)?ustudio\.com/video/(?P<id>[^/]+)/(?P<display_id>[^/?#&]+)'
14 _TEST = {
15 'url': 'http://ustudio.com/video/Uxu2my9bgSph/san_francisco_golden_gate_bridge',
16 'md5': '58bbfca62125378742df01fc2abbdef6',
17 'info_dict': {
18 'id': 'Uxu2my9bgSph',
19 'display_id': 'san_francisco_golden_gate_bridge',
20 'ext': 'mp4',
21 'title': 'San Francisco: Golden Gate Bridge',
22 'description': 'md5:23925500697f2c6d4830e387ba51a9be',
23 'thumbnail': 're:^https?://.*\.jpg$',
24 'upload_date': '20111107',
25 'uploader': 'Tony Farley',
26 }
27 }
28
29 def _real_extract(self, url):
30 mobj = re.match(self._VALID_URL, url)
31 video_id = mobj.group('id')
32 display_id = mobj.group('display_id')
33
34 config = self._download_xml(
35 'http://v1.ustudio.com/embed/%s/ustudio/config.xml' % video_id,
36 display_id)
37
38 def extract(kind):
39 return [{
40 'url': item.attrib['url'],
41 'width': int_or_none(item.get('width')),
42 'height': int_or_none(item.get('height')),
43 } for item in config.findall('./qualities/quality/%s' % kind) if item.get('url')]
44
45 formats = extract('video')
46 self._sort_formats(formats)
47
48 webpage = self._download_webpage(url, display_id)
49
50 title = self._og_search_title(webpage)
51 upload_date = unified_strdate(self._search_regex(
52 r'(?s)Uploaded by\s*.+?\s*on\s*<span>([^<]+)</span>',
53 webpage, 'upload date', fatal=False))
54 uploader = self._search_regex(
55 r'Uploaded by\s*<a[^>]*>([^<]+)<',
56 webpage, 'uploader', fatal=False)
57
58 return {
59 'id': video_id,
60 'display_id': display_id,
61 'title': title,
62 'description': self._og_search_description(webpage),
63 'thumbnails': extract('image'),
64 'upload_date': upload_date,
65 'uploader': uploader,
66 'formats': formats,
67 }