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