]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/indavideo.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / indavideo.py
1 from .common import InfoExtractor
2 from ..utils import (
3 int_or_none,
4 parse_age_limit,
5 parse_iso8601,
6 time_seconds,
7 update_url_query,
8 )
9
10
11 class IndavideoEmbedIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:(?:embed\.)?indavideo\.hu/player/video/|assets\.indavideo\.hu/swf/player\.swf\?.*\b(?:v(?:ID|id))=)(?P<id>[\da-f]+)'
13 # Some example URLs covered by generic extractor:
14 # https://indavideo.hu/video/Vicces_cica_1
15 # https://index.indavideo.hu/video/Hod_Nemetorszagban
16 # https://auto.indavideo.hu/video/Sajat_utanfutoban_a_kis_tacsko
17 # https://film.indavideo.hu/video/f_farkaslesen
18 # https://palyazat.indavideo.hu/video/Embertelen_dal_Dodgem_egyuttes
19 _EMBED_REGEX = [r'<iframe[^>]+\bsrc=["\'](?P<url>(?:https?:)//embed\.indavideo\.hu/player/video/[\da-f]+)']
20 _TESTS = [{
21 'url': 'https://indavideo.hu/player/video/1bdc3c6d80/',
22 'md5': 'c8a507a1c7410685f83a06eaeeaafeab',
23 'info_dict': {
24 'id': '1837039',
25 'ext': 'mp4',
26 'title': 'Cicatánc',
27 'description': '',
28 'thumbnail': r're:^https?://.*\.jpg$',
29 'uploader': 'cukiajanlo',
30 'uploader_id': '83729',
31 'timestamp': 1439193826,
32 'upload_date': '20150810',
33 'duration': 72,
34 'age_limit': 0,
35 'tags': ['tánc', 'cica', 'cuki', 'cukiajanlo', 'newsroom'],
36 },
37 }, {
38 'url': 'https://embed.indavideo.hu/player/video/1bdc3c6d80?autostart=1&hide=1',
39 'only_matching': True,
40 }]
41 _WEBPAGE_TESTS = [{
42 'url': 'https://indavideo.hu/video/Vicces_cica_1',
43 'info_dict': {
44 'id': '1335611',
45 'ext': 'mp4',
46 'title': 'Vicces cica',
47 'description': 'Játszik a tablettel. :D',
48 'thumbnail': r're:^https?://.*\.jpg$',
49 'uploader': 'Jet_Pack',
50 'uploader_id': '491217',
51 'timestamp': 1390821212,
52 'upload_date': '20140127',
53 'duration': 7,
54 'age_limit': 0,
55 'tags': ['cica', 'Jet_Pack'],
56 },
57 }]
58
59 def _real_extract(self, url):
60 video_id = self._match_id(url)
61
62 video = self._download_json(
63 f'https://amfphp.indavideo.hu/SYm0json.php/player.playerHandler.getVideoData/{video_id}/',
64 video_id, query={'_': time_seconds()})['data']
65
66 video_urls = []
67
68 video_files = video.get('video_files')
69 if isinstance(video_files, list):
70 video_urls.extend(video_files)
71 elif isinstance(video_files, dict):
72 video_urls.extend(video_files.values())
73
74 video_urls = list(set(video_urls))
75
76 filesh = video.get('filesh') or {}
77
78 formats = []
79 for video_url in video_urls:
80 height = int_or_none(self._search_regex(
81 r'\.(\d{3,4})\.mp4(?:\?|$)', video_url, 'height', default=None))
82 if not height and len(filesh) == 1:
83 height = int_or_none(next(iter(filesh.keys())))
84 token = filesh.get(str(height))
85 if token is None:
86 continue
87 formats.append({
88 'url': update_url_query(video_url, {'token': token}),
89 'height': height,
90 })
91
92 timestamp = video.get('date')
93 if timestamp:
94 # upload date is in CEST
95 timestamp = parse_iso8601(timestamp + ' +0200', ' ')
96
97 thumbnails = [{
98 'url': self._proto_relative_url(thumbnail),
99 } for thumbnail in video.get('thumbnails', [])]
100
101 tags = [tag['title'] for tag in video.get('tags') or []]
102
103 return {
104 'id': video.get('id') or video_id,
105 'title': video.get('title'),
106 'description': video.get('description'),
107 'thumbnails': thumbnails,
108 'uploader': video.get('user_name'),
109 'uploader_id': video.get('user_id'),
110 'timestamp': timestamp,
111 'duration': int_or_none(video.get('length')),
112 'age_limit': parse_age_limit(video.get('age_limit')),
113 'tags': tags,
114 'formats': formats,
115 }