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
2.7 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. 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': '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': '%sp' % f['height'] if f.get('height') else None,
  37. } for f in video['qualities'] if f.get('fn')]
  38. self._sort_formats(formats)
  39. thumbnail = video.get('splash')
  40. duration = float_or_none(try_get(
  41. video, lambda x: x['annotations'][0]['end_time'], compat_str))
  42. return {
  43. 'id': video_id,
  44. 'title': title,
  45. 'thumbnail': thumbnail,
  46. 'duration': duration,
  47. 'formats': formats,
  48. }
  49. class CarambaTVPageIE(InfoExtractor):
  50. _VALID_URL = r'https?://carambatv\.ru/(?:[^/]+/)+(?P<id>[^/?#&]+)'
  51. _TEST = {
  52. 'url': 'http://carambatv.ru/movie/bad-comedian/razborka-v-manile/',
  53. 'md5': '',
  54. 'info_dict': {
  55. 'id': '191910501',
  56. 'ext': 'mp4',
  57. 'title': '[BadComedian] - Разборка в Маниле (Абсолютный обзор)',
  58. 'thumbnail': 're:^https?://.*\.jpg$',
  59. 'duration': 2678.31,
  60. },
  61. }
  62. def _real_extract(self, url):
  63. video_id = self._match_id(url)
  64. webpage = self._download_webpage(url, video_id)
  65. video_url = self._og_search_property('video:iframe', webpage, default=None)
  66. if not video_url:
  67. video_id = self._search_regex(
  68. r'(?:video_id|crmb_vuid)\s*[:=]\s*["\']?(\d+)',
  69. webpage, 'video id')
  70. video_url = 'carambatv:%s' % video_id
  71. return self.url_result(video_url, CarambaTVIE.ie_key())