1 | |
---|
2 | import os |
---|
3 | import hashlib |
---|
4 | import sys |
---|
5 | from lib.net import Net |
---|
6 | import re |
---|
7 | import lib.ol_gmu as ol_gmu |
---|
8 | import lib.common as common |
---|
9 | |
---|
10 | #OL_SOURCE = 'https://offshoregit.com/tvaresolvers/ol_gmu.py' |
---|
11 | OL_PATH = '' |
---|
12 | |
---|
13 | API_BASE_URL = 'https://api.openload.co/1' |
---|
14 | INFO_URL = API_BASE_URL + '/streaming/info' |
---|
15 | GET_URL = API_BASE_URL + '/streaming/get?file={media_id}' |
---|
16 | #OL_PATH = os.path.join(common.plugins_path, 'ol_gmu.py') |
---|
17 | |
---|
18 | |
---|
19 | class OpenLoadResolver(object): |
---|
20 | name = "openload" |
---|
21 | domains = ["openload.io", "openload.co"] |
---|
22 | pattern = '(?://|\.)(openload\.(?:io|co))/(?:embed|f)/([0-9a-zA-Z-_]+)' |
---|
23 | |
---|
24 | def __init__(self): |
---|
25 | self.net = Net() |
---|
26 | url = str(sys.argv[1]) |
---|
27 | host = self.get_host_and_id(url)[0] |
---|
28 | media_id = self.get_host_and_id(url)[1] |
---|
29 | |
---|
30 | return self.get_media_url(host, media_id) |
---|
31 | |
---|
32 | def get_host_and_id(self, url): |
---|
33 | r = re.search(self.pattern, url, re.I) |
---|
34 | if r: |
---|
35 | return r.groups() |
---|
36 | else: |
---|
37 | return False |
---|
38 | |
---|
39 | def i18n(string_id): |
---|
40 | try: |
---|
41 | return addon.getLocalizedString(strings.STRINGS[string_id]).encode('utf-8', 'ignore') |
---|
42 | except Exception as e: |
---|
43 | # log_utils.log('Failed String Lookup: %s (%s)' % (string_id, e)) |
---|
44 | return string_id |
---|
45 | |
---|
46 | def get_ol_code(self): |
---|
47 | try: |
---|
48 | new_py = self.net.http_GET(OL_SOURCE).content |
---|
49 | # common.log_utils.log('new_py: %s' % (new_pya)) |
---|
50 | |
---|
51 | if new_py: |
---|
52 | with open(OL_PATH, 'w') as f: |
---|
53 | f.write(new_py) |
---|
54 | except Exception as e: |
---|
55 | print 'Exception during openload code retrieve:' |
---|
56 | # common.log_utils.log_warning('Exception during openload code retrieve: %s' % e) |
---|
57 | |
---|
58 | def get_media_url(self, host, media_id): |
---|
59 | video_url = "" |
---|
60 | try: |
---|
61 | self._auto_update(self.get_setting('url'), OL_PATH, self.get_setting('key')) |
---|
62 | reload(ol_gmu) |
---|
63 | return ol_gmu.get_media_url(self.get_url(host, media_id)) # @UndefinedVariable |
---|
64 | except Exception as e: |
---|
65 | # common.log_utils.log_debug('Exception during openload resolve parse: %s' % (e)) |
---|
66 | try: |
---|
67 | video_url = self.__check_auth(media_id) |
---|
68 | if not video_url: |
---|
69 | video_url = self.__auth_ip(media_id) |
---|
70 | #except ResolverError: |
---|
71 | except Exception as e: |
---|
72 | print "raise" |
---|
73 | # raise |
---|
74 | |
---|
75 | if video_url: |
---|
76 | print video_url |
---|
77 | |
---|
78 | def get_url(self, host, media_id): |
---|
79 | return 'http://openload.co/embed/%s' % (media_id) |
---|
80 | |
---|
81 | def __auth_ip(self, media_id): |
---|
82 | js_data = self.__get_json(INFO_URL) |
---|
83 | pair_url = js_data.get('result', {}).get('auth_url', '') |
---|
84 | if pair_url: |
---|
85 | pair_url = pair_url.replace('\/', '/') |
---|
86 | header = i18n('ol_auth_header') |
---|
87 | line1 = i18n('auth_required') |
---|
88 | line2 = i18n('visit_link') |
---|
89 | line3 = i18n('click_pair') % (pair_url) |
---|
90 | with common.kodi.CountdownDialog(header, line1, line2, line3) as cd: |
---|
91 | return cd.start(self.__check_auth, [media_id]) |
---|
92 | |
---|
93 | def __check_auth(self, media_id): |
---|
94 | try: |
---|
95 | js_data = self.__get_json(GET_URL.format(media_id=media_id)) |
---|
96 | # except ResolverError as e: |
---|
97 | except Exception as e: |
---|
98 | status, msg = e |
---|
99 | if status == 403: |
---|
100 | return |
---|
101 | # else: |
---|
102 | # raise ResolverError(msg) |
---|
103 | |
---|
104 | return js_data.get('result', {}).get('url') |
---|
105 | |
---|
106 | def __get_json(self, url): |
---|
107 | result = self.net.http_GET(url).content |
---|
108 | js_result = json.loads(result) |
---|
109 | # common.log_utils.log_debug(js_result) |
---|
110 | # if js_result['status'] != 200: |
---|
111 | # raise ResolverError(js_result['status'], js_result['msg']) |
---|
112 | return js_result |
---|
113 | |
---|
114 | |
---|
115 | sys.stdout = OpenLoadResolver() |
---|