tvc.py 3.6 KB

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