logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

tass.py (2016B)


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