You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

88 lines
3.0 KiB

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