]> jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/shemaroome.py
[ie/matchtv] Fix extractor (#10190)
[yt-dlp.git] / yt_dlp / extractor / shemaroome.py
1 import base64
2
3 from .common import InfoExtractor
4 from ..aes import aes_cbc_decrypt, unpad_pkcs7
5 from ..utils import (
6 ExtractorError,
7 bytes_to_intlist,
8 intlist_to_bytes,
9 unified_strdate,
10 )
11
12
13 class ShemarooMeIE(InfoExtractor):
14 _VALID_URL = r'https?://(?:www\.)?shemaroome\.com/(?:movies|shows)/(?P<id>[^?#]+)'
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',
22 'thumbnail': r're:^https?://.*\.jpg$',
23 'description': 'md5:2782c4127807103cf5a6ae2ca33645ce',
24 },
25 'params': {
26 'skip_download': True,
27 },
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',
35 'thumbnail': r're:^https?://.*\.jpg$',
36 'release_date': '20210507',
37 },
38 'params': {
39 'skip_download': True,
40 },
41 'skip': 'Premium videos cannot be downloaded yet.',
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 },
52 'params': {
53 'skip_download': True,
54 },
55 }]
56
57 def _real_extract(self, url):
58 video_id = self._match_id(url).replace('/', '_')
59 webpage = self._download_webpage(url, video_id)
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)
71 url_data = bytes_to_intlist(base64.b64decode(data_json['new_play_url']))
72 key = bytes_to_intlist(base64.b64decode(data_json['key']))
73 iv = [0] * 16
74 m3u8_url = unpad_pkcs7(intlist_to_bytes(aes_cbc_decrypt(url_data, key, iv))).decode('ascii')
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
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
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 })
90 subtitles = self._merge_subtitles(subtitles, m3u8_subs)
91 description = self._html_search_regex(r'(?s)>Synopsis(</.+?)</', webpage, 'description', fatal=False)
92
93 return {
94 'id': video_id,
95 'formats': formats,
96 'title': title,
97 'thumbnail': thumbnail,
98 'release_date': unified_strdate(release_date),
99 'description': description,
100 'subtitles': subtitles,
101 }