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