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