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