]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/altcensored.py
[ie/PrankCastPost] Add extractor (#8933)
[yt-dlp.git] / yt_dlp / extractor / altcensored.py
CommitLineData
3f90813f
RD
1import re
2
3from .archiveorg import ArchiveOrgIE
4from .common import InfoExtractor
5from ..utils import (
6 InAdvancePagedList,
7 int_or_none,
8 orderedSet,
9 str_to_int,
10 urljoin,
11)
12
13
14class AltCensoredIE(InfoExtractor):
15 IE_NAME = 'altcensored'
16 _VALID_URL = r'https?://(?:www\.)?altcensored\.com/(?:watch\?v=|embed/)(?P<id>[^/?#]+)'
17 _TESTS = [{
18 'url': 'https://www.altcensored.com/watch?v=k0srjLSkga8',
19 'info_dict': {
20 'id': 'youtube-k0srjLSkga8',
21 'ext': 'webm',
22 'title': "QUELLES SONT LES CONSÉQUENCES DE L'HYPERSEXUALISATION DE LA SOCIÉTÉ ?",
23 'display_id': 'k0srjLSkga8.webm',
24 'release_date': '20180403',
25 'creator': 'Virginie Vota',
26 'release_year': 2018,
27 'upload_date': '20230318',
28 'uploader': 'admin@altcensored.com',
29 'description': 'md5:0b38a8fc04103579d5c1db10a247dc30',
30 'timestamp': 1679161343,
31 'track': 'k0srjLSkga8',
32 'duration': 926.09,
33 'thumbnail': 'https://archive.org/download/youtube-k0srjLSkga8/youtube-k0srjLSkga8.thumbs/k0srjLSkga8_000925.jpg',
34 'view_count': int,
35 'categories': ['News & Politics'],
36 }
37 }]
38
39 def _real_extract(self, url):
40 video_id = self._match_id(url)
41 webpage = self._download_webpage(url, video_id)
42
43 return {
44 '_type': 'url_transparent',
45 'url': f'https://archive.org/details/youtube-{video_id}',
46 'ie_key': ArchiveOrgIE.ie_key(),
47 'view_count': str_to_int(self._html_search_regex(
48 r'YouTube Views:(?:\s|&nbsp;)*([\d,]+)', webpage, 'view count', default=None)),
49 'categories': self._html_search_regex(
50 r'<a href="/category/\d+">\s*\n?\s*([^<]+)</a>',
51 webpage, 'category', default='').split() or None,
52 }
53
54
55class AltCensoredChannelIE(InfoExtractor):
56 IE_NAME = 'altcensored:channel'
57 _VALID_URL = r'https?://(?:www\.)?altcensored\.com/channel/(?!page|table)(?P<id>[^/?#]+)'
58 _PAGE_SIZE = 24
59 _TESTS = [{
60 'url': 'https://www.altcensored.com/channel/UCFPTO55xxHqFqkzRZHu4kcw',
61 'info_dict': {
62 'title': 'Virginie Vota',
63 'id': 'UCFPTO55xxHqFqkzRZHu4kcw',
64 },
65 'playlist_count': 91
66 }, {
67 'url': 'https://altcensored.com/channel/UC9CcJ96HKMWn0LZlcxlpFTw',
68 'info_dict': {
69 'title': 'yukikaze775',
70 'id': 'UC9CcJ96HKMWn0LZlcxlpFTw',
71 },
72 'playlist_count': 4
73 }]
74
75 def _real_extract(self, url):
76 channel_id = self._match_id(url)
77 webpage = self._download_webpage(
78 url, channel_id, 'Download channel webpage', 'Unable to get channel webpage')
79 title = self._html_search_meta('altcen_title', webpage, 'title', fatal=False)
80 page_count = int_or_none(self._html_search_regex(
81 r'<a[^>]+href="/channel/\w+/page/(\d+)">(?:\1)</a>',
82 webpage, 'page count', default='1'))
83
84 def page_func(page_num):
85 page_num += 1
86 webpage = self._download_webpage(
87 f'https://altcensored.com/channel/{channel_id}/page/{page_num}',
88 channel_id, note=f'Downloading page {page_num}')
89
90 items = re.findall(r'<a[^>]+href="(/watch\?v=[^"]+)', webpage)
91 return [self.url_result(urljoin('https://www.altcensored.com', path), AltCensoredIE)
92 for path in orderedSet(items)]
93
94 return self.playlist_result(
95 InAdvancePagedList(page_func, page_count, self._PAGE_SIZE),
96 playlist_id=channel_id, playlist_title=title)