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
'https?://(?:www\.)?kusi\.com/(?P<path>story/.+|video\?clipId=(?P<clipId>\d+))' 
  21         'url': 'http://www.kusi.com/story/32849881/turko-files-refused-to-help-it-aint-right', 
  22         'md5': '4e76ce8e53660ce9697d06c0ba6fc47d', 
  26             'title': "Turko Files: Refused to Help, It Ain't Right!", 
  28             'upload_date': '20160826', 
  29             'timestamp': 1472233118, 
  30             'thumbnail': r
're:^https?://.*\.jpg$' 
  33         'url': 'http://kusi.com/video?clipId=12203019', 
  34         'only_matching': True, 
  37     def _real_extract(self
, url
): 
  38         mobj 
= re
.match(self
._VALID
_URL
, url
) 
  39         clip_id 
= mobj
.group('clipId') 
  40         video_id 
= clip_id 
or mobj
.group('path') 
  42         webpage 
= self
._download
_webpage
(url
, video_id
) 
  45             video_id 
= clip_id 
= self
._html
_search
_regex
( 
  46                 r
'"clipId"\s*,\s*"(\d+)"', webpage
, 'clip id') 
  48         affiliate_id 
= self
._search
_regex
( 
  49             r
'affiliateId\s*:\s*\'([^
\']+)\'', webpage, 'affiliate 
id') 
  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
', 
  56             'affiliateno
': affiliate_id, 
  58             'rnd
': int(round(random.random() * 1000000)), 
  61         doc = self._download_xml(xml_url, video_id) 
  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
')) 
  69         quality_options = doc.find('{http
://search
.yahoo
.com
/mrss
/}group
').findall('{http
://search
.yahoo
.com
/mrss
/}content
') 
  71         for quality in quality_options: 
  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
')), 
  76                 'vbr
': float_or_none(quality.attrib.get('bitratebits
'), scale=1000), 
  78         self._sort_formats(formats) 
  83             'description
': description, 
  86             'thumbnail
': thumbnail, 
  87             'timestamp
': createtion_time,