]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/twentymin.py
[extractors] Use new framework for existing embeds (#4307)
[yt-dlp.git] / yt_dlp / extractor / twentymin.py
CommitLineData
133b1886 1from .common import InfoExtractor
538b17a0
S
2from ..utils import (
3 int_or_none,
4 try_get,
5)
133b1886
S
6
7
8class TwentyMinutenIE(InfoExtractor):
9 IE_NAME = '20min'
538b17a0
S
10 _VALID_URL = r'''(?x)
11 https?://
12 (?:www\.)?20min\.ch/
13 (?:
14 videotv/*\?.*?\bvid=|
15 videoplayer/videoplayer\.html\?.*?\bvideoId@
16 )
17 (?P<id>\d+)
18 '''
bfd973ec 19 _EMBED_REGEX = [r'<iframe[^>]+src=(["\'])(?P<url>(?:(?:https?:)?//)?(?:www\.)?20min\.ch/videoplayer/videoplayer.html\?.*?\bvideoId@\d+.*?)\1']
133b1886 20 _TESTS = [{
133b1886 21 'url': 'http://www.20min.ch/videotv/?vid=469148&cid=2',
4e445985 22 'md5': 'e7264320db31eed8c38364150c12496e',
133b1886
S
23 'info_dict': {
24 'id': '469148',
4e445985 25 'ext': 'mp4',
133b1886 26 'title': '85 000 Franken für 15 perfekte Minuten',
538b17a0 27 'thumbnail': r're:https?://.*\.jpg$',
3cc8649c 28 },
4e445985 29 }, {
538b17a0 30 'url': 'http://www.20min.ch/videoplayer/videoplayer.html?params=client@twentyDE|videoId@523629',
4e445985
AS
31 'info_dict': {
32 'id': '523629',
4e445985
AS
33 'ext': 'mp4',
34 'title': 'So kommen Sie bei Eis und Schnee sicher an',
538b17a0
S
35 'description': 'md5:117c212f64b25e3d95747e5276863f7d',
36 'thumbnail': r're:https?://.*\.jpg$',
37 },
38 'params': {
39 'skip_download': True,
3cc8649c 40 },
133b1886
S
41 }, {
42 'url': 'http://www.20min.ch/videotv/?cid=44&vid=468738',
43 'only_matching': True,
133b1886
S
44 }]
45
46 def _real_extract(self, url):
538b17a0 47 video_id = self._match_id(url)
133b1886 48
538b17a0
S
49 video = self._download_json(
50 'http://api.20min.ch/video/%s/show' % video_id,
51 video_id)['content']
133b1886 52
538b17a0 53 title = video['title']
3cc8649c 54
538b17a0
S
55 formats = [{
56 'format_id': format_id,
57 'url': 'http://podcast.20min-tv.ch/podcast/20min/%s%s.mp4' % (video_id, p),
58 'quality': quality,
59 } for quality, (format_id, p) in enumerate([('sd', ''), ('hd', 'h')])]
60 self._sort_formats(formats)
133b1886 61
538b17a0
S
62 description = video.get('lead')
63 thumbnail = video.get('thumbnail')
133b1886 64
538b17a0
S
65 def extract_count(kind):
66 return try_get(
67 video,
68 lambda x: int_or_none(x['communityobject']['thumbs_%s' % kind]))
133b1886 69
538b17a0
S
70 like_count = extract_count('up')
71 dislike_count = extract_count('down')
4e445985 72
133b1886
S
73 return {
74 'id': video_id,
133b1886
S
75 'title': title,
76 'description': description,
77 'thumbnail': thumbnail,
538b17a0
S
78 'like_count': like_count,
79 'dislike_count': dislike_count,
4e445985 80 'formats': formats,
133b1886 81 }