2 from __future__ import unicode_literals
7 from .common import InfoExtractor
8 from ..compat import compat_urllib_parse_unquote_plus
18 class KUSIIE(InfoExtractor):
19 _VALID_URL = r'http://(?:www\.)?kusi\.com/(?P<path>story/.+|video\?clipId=(?P<clipId>\d+))'
21 'url': 'http://www.kusi.com/story/31183873/turko-files-case-closed-put-on-hold',
22 'md5': 'f926e7684294cf8cb7bdf8858e1b3988',
26 'title': 'Turko Files: Case Closed! & Put On Hold!',
30 'url': 'http://kusi.com/video?clipId=12203019',
34 'title': 'Turko Files: Case Closed! & Put On Hold!',
36 'upload_date': '20160210',
37 'timestamp': 1455087571,
38 'thumbnail': 're:^https?://.*\.jpg$'
41 'skip_download': True, # Same as previous one
45 def _real_extract(self, url):
46 mobj = re.match(self._VALID_URL, url)
47 clip_id = mobj.group('clipId')
48 video_id = clip_id or mobj.group('path')
50 webpage = self._download_webpage(url, video_id)
53 video_id = clip_id = self._html_search_regex(
54 r'"clipId"\s*,\s*"(\d+)"', webpage, 'clip id')
56 affiliate_id = self._search_regex(
57 r'affiliateId\s*:\s*\'([^\']+)\'', webpage, 'affiliate id')
59 # See __Packages/worldnow/model/GalleryModel.as of WNGallery.swf
60 xml_url = update_url_query('http://www.kusi.com/build.asp', {
61 'buildtype': 'buildfeaturexmlrequest',
62 'featureType': 'Clip',
64 'affiliateno': affiliate_id,
66 'rnd': int(round(random.random() * 1000000)),
69 doc = self._download_xml(xml_url, video_id)
71 video_title = xpath_text(doc, 'HEADLINE', fatal=True)
72 duration = float_or_none(xpath_text(doc, 'DURATION'), scale=1000)
73 description = xpath_text(doc, 'ABSTRACT')
74 thumbnail = xpath_text(doc, './THUMBNAILIMAGE/FILENAME')
75 createtion_time = timeconvert(xpath_text(doc, 'rfc822creationdate'))
77 quality_options = doc.find('{http://search.yahoo.com/mrss/}group').findall('{http://search.yahoo.com/mrss/}content')
79 for quality in quality_options:
81 'url': compat_urllib_parse_unquote_plus(quality.attrib['url']),
82 'height': int_or_none(quality.attrib.get('height')),
83 'width': int_or_none(quality.attrib.get('width')),
84 'vbr': float_or_none(quality.attrib.get('bitratebits'), scale=1000),
86 self._sort_formats(formats)
91 'description': description,
94 'thumbnail': thumbnail,
95 'timestamp': createtion_time,