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.

73 lines
2.7 KiB

10 years ago
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. int_or_none,
  7. parse_duration,
  8. )
  9. class KontrTubeIE(InfoExtractor):
  10. IE_NAME = 'kontrtube'
  11. IE_DESC = 'KontrTube.ru - Труба зовёт'
  12. _VALID_URL = r'https?://(?:www\.)?kontrtube\.ru/videos/(?P<id>\d+)/(?P<display_id>[^/]+)/'
  13. _TEST = {
  14. 'url': 'http://www.kontrtube.ru/videos/2678/nad-olimpiyskoy-derevney-v-sochi-podnyat-rossiyskiy-flag/',
  15. 'md5': '975a991a4926c9a85f383a736a2e6b80',
  16. 'info_dict': {
  17. 'id': '2678',
  18. 'display_id': 'nad-olimpiyskoy-derevney-v-sochi-podnyat-rossiyskiy-flag',
  19. 'ext': 'mp4',
  20. 'title': 'Над олимпийской деревней в Сочи поднят российский флаг',
  21. 'description': 'md5:80edc4c613d5887ae8ccf1d59432be41',
  22. 'thumbnail': 'http://www.kontrtube.ru/contents/videos_screenshots/2000/2678/preview.mp4.jpg',
  23. 'duration': 270,
  24. }
  25. }
  26. def _real_extract(self, url):
  27. mobj = re.match(self._VALID_URL, url)
  28. video_id = mobj.group('id')
  29. display_id = mobj.group('display_id')
  30. webpage = self._download_webpage(
  31. url, display_id, 'Downloading page')
  32. video_url = self._search_regex(
  33. r"video_url\s*:\s*'(.+?)/?',", webpage, 'video URL')
  34. thumbnail = self._search_regex(
  35. r"preview_url\s*:\s*'(.+?)/?',", webpage, 'thumbnail', fatal=False)
  36. title = self._html_search_regex(
  37. r'(?s)<h2>(.+?)</h2>', webpage, 'title')
  38. description = self._html_search_meta(
  39. 'description', webpage, 'description')
  40. duration = self._search_regex(
  41. r'Длительность: <em>([^<]+)</em>', webpage, 'duration', fatal=False)
  42. if duration:
  43. duration = parse_duration(duration.replace('мин', 'min').replace('сек', 'sec'))
  44. view_count = self._search_regex(
  45. r'Просмотров: <em>([^<]+)</em>',
  46. webpage, 'view count', fatal=False)
  47. if view_count:
  48. view_count = int_or_none(view_count.replace(' ', ''))
  49. comment_count = int_or_none(self._search_regex(
  50. r'Комментарии \((\d+)\)<', webpage, ' comment count', fatal=False))
  51. return {
  52. 'id': video_id,
  53. 'display_id': display_id,
  54. 'url': video_url,
  55. 'thumbnail': thumbnail,
  56. 'title': title,
  57. 'description': description,
  58. 'duration': duration,
  59. 'view_count': int_or_none(view_count),
  60. 'comment_count': int_or_none(comment_count),
  61. }