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.

102 lines
3.2 KiB

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