tass.py 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import json
  2. from .common import InfoExtractor
  3. from ..utils import (
  4. js_to_json,
  5. qualities,
  6. )
  7. class TassIE(InfoExtractor):
  8. _WORKING = False
  9. _VALID_URL = r'https?://(?:tass\.ru|itar-tass\.com)/[^/]+/(?P<id>\d+)'
  10. _TESTS = [
  11. {
  12. 'url': 'http://tass.ru/obschestvo/1586870',
  13. 'md5': '3b4cdd011bc59174596b6145cda474a4',
  14. 'info_dict': {
  15. 'id': '1586870',
  16. 'ext': 'mp4',
  17. 'title': 'Посетителям московского зоопарка показали красную панду',
  18. 'description': 'Приехавшую из Дублина Зейну можно увидеть в павильоне "Кошки тропиков"',
  19. 'thumbnail': r're:^https?://.*\.jpg$',
  20. },
  21. },
  22. {
  23. 'url': 'http://itar-tass.com/obschestvo/1600009',
  24. 'only_matching': True,
  25. },
  26. ]
  27. def _real_extract(self, url):
  28. video_id = self._match_id(url)
  29. webpage = self._download_webpage(url, video_id)
  30. sources = json.loads(js_to_json(self._search_regex(
  31. r'(?s)sources\s*:\s*(\[.+?\])', webpage, 'sources')))
  32. quality = qualities(['sd', 'hd'])
  33. formats = []
  34. for source in sources:
  35. video_url = source.get('file')
  36. if not video_url or not video_url.startswith('http') or not video_url.endswith('.mp4'):
  37. continue
  38. label = source.get('label')
  39. formats.append({
  40. 'url': video_url,
  41. 'format_id': label,
  42. 'quality': quality(label),
  43. })
  44. return {
  45. 'id': video_id,
  46. 'title': self._og_search_title(webpage),
  47. 'description': self._og_search_description(webpage),
  48. 'thumbnail': self._og_search_thumbnail(webpage),
  49. 'formats': formats,
  50. }