[ie/youtube] Fix `uploader_id` extraction (#11818)
[yt-dlp.git] / yt_dlp / extractor / shemaroome.py
blob3ab322f67d6df8a5d144f9ea99dd1f6242f4f534
1 import base64
3 from .common import InfoExtractor
4 from ..aes import aes_cbc_decrypt_bytes, unpad_pkcs7
5 from ..utils import (
6 ExtractorError,
7 unified_strdate,
11 class ShemarooMeIE(InfoExtractor):
12 _VALID_URL = r'https?://(?:www\.)?shemaroome\.com/(?:movies|shows)/(?P<id>[^?#]+)'
13 _TESTS = [{
14 'url': 'https://www.shemaroome.com/movies/dil-hai-tumhaara',
15 'info_dict': {
16 'id': 'dil-hai-tumhaara',
17 'ext': 'mp4',
18 'title': 'Dil Hai Tumhaara',
19 'release_date': '20020906',
20 'thumbnail': r're:^https?://.*\.jpg$',
21 'description': 'md5:2782c4127807103cf5a6ae2ca33645ce',
23 'params': {
24 'skip_download': True,
26 }, {
27 'url': 'https://www.shemaroome.com/shows/jurm-aur-jazbaat/laalach',
28 'info_dict': {
29 'id': 'jurm-aur-jazbaat_laalach',
30 'ext': 'mp4',
31 'title': 'Laalach',
32 'description': 'md5:92b79c2dcb539b0ab53f9fa5a048f53c',
33 'thumbnail': r're:^https?://.*\.jpg$',
34 'release_date': '20210507',
36 'params': {
37 'skip_download': True,
39 'skip': 'Premium videos cannot be downloaded yet.',
40 }, {
41 'url': 'https://www.shemaroome.com/shows/jai-jai-jai-bajrang-bali/jai-jai-jai-bajrang-bali-episode-99',
42 'info_dict': {
43 'id': 'jai-jai-jai-bajrang-bali_jai-jai-jai-bajrang-bali-episode-99',
44 'ext': 'mp4',
45 'title': 'Jai Jai Jai Bajrang Bali Episode 99',
46 'description': 'md5:850d127a18ee3f9529d7fbde2f49910d',
47 'thumbnail': r're:^https?://.*\.jpg$',
48 'release_date': '20110101',
50 'params': {
51 'skip_download': True,
55 def _real_extract(self, url):
56 video_id = self._match_id(url).replace('/', '_')
57 webpage = self._download_webpage(url, video_id)
58 title = self._search_regex(r'id=\"ma_title\" value=\"([^\"]+)', webpage, 'title')
59 thumbnail = self._og_search_thumbnail(webpage)
60 content_def = self._search_regex(r'id=\"content_definition\" value=\"([^\"]+)', webpage, 'content_def')
61 catalog_id = self._search_regex(r'id=\"catalog_id\" value=\"([^\"]+)', webpage, 'catalog_id')
62 item_category = self._search_regex(r'id=\"item_category\" value=\"([^\"]+)', webpage, 'item_category')
63 content_id = self._search_regex(r'id=\"content_id\" value=\"([^\"]+)', webpage, 'content_id')
65 data = f'catalog_id={catalog_id}&content_id={content_id}&category={item_category}&content_def={content_def}'
66 data_json = self._download_json('https://www.shemaroome.com/users/user_all_lists', video_id, data=data.encode())
67 if not data_json.get('status'):
68 raise ExtractorError('Premium videos cannot be downloaded yet.', expected=True)
69 url_data = base64.b64decode(data_json['new_play_url'])
70 key = base64.b64decode(data_json['key'])
71 iv = bytes(16)
72 m3u8_url = unpad_pkcs7(aes_cbc_decrypt_bytes(url_data, key, iv)).decode('ascii')
73 headers = {'stream_key': data_json['stream_key']}
74 formats, m3u8_subs = self._extract_m3u8_formats_and_subtitles(m3u8_url, video_id, fatal=False, headers=headers)
75 for fmt in formats:
76 fmt['http_headers'] = headers
78 release_date = self._html_search_regex(
79 (r'itemprop="uploadDate">\s*([\d-]+)', r'id="release_date" value="([\d-]+)'),
80 webpage, 'release date', fatal=False)
82 subtitles = {}
83 sub_url = data_json.get('subtitle')
84 if sub_url:
85 subtitles.setdefault('EN', []).append({
86 'url': self._proto_relative_url(sub_url),
88 subtitles = self._merge_subtitles(subtitles, m3u8_subs)
89 description = self._html_search_regex(r'(?s)>Synopsis(</.+?)</', webpage, 'description', fatal=False)
91 return {
92 'id': video_id,
93 'formats': formats,
94 'title': title,
95 'thumbnail': thumbnail,
96 'release_date': unified_strdate(release_date),
97 'description': description,
98 'subtitles': subtitles,