tvc.py 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. clean_html,
  4. int_or_none,
  5. )
  6. class TVCIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?tvc\.ru/video/iframe/id/(?P<id>\d+)'
  8. _EMBED_REGEX = [r'<iframe[^>]+?src=(["\'])(?P<url>(?:http:)?//(?:www\.)?tvc\.ru/video/iframe/id/[^"]+)\1']
  9. _TEST = {
  10. 'url': 'http://www.tvc.ru/video/iframe/id/74622/isPlay/false/id_stat/channel/?acc_video_id=/channel/brand/id/17/show/episodes/episode_id/39702',
  11. 'md5': 'bbc5ff531d1e90e856f60fc4b3afd708',
  12. 'info_dict': {
  13. 'id': '74622',
  14. 'ext': 'mp4',
  15. 'title': 'События. "События". Эфир от 22.05.2015 14:30',
  16. 'thumbnail': r're:^https?://.*\.jpg$',
  17. 'duration': 1122,
  18. },
  19. }
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. video = self._download_json(
  23. f'http://www.tvc.ru/video/json/id/{video_id}', video_id)
  24. formats = []
  25. for info in video.get('path', {}).get('quality', []):
  26. video_url = info.get('url')
  27. if not video_url:
  28. continue
  29. format_id = self._search_regex(
  30. r'cdnvideo/([^/]+?)(?:-[^/]+?)?/', video_url,
  31. 'format id', default=None)
  32. formats.append({
  33. 'url': video_url,
  34. 'format_id': format_id,
  35. 'width': int_or_none(info.get('width')),
  36. 'height': int_or_none(info.get('height')),
  37. 'tbr': int_or_none(info.get('bitrate')),
  38. })
  39. return {
  40. 'id': video_id,
  41. 'title': video['title'],
  42. 'thumbnail': video.get('picture'),
  43. 'duration': int_or_none(video.get('duration')),
  44. 'formats': formats,
  45. }
  46. class TVCArticleIE(InfoExtractor):
  47. _VALID_URL = r'https?://(?:www\.)?tvc\.ru/(?!video/iframe/id/)(?P<id>[^?#]+)'
  48. _TESTS = [{
  49. 'url': 'http://www.tvc.ru/channel/brand/id/29/show/episodes/episode_id/39702/',
  50. 'info_dict': {
  51. 'id': '74622',
  52. 'ext': 'mp4',
  53. 'title': 'События. "События". Эфир от 22.05.2015 14:30',
  54. 'description': 'md5:ad7aa7db22903f983e687b8a3e98c6dd',
  55. 'thumbnail': r're:^https?://.*\.jpg$',
  56. 'duration': 1122,
  57. },
  58. }, {
  59. 'url': 'http://www.tvc.ru/news/show/id/69944',
  60. 'info_dict': {
  61. 'id': '75399',
  62. 'ext': 'mp4',
  63. 'title': 'Эксперты: в столице встал вопрос о максимально безопасных остановках',
  64. 'description': 'md5:f2098f71e21f309e89f69b525fd9846e',
  65. 'thumbnail': r're:^https?://.*\.jpg$',
  66. 'duration': 278,
  67. },
  68. }, {
  69. 'url': 'http://www.tvc.ru/channel/brand/id/47/show/episodes#',
  70. 'info_dict': {
  71. 'id': '2185',
  72. 'ext': 'mp4',
  73. 'title': 'Ещё не поздно. Эфир от 03.08.2013',
  74. 'description': 'md5:51fae9f3f8cfe67abce014e428e5b027',
  75. 'thumbnail': r're:^https?://.*\.jpg$',
  76. 'duration': 3316,
  77. },
  78. }]
  79. def _real_extract(self, url):
  80. webpage = self._download_webpage(url, self._match_id(url))
  81. return {
  82. '_type': 'url_transparent',
  83. 'ie_key': 'TVC',
  84. 'url': self._og_search_video_url(webpage),
  85. 'title': clean_html(self._og_search_title(webpage)),
  86. 'description': clean_html(self._og_search_description(webpage)),
  87. 'thumbnail': self._og_search_thumbnail(webpage),
  88. }