]>
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): | |
19 | _VALID_URL = r'http://(?:www\.)?kusi\.com/(?P<path>story/.+|video\?clipId=(?P<clipId>\d+))' | |
b6f94d81 | 20 | _TESTS = [{ |
199e7242 | 21 | 'url': 'http://www.kusi.com/story/31183873/turko-files-case-closed-put-on-hold', |
22 | 'md5': 'f926e7684294cf8cb7bdf8858e1b3988', | |
23 | 'info_dict': { | |
24 | 'id': '12203019', | |
25 | 'ext': 'mp4', | |
26 | 'title': 'Turko Files: Case Closed! & Put On Hold!', | |
28559564 YCH |
27 | 'duration': 231.0, |
28 | 'upload_date': '20160210', | |
29 | 'timestamp': 1455087571, | |
30 | 'thumbnail': 're:^https?://.*\.jpg$' | |
b6f94d81 YCH |
31 | }, |
32 | }, { | |
33 | 'url': 'http://kusi.com/video?clipId=12203019', | |
34 | 'info_dict': { | |
35 | 'id': '12203019', | |
36 | 'ext': 'mp4', | |
37 | 'title': 'Turko Files: Case Closed! & Put On Hold!', | |
5f1688f2 YCH |
38 | 'duration': 231.0, |
39 | 'upload_date': '20160210', | |
40 | 'timestamp': 1455087571, | |
41 | 'thumbnail': 're:^https?://.*\.jpg$' | |
b6f94d81 YCH |
42 | }, |
43 | 'params': { | |
44 | 'skip_download': True, # Same as previous one | |
45 | }, | |
46 | }] | |
199e7242 | 47 | |
48 | def _real_extract(self, url): | |
49 | mobj = re.match(self._VALID_URL, url) | |
5f1688f2 YCH |
50 | clip_id = mobj.group('clipId') |
51 | video_id = clip_id or mobj.group('path') | |
199e7242 | 52 | |
5f1688f2 | 53 | webpage = self._download_webpage(url, video_id) |
199e7242 | 54 | |
5f1688f2 YCH |
55 | if clip_id is None: |
56 | video_id = clip_id = self._html_search_regex( | |
57 | r'"clipId"\s*,\s*"(\d+)"', webpage, 'clip id') | |
199e7242 | 58 | |
5f1688f2 YCH |
59 | affiliate_id = self._search_regex( |
60 | r'affiliateId\s*:\s*\'([^\']+)\'', webpage, 'affiliate id') | |
61 | ||
62 | # See __Packages/worldnow/model/GalleryModel.as of WNGallery.swf | |
63 | xml_url = update_url_query('http://www.kusi.com/build.asp', { | |
64 | 'buildtype': 'buildfeaturexmlrequest', | |
65 | 'featureType': 'Clip', | |
66 | 'featureid': clip_id, | |
67 | 'affiliateno': affiliate_id, | |
68 | 'clientgroupid': '1', | |
69 | 'rnd': int(round(random.random() * 1000000)), | |
70 | }) | |
71 | ||
72 | doc = self._download_xml(xml_url, video_id) | |
73 | ||
fa880d20 YCH |
74 | video_title = xpath_text(doc, 'HEADLINE', fatal=True) |
75 | duration = float_or_none(xpath_text(doc, 'DURATION'), scale=1000) | |
76 | description = xpath_text(doc, 'ABSTRACT') | |
77 | thumbnail = xpath_text(doc, './THUMBNAILIMAGE/FILENAME') | |
78 | createtion_time = timeconvert(xpath_text(doc, 'rfc822creationdate')) | |
199e7242 | 79 | |
80 | quality_options = doc.find('{http://search.yahoo.com/mrss/}group').findall('{http://search.yahoo.com/mrss/}content') | |
81 | formats = [] | |
82 | for quality in quality_options: | |
5f1688f2 YCH |
83 | formats.append({ |
84 | 'url': compat_urllib_parse_unquote_plus(quality.attrib['url']), | |
85 | 'height': int_or_none(quality.attrib.get('height')), | |
86 | 'width': int_or_none(quality.attrib.get('width')), | |
fa880d20 | 87 | 'vbr': float_or_none(quality.attrib.get('bitratebits'), scale=1000), |
5f1688f2 | 88 | }) |
199e7242 | 89 | self._sort_formats(formats) |
90 | ||
91 | return { | |
92 | 'id': video_id, | |
93 | 'title': video_title, | |
94 | 'description': description, | |
95 | 'duration': duration, | |
96 | 'formats': formats, | |
5f1688f2 YCH |
97 | 'thumbnail': thumbnail, |
98 | 'timestamp': createtion_time, | |
199e7242 | 99 | } |