mirror of https://github.com/yt-dlp/yt-dlp.git
[kusi] Simplify and improve
This commit is contained in:
parent
b6f94d81ea
commit
5f1688f271
|
@ -1,11 +1,18 @@
|
||||||
# coding: utf-8
|
# coding: utf-8
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
import random
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..compat import compat_urllib_parse_unquote_plus
|
from ..compat import compat_urllib_parse_unquote_plus
|
||||||
from ..utils import int_or_none
|
from ..utils import (
|
||||||
|
int_or_none,
|
||||||
|
float_or_none,
|
||||||
|
timeconvert,
|
||||||
|
update_url_query,
|
||||||
|
xpath_text,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class KUSIIE(InfoExtractor):
|
class KUSIIE(InfoExtractor):
|
||||||
|
@ -17,7 +24,7 @@ class KUSIIE(InfoExtractor):
|
||||||
'id': '12203019',
|
'id': '12203019',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Turko Files: Case Closed! & Put On Hold!',
|
'title': 'Turko Files: Case Closed! & Put On Hold!',
|
||||||
'duration': 231000,
|
'duration': 231,
|
||||||
},
|
},
|
||||||
}, {
|
}, {
|
||||||
'url': 'http://kusi.com/video?clipId=12203019',
|
'url': 'http://kusi.com/video?clipId=12203019',
|
||||||
|
@ -25,7 +32,10 @@ class KUSIIE(InfoExtractor):
|
||||||
'id': '12203019',
|
'id': '12203019',
|
||||||
'ext': 'mp4',
|
'ext': 'mp4',
|
||||||
'title': 'Turko Files: Case Closed! & Put On Hold!',
|
'title': 'Turko Files: Case Closed! & Put On Hold!',
|
||||||
'duration': 231000,
|
'duration': 231.0,
|
||||||
|
'upload_date': '20160210',
|
||||||
|
'timestamp': 1455087571,
|
||||||
|
'thumbnail': 're:^https?://.*\.jpg$'
|
||||||
},
|
},
|
||||||
'params': {
|
'params': {
|
||||||
'skip_download': True, # Same as previous one
|
'skip_download': True, # Same as previous one
|
||||||
|
@ -34,32 +44,46 @@ class KUSIIE(InfoExtractor):
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
mobj = re.match(self._VALID_URL, url)
|
mobj = re.match(self._VALID_URL, url)
|
||||||
|
clip_id = mobj.group('clipId')
|
||||||
|
video_id = clip_id or mobj.group('path')
|
||||||
|
|
||||||
if mobj.group('clipId') is not None:
|
webpage = self._download_webpage(url, video_id)
|
||||||
video_id = mobj.group('clipId')
|
|
||||||
else:
|
|
||||||
webpage = self._download_webpage(url, mobj.group('path'))
|
|
||||||
video_id = self._html_search_regex(r'"clipId", "(\d+)"', webpage,
|
|
||||||
'clipId')
|
|
||||||
|
|
||||||
xml_url = 'http://www.kusi.com/build.asp?buildtype=buildfeaturexml'\
|
if clip_id is None:
|
||||||
'request&featureType=Clip&featureid={0}&affiliateno=956&'\
|
video_id = clip_id = self._html_search_regex(
|
||||||
'clientgroupid=1&rnd=562461'.format(video_id)
|
r'"clipId"\s*,\s*"(\d+)"', webpage, 'clip id')
|
||||||
doc = self._download_xml(xml_url, video_id,
|
|
||||||
note='Downloading video info',
|
|
||||||
errnote='Failed to download video info')
|
|
||||||
|
|
||||||
video_title = doc.find('HEADLINE').text
|
affiliate_id = self._search_regex(
|
||||||
duration = int_or_none(doc.find('DURATION'), get_attr='text')
|
r'affiliateId\s*:\s*\'([^\']+)\'', webpage, 'affiliate id')
|
||||||
description = doc.find('ABSTRACT')
|
|
||||||
|
# See __Packages/worldnow/model/GalleryModel.as of WNGallery.swf
|
||||||
|
xml_url = update_url_query('http://www.kusi.com/build.asp', {
|
||||||
|
'buildtype': 'buildfeaturexmlrequest',
|
||||||
|
'featureType': 'Clip',
|
||||||
|
'featureid': clip_id,
|
||||||
|
'affiliateno': affiliate_id,
|
||||||
|
'clientgroupid': '1',
|
||||||
|
'rnd': int(round(random.random() * 1000000)),
|
||||||
|
})
|
||||||
|
|
||||||
|
doc = self._download_xml(xml_url, video_id)
|
||||||
|
|
||||||
|
video_title = xpath_text(doc, 'HEADLINE')
|
||||||
|
duration = float_or_none(
|
||||||
|
xpath_text(doc, 'DURATION', fatal=False), scale=1000)
|
||||||
|
description = xpath_text(doc, 'ABSTRACT', fatal=False)
|
||||||
|
thumbnail = xpath_text(doc, './THUMBNAILIMAGE/FILENAME', fatal=False)
|
||||||
|
createtion_time = timeconvert(
|
||||||
|
xpath_text(doc, 'rfc822creationdate', fatal=False))
|
||||||
|
|
||||||
quality_options = doc.find('{http://search.yahoo.com/mrss/}group').findall('{http://search.yahoo.com/mrss/}content')
|
quality_options = doc.find('{http://search.yahoo.com/mrss/}group').findall('{http://search.yahoo.com/mrss/}content')
|
||||||
formats = []
|
formats = []
|
||||||
for quality in quality_options:
|
for quality in quality_options:
|
||||||
if 'height' in quality.attrib:
|
|
||||||
formats.append({
|
formats.append({
|
||||||
'url': compat_urllib_parse_unquote_plus(quality.attrib['url']),
|
'url': compat_urllib_parse_unquote_plus(quality.attrib['url']),
|
||||||
'height': quality.attrib['height'],
|
'height': int_or_none(quality.attrib.get('height')),
|
||||||
|
'width': int_or_none(quality.attrib.get('width')),
|
||||||
|
'vbr': float_or_none(quality.attrib.get('bitratebits'), scale=1024),
|
||||||
})
|
})
|
||||||
self._sort_formats(formats)
|
self._sort_formats(formats)
|
||||||
|
|
||||||
|
@ -69,4 +93,6 @@ class KUSIIE(InfoExtractor):
|
||||||
'description': description,
|
'description': description,
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'formats': formats,
|
'formats': formats,
|
||||||
|
'thumbnail': thumbnail,
|
||||||
|
'timestamp': createtion_time,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue