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