2 from __future__ import unicode_literals
7 from .common import InfoExtractor
15 get_elements_by_class,
20 class EinthusanIE(InfoExtractor):
21 _VALID_URL = r'https?://einthusan\.tv/movie/watch/(?P<id>[0-9]+)'
23 'url': 'https://einthusan.tv/movie/watch/9097/',
24 'md5': 'ff0f7f2065031b8a2cf13a933731c035',
28 'title': 'Ae Dil Hai Mushkil',
29 'description': 'md5:33ef934c82a671a94652a9b4e54d931b',
30 'thumbnail': r're:^https?://.*\.jpg$',
34 # reversed from jsoncrypto.prototype.decrypt() in einthusan-PGMovieWatcher.js
35 def _decrypt(self, encrypted_data, video_id):
36 return self._parse_json(base64.b64decode((
37 encrypted_data[:10] + encrypted_data[-1] + encrypted_data[12:-1]
38 ).encode('ascii')).decode('utf-8'), video_id)
40 def _real_extract(self, url):
41 video_id = self._match_id(url)
43 webpage = self._download_webpage(url, video_id)
45 title = self._html_search_regex(r'<h3>([^<]+)</h3>', webpage, 'title')
47 player_params = extract_attributes(self._search_regex(
48 r'(<section[^>]+id="UIVideoPlayer"[^>]+>)', webpage, 'player parameters'))
50 page_id = self._html_search_regex(
51 '<html[^>]+data-pageid="([^"]+)"', webpage, 'page ID')
52 video_data = self._download_json(
53 'https://einthusan.tv/ajax/movie/watch/%s/' % video_id, video_id,
54 data=urlencode_postdata({
55 'xEvent': 'UIVideoPlayer.PingOutcome',
57 'EJOutcomes': player_params['data-ejpingables'],
62 'gorilla.csrf.Token': page_id,
65 if isinstance(video_data, compat_str) and video_data.startswith('/ratelimited/'):
67 'Download rate reached. Please try again later.', expected=True)
69 ej_links = self._decrypt(video_data['EJLinks'], video_id)
73 m3u8_url = ej_links.get('HLSLink')
75 formats.extend(self._extract_m3u8_formats(
76 m3u8_url, video_id, ext='mp4', entry_protocol='m3u8_native'))
78 mp4_url = ej_links.get('MP4Link')
84 self._sort_formats(formats)
86 description = get_elements_by_class('synopsis', webpage)[0]
87 thumbnail = self._html_search_regex(
88 r'''<img[^>]+src=(["'])(?P<url>(?!\1).+?/moviecovers/(?!\1).+?)\1''',
89 webpage, 'thumbnail url', fatal=False, group='url')
90 if thumbnail is not None:
91 thumbnail = compat_urlparse.urljoin(url, thumbnail)
97 'thumbnail': thumbnail,
98 'description': description,