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.

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