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