]>
Commit | Line | Data |
---|---|---|
22f5f5c6 | 1 | from .common import InfoExtractor |
8bdd16b4 | 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 | ) | |
22f5f5c6 AJ |
11 | |
12 | ||
13 | class MallTVIE(InfoExtractor): | |
d5147b65 | 14 | _VALID_URL = r'https?://(?:(?:www|sk)\.)?mall\.tv/(?:[^/]+/)*(?P<id>[^/?#&]+)' |
4de3cb88 S |
15 | _TESTS = [{ |
16 | 'url': 'https://www.mall.tv/18-miliard-pro-neziskovky-opravdu-jsou-sportovci-nebo-clovek-v-tisni-pijavice', | |
17 | 'md5': '1c4a37f080e1f3023103a7b43458e518', | |
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?', | |
8bdd16b4 | 23 | 'description': 'md5:db7d5744a4bd4043d9d98324aa72ab35', |
4de3cb88 S |
24 | 'duration': 216, |
25 | 'timestamp': 1538870400, | |
26 | 'upload_date': '20181007', | |
27 | 'view_count': int, | |
22f5f5c6 | 28 | } |
4de3cb88 S |
29 | }, { |
30 | 'url': 'https://www.mall.tv/kdo-to-plati/18-miliard-pro-neziskovky-opravdu-jsou-sportovci-nebo-clovek-v-tisni-pijavice', | |
31 | 'only_matching': True, | |
d5147b65 MD |
32 | }, { |
33 | 'url': 'https://sk.mall.tv/gejmhaus/reklamacia-nehreje-vyrobnik-tepla-alebo-spekacka', | |
34 | 'only_matching': True, | |
4de3cb88 | 35 | }] |
22f5f5c6 AJ |
36 | |
37 | def _real_extract(self, url): | |
38 | display_id = self._match_id(url) | |
4de3cb88 S |
39 | |
40 | webpage = self._download_webpage( | |
41 | url, display_id, headers=self.geo_verification_headers()) | |
42 | ||
8bdd16b4 | 43 | video = self._parse_json(self._search_regex( |
44 | r'videoObject\s*=\s*JSON\.parse\(JSON\.stringify\(({.+?})\)\);', | |
45 | webpage, 'video object'), display_id) | |
46 | video_source = video['VideoSource'] | |
4de3cb88 | 47 | video_id = self._search_regex( |
8bdd16b4 | 48 | r'/([\da-z]+)/index\b', video_source, 'video id') |
49 | ||
50 | formats = self._extract_m3u8_formats( | |
51 | video_source + '.m3u8', video_id, 'mp4', 'm3u8_native') | |
52 | self._sort_formats(formats) | |
53 | ||
54 | subtitles = {} | |
55 | for s in (video.get('Subtitles') or {}): | |
56 | s_url = s.get('Url') | |
57 | if not s_url: | |
58 | continue | |
59 | subtitles.setdefault(s.get('Language') or 'cz', []).append({ | |
60 | 'url': s_url, | |
61 | }) | |
62 | ||
63 | entity_counts = video.get('EntityCounts') or {} | |
4de3cb88 | 64 | |
8bdd16b4 | 65 | def get_count(k): |
66 | v = entity_counts.get(k + 's') or {} | |
67 | return int_or_none(dict_get(v, ('Count', 'StrCount'))) | |
4de3cb88 | 68 | |
22f5f5c6 | 69 | info = self._search_json_ld(webpage, video_id, default={}) |
22f5f5c6 | 70 | |
8bdd16b4 | 71 | return merge_dicts({ |
4de3cb88 S |
72 | 'id': video_id, |
73 | 'display_id': display_id, | |
8bdd16b4 | 74 | 'title': video.get('Title'), |
75 | 'description': clean_html(video.get('Description')), | |
76 | 'thumbnail': video.get('ThumbnailUrl'), | |
77 | 'formats': formats, | |
78 | 'subtitles': subtitles, | |
79 | 'duration': int_or_none(video.get('DurationSeconds')) or parse_duration(video.get('Duration')), | |
80 | 'view_count': get_count('View'), | |
81 | 'like_count': get_count('Like'), | |
82 | 'dislike_count': get_count('Dislike'), | |
83 | 'average_rating': float_or_none(try_get(video, lambda x: x['EntityRating']['AvarageRate'])), | |
84 | 'comment_count': get_count('Comment'), | |
85 | }, info) |