carambatv.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. from .common import InfoExtractor
  2. from ..compat import compat_str
  3. from ..utils import (
  4. format_field,
  5. float_or_none,
  6. int_or_none,
  7. try_get,
  8. )
  9. from .videomore import VideomoreIE
  10. class CarambaTVIE(InfoExtractor):
  11. _VALID_URL = r'(?:carambatv:|https?://video1\.carambatv\.ru/v/)(?P<id>\d+)'
  12. _TESTS = [{
  13. 'url': 'http://video1.carambatv.ru/v/191910501',
  14. 'md5': '2f4a81b7cfd5ab866ee2d7270cb34a2a',
  15. 'info_dict': {
  16. 'id': '191910501',
  17. 'ext': 'mp4',
  18. 'title': '[BadComedian] - Разборка в Маниле (Абсолютный обзор)',
  19. 'thumbnail': r're:^https?://.*\.jpg',
  20. 'duration': 2678.31,
  21. },
  22. }, {
  23. 'url': 'carambatv:191910501',
  24. 'only_matching': True,
  25. }]
  26. def _real_extract(self, url):
  27. video_id = self._match_id(url)
  28. video = self._download_json(
  29. 'http://video1.carambatv.ru/v/%s/videoinfo.js' % video_id,
  30. video_id)
  31. title = video['title']
  32. base_url = video.get('video') or 'http://video1.carambatv.ru/v/%s/' % video_id
  33. formats = [{
  34. 'url': base_url + f['fn'],
  35. 'height': int_or_none(f.get('height')),
  36. 'format_id': format_field(f, 'height', '%sp'),
  37. } for f in video['qualities'] if f.get('fn')]
  38. thumbnail = video.get('splash')
  39. duration = float_or_none(try_get(
  40. video, lambda x: x['annotations'][0]['end_time'], compat_str))
  41. return {
  42. 'id': video_id,
  43. 'title': title,
  44. 'thumbnail': thumbnail,
  45. 'duration': duration,
  46. 'formats': formats,
  47. }
  48. class CarambaTVPageIE(InfoExtractor):
  49. _VALID_URL = r'https?://carambatv\.ru/(?:[^/]+/)+(?P<id>[^/?#&]+)'
  50. _TEST = {
  51. 'url': 'http://carambatv.ru/movie/bad-comedian/razborka-v-manile/',
  52. 'md5': 'a49fb0ec2ad66503eeb46aac237d3c86',
  53. 'info_dict': {
  54. 'id': '475222',
  55. 'ext': 'flv',
  56. 'title': '[BadComedian] - Разборка в Маниле (Абсолютный обзор)',
  57. 'thumbnail': r're:^https?://.*\.jpg',
  58. # duration reported by videomore is incorrect
  59. 'duration': int,
  60. },
  61. 'add_ie': [VideomoreIE.ie_key()],
  62. }
  63. def _real_extract(self, url):
  64. video_id = self._match_id(url)
  65. webpage = self._download_webpage(url, video_id)
  66. videomore_url = VideomoreIE._extract_url(webpage)
  67. if not videomore_url:
  68. videomore_id = self._search_regex(
  69. r'getVMCode\s*\(\s*["\']?(\d+)', webpage, 'videomore id',
  70. default=None)
  71. if videomore_id:
  72. videomore_url = 'videomore:%s' % videomore_id
  73. if videomore_url:
  74. title = self._og_search_title(webpage)
  75. return {
  76. '_type': 'url_transparent',
  77. 'url': videomore_url,
  78. 'ie_key': VideomoreIE.ie_key(),
  79. 'title': title,
  80. }
  81. video_url = self._og_search_property('video:iframe', webpage, default=None)
  82. if not video_url:
  83. video_id = self._search_regex(
  84. r'(?:video_id|crmb_vuid)\s*[:=]\s*["\']?(\d+)',
  85. webpage, 'video id')
  86. video_url = 'carambatv:%s' % video_id
  87. return self.url_result(video_url, CarambaTVIE.ie_key())