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