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