tvigle.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. unified_strdate,
  7. clean_html,
  8. )
  9. class TvigleIE(InfoExtractor):
  10. IE_NAME = 'tvigle'
  11. IE_DESC = 'Интернет-телевидение Tvigle.ru'
  12. _VALID_URL = r'http://(?:www\.)?tvigle\.ru/category/.+?video=(?P<id>\d+)'
  13. _TEST = {
  14. 'url': 'http://www.tvigle.ru/category/cinema/1608/?video=503081',
  15. 'md5': '09afba4616666249f087efc6dcf83cb3',
  16. 'info_dict': {
  17. 'id': '503081',
  18. 'ext': 'flv',
  19. 'title': 'Брат 2 ',
  20. 'description': 'md5:f5a42970f50648cee3d7ad740f3ae769',
  21. 'upload_date': '20110919',
  22. }
  23. }
  24. def _real_extract(self, url):
  25. mobj = re.match(self._VALID_URL, url)
  26. video_id = mobj.group('id')
  27. video_data = self._download_xml(
  28. 'http://www.tvigle.ru/xml/single.php?obj=%s' % video_id, video_id, 'Downloading video XML')
  29. video = video_data.find('./video')
  30. title = video.get('name')
  31. description = video.get('anons')
  32. if description:
  33. description = clean_html(description)
  34. thumbnail = video_data.get('img')
  35. upload_date = unified_strdate(video.get('date'))
  36. like_count = video.get('vtp')
  37. formats = []
  38. for num, (format_id, format_note) in enumerate([['low_file', 'SQ'], ['file', 'HQ'], ['hd', 'HD 720']]):
  39. video_url = video.get(format_id)
  40. if not video_url:
  41. continue
  42. formats.append({
  43. 'url': video_url,
  44. 'format_id': format_id,
  45. 'format_note': format_note,
  46. 'quality': num,
  47. })
  48. self._sort_formats(formats)
  49. return {
  50. 'id': video_id,
  51. 'title': title,
  52. 'description': description,
  53. 'thumbnail': thumbnail,
  54. 'upload_date': upload_date,
  55. 'like_count': like_count,
  56. 'formats': formats,
  57. }