]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/einthusan.py
[extractor] Deprecate `_sort_formats`
[yt-dlp.git] / yt_dlp / extractor / einthusan.py
CommitLineData
f8514630
YCH
1import json
2
98703c7f 3from .common import InfoExtractor
f8514630 4from ..compat import (
cf282071 5 compat_b64decode,
f8514630 6 compat_str,
cf282071 7 compat_urlparse,
f8514630 8)
b26afec8 9from ..utils import (
f8514630
YCH
10 extract_attributes,
11 ExtractorError,
12 get_elements_by_class,
13 urlencode_postdata,
b26afec8 14)
98703c7f
HP
15
16
17class EinthusanIE(InfoExtractor):
393cc31d 18 _VALID_URL = r'https?://(?P<host>einthusan\.(?:tv|com|ca))/movie/watch/(?P<id>[^/?#&]+)'
4cead6a6 19 _TESTS = [{
f8514630
YCH
20 'url': 'https://einthusan.tv/movie/watch/9097/',
21 'md5': 'ff0f7f2065031b8a2cf13a933731c035',
22 'info_dict': {
23 'id': '9097',
24 'ext': 'mp4',
25 'title': 'Ae Dil Hai Mushkil',
26 'description': 'md5:33ef934c82a671a94652a9b4e54d931b',
27 'thumbnail': r're:^https?://.*\.jpg$',
28 }
4cead6a6
S
29 }, {
30 'url': 'https://einthusan.tv/movie/watch/51MZ/?lang=hindi',
31 'only_matching': True,
f2a213d0 32 }, {
33 'url': 'https://einthusan.com/movie/watch/9097/',
34 'only_matching': True,
393cc31d 35 }, {
36 'url': 'https://einthusan.ca/movie/watch/4E9n/?lang=hindi',
37 'only_matching': True,
4cead6a6 38 }]
f8514630
YCH
39
40 # reversed from jsoncrypto.prototype.decrypt() in einthusan-PGMovieWatcher.js
41 def _decrypt(self, encrypted_data, video_id):
cf282071 42 return self._parse_json(compat_b64decode((
f8514630 43 encrypted_data[:10] + encrypted_data[-1] + encrypted_data[12:-1]
cf282071 44 )).decode('utf-8'), video_id)
98703c7f
HP
45
46 def _real_extract(self, url):
5ad28e7f 47 mobj = self._match_valid_url(url)
f2a213d0 48 host = mobj.group('host')
49 video_id = mobj.group('id')
b26afec8 50
f8514630
YCH
51 webpage = self._download_webpage(url, video_id)
52
53 title = self._html_search_regex(r'<h3>([^<]+)</h3>', webpage, 'title')
54
55 player_params = extract_attributes(self._search_regex(
56 r'(<section[^>]+id="UIVideoPlayer"[^>]+>)', webpage, 'player parameters'))
57
58 page_id = self._html_search_regex(
59 '<html[^>]+data-pageid="([^"]+)"', webpage, 'page ID')
60 video_data = self._download_json(
f2a213d0 61 'https://%s/ajax/movie/watch/%s/' % (host, video_id), video_id,
f8514630
YCH
62 data=urlencode_postdata({
63 'xEvent': 'UIVideoPlayer.PingOutcome',
64 'xJson': json.dumps({
65 'EJOutcomes': player_params['data-ejpingables'],
66 'NativeHLS': False
67 }),
68 'arcVersion': 3,
69 'appVersion': 59,
70 'gorilla.csrf.Token': page_id,
71 }))['Data']
72
73 if isinstance(video_data, compat_str) and video_data.startswith('/ratelimited/'):
74 raise ExtractorError(
75 'Download rate reached. Please try again later.', expected=True)
76
77 ej_links = self._decrypt(video_data['EJLinks'], video_id)
78
79 formats = []
98703c7f 80
f8514630
YCH
81 m3u8_url = ej_links.get('HLSLink')
82 if m3u8_url:
83 formats.extend(self._extract_m3u8_formats(
84 m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native'))
98703c7f 85
f8514630
YCH
86 mp4_url = ej_links.get('MP4Link')
87 if mp4_url:
88 formats.append({
89 'url': mp4_url,
90 })
0416006a 91
f8514630 92 description = get_elements_by_class('synopsis', webpage)[0]
e2037b3f 93 thumbnail = self._html_search_regex(
f8514630
YCH
94 r'''<img[^>]+src=(["'])(?P<url>(?!\1).+?/moviecovers/(?!\1).+?)\1''',
95 webpage, 'thumbnail url', fatal=False, group='url')
e2037b3f 96 if thumbnail is not None:
f8514630 97 thumbnail = compat_urlparse.urljoin(url, thumbnail)
98703c7f
HP
98
99 return {
100 'id': video_id,
b26afec8 101 'title': title,
d75d9e34 102 'formats': formats,
e2037b3f
PH
103 'thumbnail': thumbnail,
104 'description': description,
98703c7f 105 }