source: titan/mediathek/localhoster/openload.py @ 40134

Last change on this file since 40134 was 40087, checked in by obi, 7 years ago

fix

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