2 from __future__ import unicode_literals
7 from .common import InfoExtractor
16 get_elements_by_class,
21 class EinthusanIE(InfoExtractor):
22 _VALID_URL = r'https?://(?P<host>einthusan\.(?:tv|com))/movie/watch/(?P<id>[^/?#&]+)'
24 'url': 'https://einthusan.tv/movie/watch/9097/',
25 'md5': 'ff0f7f2065031b8a2cf13a933731c035',
29 'title': 'Ae Dil Hai Mushkil',
30 'description': 'md5:33ef934c82a671a94652a9b4e54d931b',
31 'thumbnail': r're:^https?://.*\.jpg$',
34 'url': 'https://einthusan.tv/movie/watch/51MZ/?lang=hindi',
35 'only_matching': True,
37 'url': 'https://einthusan.com/movie/watch/9097/',
38 'only_matching': True,
41 # reversed from jsoncrypto.prototype.decrypt() in einthusan-PGMovieWatcher.js
42 def _decrypt(self, encrypted_data, video_id):
43 return self._parse_json(compat_b64decode((
44 encrypted_data[:10] + encrypted_data[-1] + encrypted_data[12:-1]
45 )).decode('utf-8'), video_id)
47 def _real_extract(self, url):
48 mobj = re.match(self._VALID_URL, url)
49 host = mobj.group('host')
50 video_id = mobj.group('id')
52 webpage = self._download_webpage(url, video_id)
54 title = self._html_search_regex(r'<h3>([^<]+)</h3>', webpage, 'title')
56 player_params = extract_attributes(self._search_regex(
57 r'(<section[^>]+id="UIVideoPlayer"[^>]+>)', webpage, 'player parameters'))
59 page_id = self._html_search_regex(
60 '<html[^>]+data-pageid="([^"]+)"', webpage, 'page ID')
61 video_data = self._download_json(
62 'https://%s/ajax/movie/watch/%s/' % (host, video_id), video_id,
63 data=urlencode_postdata({
64 'xEvent': 'UIVideoPlayer.PingOutcome',
66 'EJOutcomes': player_params['data-ejpingables'],
71 'gorilla.csrf.Token': page_id,
74 if isinstance(video_data, compat_str) and video_data.startswith('/ratelimited/'):
76 'Download rate reached. Please try again later.', expected=True)
78 ej_links = self._decrypt(video_data['EJLinks'], video_id)
82 m3u8_url = ej_links.get('HLSLink')
84 formats.extend(self._extract_m3u8_formats(
85 m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native'))
87 mp4_url = ej_links.get('MP4Link')
93 self._sort_formats(formats)
95 description = get_elements_by_class('synopsis', webpage)[0]
96 thumbnail = self._html_search_regex(
97 r'''<img[^>]+src=(["'])(?P<url>(?!\1).+?/moviecovers/(?!\1).+?)\1''',
98 webpage, 'thumbnail url', fatal=False, group='url')
99 if thumbnail is not None:
100 thumbnail = compat_urlparse.urljoin(url, thumbnail)
106 'thumbnail': thumbnail,
107 'description': description,