]>
Commit | Line | Data |
---|---|---|
5f1688f2 | 1 | import random |
ac668111 | 2 | import urllib.parse |
199e7242 | 3 | |
4 | from .common import InfoExtractor | |
5f1688f2 | 5 | from ..utils import ( |
5f1688f2 | 6 | float_or_none, |
ac668111 | 7 | int_or_none, |
5f1688f2 YCH |
8 | timeconvert, |
9 | update_url_query, | |
10 | xpath_text, | |
11 | ) | |
199e7242 | 12 | |
13 | ||
14 | class KUSIIE(InfoExtractor): | |
5886b38d | 15 | _VALID_URL = r'https?://(?:www\.)?kusi\.com/(?P<path>story/.+|video\?clipId=(?P<clipId>\d+))' |
b6f94d81 | 16 | _TESTS = [{ |
a06e1498 S |
17 | 'url': 'http://www.kusi.com/story/32849881/turko-files-refused-to-help-it-aint-right', |
18 | 'md5': '4e76ce8e53660ce9697d06c0ba6fc47d', | |
199e7242 | 19 | 'info_dict': { |
a06e1498 | 20 | 'id': '12689020', |
199e7242 | 21 | 'ext': 'mp4', |
a06e1498 S |
22 | 'title': "Turko Files: Refused to Help, It Ain't Right!", |
23 | 'duration': 223.586, | |
24 | 'upload_date': '20160826', | |
25 | 'timestamp': 1472233118, | |
ec85ded8 | 26 | 'thumbnail': r're:^https?://.*\.jpg$' |
b6f94d81 YCH |
27 | }, |
28 | }, { | |
29 | 'url': 'http://kusi.com/video?clipId=12203019', | |
a06e1498 | 30 | 'only_matching': True, |
b6f94d81 | 31 | }] |
199e7242 | 32 | |
33 | def _real_extract(self, url): | |
5ad28e7f | 34 | mobj = self._match_valid_url(url) |
5f1688f2 YCH |
35 | clip_id = mobj.group('clipId') |
36 | video_id = clip_id or mobj.group('path') | |
199e7242 | 37 | |
5f1688f2 | 38 | webpage = self._download_webpage(url, video_id) |
199e7242 | 39 | |
5f1688f2 YCH |
40 | if clip_id is None: |
41 | video_id = clip_id = self._html_search_regex( | |
42 | r'"clipId"\s*,\s*"(\d+)"', webpage, 'clip id') | |
199e7242 | 43 | |
5f1688f2 YCH |
44 | affiliate_id = self._search_regex( |
45 | r'affiliateId\s*:\s*\'([^\']+)\'', webpage, 'affiliate id') | |
46 | ||
47 | # See __Packages/worldnow/model/GalleryModel.as of WNGallery.swf | |
48 | xml_url = update_url_query('http://www.kusi.com/build.asp', { | |
49 | 'buildtype': 'buildfeaturexmlrequest', | |
50 | 'featureType': 'Clip', | |
51 | 'featureid': clip_id, | |
52 | 'affiliateno': affiliate_id, | |
53 | 'clientgroupid': '1', | |
54 | 'rnd': int(round(random.random() * 1000000)), | |
55 | }) | |
56 | ||
57 | doc = self._download_xml(xml_url, video_id) | |
58 | ||
fa880d20 YCH |
59 | video_title = xpath_text(doc, 'HEADLINE', fatal=True) |
60 | duration = float_or_none(xpath_text(doc, 'DURATION'), scale=1000) | |
61 | description = xpath_text(doc, 'ABSTRACT') | |
62 | thumbnail = xpath_text(doc, './THUMBNAILIMAGE/FILENAME') | |
a0566bbf | 63 | creation_time = timeconvert(xpath_text(doc, 'rfc822creationdate')) |
199e7242 | 64 | |
65 | quality_options = doc.find('{http://search.yahoo.com/mrss/}group').findall('{http://search.yahoo.com/mrss/}content') | |
66 | formats = [] | |
67 | for quality in quality_options: | |
5f1688f2 | 68 | formats.append({ |
ac668111 | 69 | 'url': urllib.parse.unquote_plus(quality.attrib['url']), |
5f1688f2 YCH |
70 | 'height': int_or_none(quality.attrib.get('height')), |
71 | 'width': int_or_none(quality.attrib.get('width')), | |
fa880d20 | 72 | 'vbr': float_or_none(quality.attrib.get('bitratebits'), scale=1000), |
5f1688f2 | 73 | }) |
199e7242 | 74 | self._sort_formats(formats) |
75 | ||
76 | return { | |
77 | 'id': video_id, | |
78 | 'title': video_title, | |
79 | 'description': description, | |
80 | 'duration': duration, | |
81 | 'formats': formats, | |
5f1688f2 | 82 | 'thumbnail': thumbnail, |
a0566bbf | 83 | 'timestamp': creation_time, |
199e7242 | 84 | } |