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