]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/popcorntimes.py
[cleanup] Add more ruff rules (#10149)
[yt-dlp.git] / yt_dlp / extractor / popcorntimes.py
CommitLineData
add96eb9 1import base64
2
7d55b62f 3from .common import InfoExtractor
7d55b62f
S
4from ..utils import int_or_none
5
6
7class PopcorntimesIE(InfoExtractor):
8 _VALID_URL = r'https?://popcorntimes\.tv/[^/]+/m/(?P<id>[^/]+)/(?P<display_id>[^/?#&]+)'
9 _TEST = {
10 'url': 'https://popcorntimes.tv/de/m/A1XCFvz/haensel-und-gretel-opera-fantasy',
11 'md5': '93f210991ad94ba8c3485950a2453257',
12 'info_dict': {
13 'id': 'A1XCFvz',
14 'display_id': 'haensel-und-gretel-opera-fantasy',
15 'ext': 'mp4',
16 'title': 'Hänsel und Gretel',
17 'description': 'md5:1b8146791726342e7b22ce8125cf6945',
18 'thumbnail': r're:^https?://.*\.jpg$',
19 'creator': 'John Paul',
20 'release_date': '19541009',
21 'duration': 4260,
22 'tbr': 5380,
23 'width': 720,
24 'height': 540,
25 },
26 }
27
28 def _real_extract(self, url):
5ad28e7f 29 mobj = self._match_valid_url(url)
7d55b62f
S
30 video_id, display_id = mobj.group('id', 'display_id')
31
32 webpage = self._download_webpage(url, display_id)
33
34 title = self._search_regex(
35 r'<h1>([^<]+)', webpage, 'title',
36 default=None) or self._html_search_meta(
37 'ya:ovs:original_name', webpage, 'title', fatal=True)
38
39 loc = self._search_regex(
40 r'PCTMLOC\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1', webpage, 'loc',
41 group='value')
42
43 loc_b64 = ''
44 for c in loc:
45 c_ord = ord(c)
46 if ord('a') <= c_ord <= ord('z') or ord('A') <= c_ord <= ord('Z'):
47 upper = ord('Z') if c_ord <= ord('Z') else ord('z')
48 c_ord += 13
49 if upper < c_ord:
50 c_ord -= 26
ac668111 51 loc_b64 += chr(c_ord)
7d55b62f 52
add96eb9 53 video_url = base64.b64decode(loc_b64).decode('utf-8')
7d55b62f
S
54
55 description = self._html_search_regex(
56 r'(?s)<div[^>]+class=["\']pt-movie-desc[^>]+>(.+?)</div>', webpage,
57 'description', fatal=False)
58
59 thumbnail = self._search_regex(
60 r'<img[^>]+class=["\']video-preview[^>]+\bsrc=(["\'])(?P<value>(?:(?!\1).)+)\1',
61 webpage, 'thumbnail', default=None,
62 group='value') or self._og_search_thumbnail(webpage)
63
64 creator = self._html_search_meta(
65 'video:director', webpage, 'creator', default=None)
66
67 release_date = self._html_search_meta(
68 'video:release_date', webpage, default=None)
69 if release_date:
70 release_date = release_date.replace('-', '')
71
72 def int_meta(name):
73 return int_or_none(self._html_search_meta(
74 name, webpage, default=None))
75
76 return {
77 'id': video_id,
78 'display_id': display_id,
79 'url': video_url,
80 'title': title,
81 'description': description,
82 'thumbnail': thumbnail,
83 'creator': creator,
84 'release_date': release_date,
85 'duration': int_meta('video:duration'),
86 'tbr': int_meta('ya:ovs:bitrate'),
87 'width': int_meta('og:video:width'),
88 'height': int_meta('og:video:height'),
89 'http_headers': {
90 'Referer': url,
91 },
92 }