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