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