]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/malltv.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / malltv.py
1 from .common import InfoExtractor
2 from ..utils import (
3 clean_html,
4 dict_get,
5 float_or_none,
6 int_or_none,
7 merge_dicts,
8 parse_duration,
9 try_get,
10 )
11
12
13 class MallTVIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:(?:www|sk)\.)?mall\.tv/(?:[^/]+/)*(?P<id>[^/?#&]+)'
15 _TESTS = [{
16 'url': 'https://www.mall.tv/18-miliard-pro-neziskovky-opravdu-jsou-sportovci-nebo-clovek-v-tisni-pijavice',
17 'md5': 'cd69ce29176f6533b65bff69ed9a5f2a',
18 'info_dict': {
19 'id': 't0zzt0',
20 'display_id': '18-miliard-pro-neziskovky-opravdu-jsou-sportovci-nebo-clovek-v-tisni-pijavice',
21 'ext': 'mp4',
22 'title': '18 miliard pro neziskovky. Opravdu jsou sportovci nebo Člověk v tísni pijavice?',
23 'description': 'md5:db7d5744a4bd4043d9d98324aa72ab35',
24 'duration': 216,
25 'timestamp': 1538870400,
26 'upload_date': '20181007',
27 'view_count': int,
28 'comment_count': int,
29 'thumbnail': 'https://cdn.vpplayer.tech/agmipnzv/encode/vjsnigfq/thumbnails/retina.jpg',
30 'average_rating': 9.060869565217391,
31 'dislike_count': int,
32 'like_count': int,
33 }
34 }, {
35 'url': 'https://www.mall.tv/kdo-to-plati/18-miliard-pro-neziskovky-opravdu-jsou-sportovci-nebo-clovek-v-tisni-pijavice',
36 'only_matching': True,
37 }, {
38 'url': 'https://sk.mall.tv/gejmhaus/reklamacia-nehreje-vyrobnik-tepla-alebo-spekacka',
39 'only_matching': True,
40 }, {
41 'url': 'https://www.mall.tv/zivoty-slavnych/nadeje-vychodu-i-zapadu-jak-michail-gorbacov-zmenil-politickou-mapu-sveta-a-ziskal-za-to-nobelovu-cenu-miru',
42 'info_dict': {
43 'id': 'yx010y',
44 'ext': 'mp4',
45 'dislike_count': int,
46 'description': 'md5:aee02bee5a8d072c6a8207b91d1905a9',
47 'thumbnail': 'https://cdn.vpplayer.tech/agmipnzv/encode/vjsnjdeu/thumbnails/retina.jpg',
48 'comment_count': int,
49 'display_id': 'md5:0ec2afa94d2e2b7091c019cef2a43a9b',
50 'like_count': int,
51 'duration': 752,
52 'timestamp': 1646956800,
53 'title': 'md5:fe79385daaf16d74c12c1ec4a26687af',
54 'view_count': int,
55 'upload_date': '20220311',
56 'average_rating': 9.685714285714285,
57 }
58 }]
59
60 def _real_extract(self, url):
61 display_id = self._match_id(url)
62
63 webpage = self._download_webpage(
64 url, display_id, headers=self.geo_verification_headers())
65
66 video = self._parse_json(self._search_regex(
67 r'videoObject\s*=\s*JSON\.parse\(JSON\.stringify\(({.+?})\)\);',
68 webpage, 'video object'), display_id)
69
70 video_id = self._search_regex(
71 r'<input\s*id\s*=\s*player-id-name\s*[^>]+value\s*=\s*(\w+)', webpage, 'video id')
72
73 formats = self._extract_m3u8_formats(
74 video['VideoSource'], video_id, 'mp4', 'm3u8_native')
75
76 subtitles = {}
77 for s in (video.get('Subtitles') or {}):
78 s_url = s.get('Url')
79 if not s_url:
80 continue
81 subtitles.setdefault(s.get('Language') or 'cz', []).append({
82 'url': s_url,
83 })
84
85 entity_counts = video.get('EntityCounts') or {}
86
87 def get_count(k):
88 v = entity_counts.get(k + 's') or {}
89 return int_or_none(dict_get(v, ('Count', 'StrCount')))
90
91 info = self._search_json_ld(webpage, video_id, default={})
92
93 return merge_dicts({
94 'id': str(video_id),
95 'display_id': display_id,
96 'title': video.get('Title'),
97 'description': clean_html(video.get('Description')),
98 'thumbnail': video.get('ThumbnailUrl'),
99 'formats': formats,
100 'subtitles': subtitles,
101 'duration': int_or_none(video.get('DurationSeconds')) or parse_duration(video.get('Duration')),
102 'view_count': get_count('View'),
103 'like_count': get_count('Like'),
104 'dislike_count': get_count('Dislike'),
105 'average_rating': float_or_none(try_get(video, lambda x: x['EntityRating']['AvarageRate'])),
106 'comment_count': get_count('Comment'),
107 }, info)