[38996] | 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 |
---|
[39608] | 8 | import lib.common as common |
---|
[38996] | 9 | |
---|
[39608] | 10 | #OL_SOURCE = 'https://offshoregit.com/tvaresolvers/ol_gmu.py' |
---|
[38996] | 11 | OL_PATH = '' |
---|
| 12 | |
---|
[39608] | 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 | |
---|
[38996] | 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 | |
---|
[39608] | 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 | |
---|
[38996] | 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: |
---|
[39608] | 55 | print 'Exception during openload code retrieve:' |
---|
| 56 | # common.log_utils.log_warning('Exception during openload code retrieve: %s' % e) |
---|
[38996] | 57 | |
---|
| 58 | def get_media_url(self, host, media_id): |
---|
[39608] | 59 | video_url = "" |
---|
[38996] | 60 | try: |
---|
[39608] | 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 |
---|
[38996] | 64 | except Exception as e: |
---|
[39608] | 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 |
---|
[38996] | 77 | |
---|
| 78 | def get_url(self, host, media_id): |
---|
[39608] | 79 | return 'http://openload.co/embed/%s' % (media_id) |
---|
[38996] | 80 | |
---|
[39608] | 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 |
---|
[38996] | 113 | |
---|
[39608] | 114 | |
---|
[38996] | 115 | sys.stdout = OpenLoadResolver() |
---|