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.

109 lines
3.8 KiB

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