[ie/wistia] Support password-protected videos (#11100)
[yt-dlp3.git] / yt_dlp / extractor / popcorntimes.py
blobcfece86ee7187906be94af19bde66784823a1ec3
1 import base64
3 from .common import InfoExtractor
4 from ..utils import int_or_none
7 class 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,
28 def _real_extract(self, url):
29 mobj = self._match_valid_url(url)
30 video_id, display_id = mobj.group('id', 'display_id')
32 webpage = self._download_webpage(url, display_id)
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)
39 loc = self._search_regex(
40 r'PCTMLOC\s*=\s*(["\'])(?P<value>(?:(?!\1).)+)\1', webpage, 'loc',
41 group='value')
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
51 loc_b64 += chr(c_ord)
53 video_url = base64.b64decode(loc_b64).decode('utf-8')
55 description = self._html_search_regex(
56 r'(?s)<div[^>]+class=["\']pt-movie-desc[^>]+>(.+?)</div>', webpage,
57 'description', fatal=False)
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)
64 creator = self._html_search_meta(
65 'video:director', webpage, 'creator', default=None)
67 release_date = self._html_search_meta(
68 'video:release_date', webpage, default=None)
69 if release_date:
70 release_date = release_date.replace('-', '')
72 def int_meta(name):
73 return int_or_none(self._html_search_meta(
74 name, webpage, default=None))
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,