]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/wevidi.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / wevidi.py
CommitLineData
1ea15603 1from .common import InfoExtractor
2from ..utils import clean_html, float_or_none, get_element_by_class, js_to_json, traverse_obj
3
4
5class WeVidiIE(InfoExtractor):
6 _VALID_URL = r'https?://(?:www\.)?wevidi\.net/watch/(?P<id>[\w-]{11})'
7 _TESTS = [{
8 'url': 'https://wevidi.net/watch/2th7UO5F4KV',
9 'md5': 'b913d1ff5bbad499e2c7ef4aa6d829d7',
10 'info_dict': {
11 'id': '2th7UO5F4KV',
12 'ext': 'mp4',
13 'title': 'YouTube Alternative: WeVidi - customizable channels & more',
14 'thumbnail': r're:^https?://.*\.jpg$',
15 'description': 'md5:73a27d0a87d49fbcc5584566326ebeed',
16 'uploader': 'eclecRC',
17 'duration': 932.098,
add96eb9 18 },
1ea15603 19 }, {
20 'url': 'https://wevidi.net/watch/ievRuuQHbPS',
21 'md5': 'ce8a94989a959bff9003fa27ee572935',
22 'info_dict': {
23 'id': 'ievRuuQHbPS',
24 'ext': 'mp4',
25 'title': 'WeVidi Playlists',
26 'thumbnail': r're:^https?://.*\.jpg$',
27 'description': 'md5:32cdfca272687390d9bd9b0c9c6153ee',
28 'uploader': 'WeVidi',
29 'duration': 36.1999,
add96eb9 30 },
1ea15603 31 }, {
32 'url': 'https://wevidi.net/watch/PcMzDWaQSWb',
33 'md5': '55ee0d3434be5d9e5cc76b83f2bb57ec',
34 'info_dict': {
35 'id': 'PcMzDWaQSWb',
36 'ext': 'mp4',
37 'title': 'Cat blep',
38 'thumbnail': r're:^https?://.*\.jpg$',
39 'description': 'md5:e2c9e2b54b8bb424cc64937c8fdc068f',
40 'uploader': 'WeVidi',
41 'duration': 41.972,
add96eb9 42 },
1ea15603 43 }, {
44 'url': 'https://wevidi.net/watch/wJnRqDHNe_u',
45 'md5': 'c8f263dd47e66cc17546b3abf47b5a77',
46 'info_dict': {
47 'id': 'wJnRqDHNe_u',
48 'ext': 'mp4',
49 'title': 'Gissy Talks: YouTube Alternatives',
50 'thumbnail': r're:^https?://.*\.jpg$',
51 'description': 'md5:e65036f0d4af80e0af191bd11af5195e',
52 'uploader': 'GissyEva',
53 'duration': 630.451,
add96eb9 54 },
1ea15603 55 }, {
56 'url': 'https://wevidi.net/watch/4m1c4yJR_yc',
57 'md5': 'c63ce5ca6990dce86855fc02ca5bc1ed',
58 'info_dict': {
59 'id': '4m1c4yJR_yc',
60 'ext': 'mp4',
61 'title': 'Enough of that! - Awesome Exilez Podcast',
62 'thumbnail': r're:^https?://.*\.jpg$',
63 'description': 'md5:96af99dd63468b2dfab3020560e3e9b2',
64 'uploader': 'eclecRC',
65 'duration': 6.804,
add96eb9 66 },
1ea15603 67 }]
68
69 def _extract_formats(self, wvplayer_props):
70 # Taken from WeVidi player JS: https://wevidi.net/layouts/default/static/player.min.js
71 resolution_map = {
72 1: 144,
73 2: 240,
74 3: 360,
75 4: 480,
76 5: 720,
add96eb9 77 6: 1080,
1ea15603 78 }
79
80 src_path = f'{wvplayer_props["srcVID"]}/{wvplayer_props["srcUID"]}/{wvplayer_props["srcNAME"]}'
81 for res in traverse_obj(wvplayer_props, ('resolutions', ..., {int}, {lambda x: x or None})):
82 format_id = str(-(res // -2) - 1)
83 yield {
84 'acodec': 'mp4a.40.2',
85 'ext': 'mp4',
86 'format_id': format_id,
87 'height': resolution_map.get(res),
88 'url': f'https://www.wevidi.net/videoplayback/{src_path}/{format_id}',
89 'vcodec': 'avc1.42E01E',
90 }
91
92 def _real_extract(self, url):
93 video_id = self._match_id(url)
94 webpage = self._download_webpage(url, video_id)
95
96 wvplayer_props = self._search_json(
97 r'WVPlayer\(', webpage, 'player', video_id,
98 transform_source=lambda x: js_to_json(x.replace('||', '}')))
99
100 return {
101 'id': video_id,
102 'title': clean_html(get_element_by_class('video_title', webpage)),
103 'description': clean_html(get_element_by_class('descr_long', webpage)),
104 'uploader': clean_html(get_element_by_class('username', webpage)),
105 'formats': list(self._extract_formats(wvplayer_props)),
106 'thumbnail': self._og_search_thumbnail(webpage),
107 'duration': float_or_none(wvplayer_props.get('duration')),
108 }