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.

87 lines
2.9 KiB

10 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. float_or_none,
  7. str_to_int,
  8. )
  9. class TvigleIE(InfoExtractor):
  10. IE_NAME = 'tvigle'
  11. IE_DESC = 'Интернет-телевидение Tvigle.ru'
  12. _VALID_URL = r'http://(?:www\.)?tvigle\.ru/(?:[^/]+/)+(?P<display_id>[^/]+)/$'
  13. _TESTS = [
  14. {
  15. 'url': 'http://www.tvigle.ru/video/brat/',
  16. 'md5': 'ff4344a4894b0524441fb6f8218dc716',
  17. 'info_dict': {
  18. 'id': '5118490',
  19. 'display_id': 'brat',
  20. 'ext': 'mp4',
  21. 'title': 'Брат',
  22. 'description': 'md5:d16ac7c0b47052ea51fddb92c4e413eb',
  23. 'duration': 5722.6,
  24. 'age_limit': 16,
  25. },
  26. },
  27. {
  28. 'url': 'http://www.tvigle.ru/video/vladimir-vysotskii/vedushchii-teleprogrammy-60-minut-ssha-o-vladimire-vysotskom/',
  29. 'md5': 'd9012d7c7c598fe7a11d7fb46dc1f574',
  30. 'info_dict': {
  31. 'id': '5142516',
  32. 'ext': 'mp4',
  33. 'title': 'Ведущий телепрограммы «60 минут» (США) о Владимире Высоцком',
  34. 'description': 'md5:027f7dc872948f14c96d19b4178428a4',
  35. 'duration': 186.080,
  36. 'age_limit': 0,
  37. },
  38. },
  39. ]
  40. def _real_extract(self, url):
  41. mobj = re.match(self._VALID_URL, url)
  42. display_id = mobj.group('display_id')
  43. webpage = self._download_webpage(url, display_id)
  44. video_id = self._html_search_regex(
  45. r'<li class="video-preview current_playing" id="(\d+)">', webpage, 'video id')
  46. video_data = self._download_json(
  47. 'http://cloud.tvigle.ru/api/play/video/%s/' % video_id, display_id)
  48. item = video_data['playlist']['items'][0]
  49. title = item['title']
  50. description = item['description']
  51. thumbnail = item['thumbnail']
  52. duration = float_or_none(item['durationMilliseconds'], 1000)
  53. age_limit = str_to_int(item['ageRestrictions'])
  54. formats = []
  55. for vcodec, fmts in item['videos'].items():
  56. for quality, video_url in fmts.items():
  57. formats.append({
  58. 'url': video_url,
  59. 'format_id': '%s-%s' % (vcodec, quality),
  60. 'vcodec': vcodec,
  61. 'height': int(quality[:-1]),
  62. 'filesize': item['video_files_size'][vcodec][quality],
  63. })
  64. self._sort_formats(formats)
  65. return {
  66. 'id': video_id,
  67. 'display_id': display_id,
  68. 'title': title,
  69. 'description': description,
  70. 'thumbnail': thumbnail,
  71. 'duration': duration,
  72. 'age_limit': age_limit,
  73. 'formats': formats,
  74. }