1 | |
---|
2 | import os |
---|
3 | import hashlib |
---|
4 | import sys |
---|
5 | from lib.net import Net |
---|
6 | import ol_gmu |
---|
7 | |
---|
8 | OL_SOURCE = 'https://offshoregit.com/tvaresolvers/ol_gmu.py' |
---|
9 | OL_PATH = ''#os.path.join(common.plugins_path, 'ol_gmu.py') |
---|
10 | |
---|
11 | class OpenLoadResolver(object): |
---|
12 | name = "openload" |
---|
13 | domains = ["openload.io", "openload.co"] |
---|
14 | pattern = '(?://|\.)(openload\.(?:io|co))/(?:embed|f)/([0-9a-zA-Z-_]+)' |
---|
15 | |
---|
16 | def __init__(self): |
---|
17 | self.net = Net() |
---|
18 | url = str(sys.argv[1]) |
---|
19 | host = self.get_host_and_id(url)[0] |
---|
20 | media_id = self.get_host_and_id(url)[1] |
---|
21 | |
---|
22 | return self.get_media_url(host, media_id) |
---|
23 | |
---|
24 | @common.cache.cache_method(cache_limit=8) |
---|
25 | def get_ol_code(self): |
---|
26 | try: |
---|
27 | new_py = self.net.http_GET(OL_SOURCE).content |
---|
28 | # common.log_utils.log('new_py: %s' % (new_pya)) |
---|
29 | |
---|
30 | if new_py: |
---|
31 | with open(OL_PATH, 'w') as f: |
---|
32 | f.write(new_py) |
---|
33 | except Exception as e: |
---|
34 | common.log_utils.log_warning('Exception during openload code retrieve: %s' % e) |
---|
35 | |
---|
36 | def get_media_url(self, host, media_id): |
---|
37 | # common.log_utils.log('host: %s' % (host)) |
---|
38 | # common.log_utils.log('media_id: %s' % (media_id)) |
---|
39 | # common.log_utils.log('OL_PATH: %s' % (OL_PATH)) |
---|
40 | try: |
---|
41 | # if self.get_setting('auto_update') == 'true': |
---|
42 | # self.get_ol_code() |
---|
43 | # with open(OL_PATH, 'r') as f: |
---|
44 | # py_data = f.read() |
---|
45 | # common.log_utils.log('py_data: %s' % (py_data)) |
---|
46 | # common.log_utils.log('ol_gmu hash: %s' % (hashlib.md5(py_data).hexdigest())) |
---|
47 | # import ol_gmu |
---|
48 | web_url = self.get_url(host, media_id) |
---|
49 | # common.log_utils.log('web_url: %s' % (web_url)) |
---|
50 | return ol_gmu.get_media_url(web_url) |
---|
51 | except Exception as e: |
---|
52 | # common.log_utils.log_debug('Exception during openload resolve parse: %s' % e) |
---|
53 | raise |
---|
54 | |
---|
55 | def get_url(self, host, media_id): |
---|
56 | return 'http://openload.io/embed/%s' % media_id |
---|
57 | |
---|
58 | def get_settings_xml(cls): |
---|
59 | xml = super(cls, cls).get_settings_xml() |
---|
60 | xml.append('<setting id="%s_auto_update" type="bool" label="Automatically update resolver" default="true"/>' % (cls.__name__)) |
---|
61 | return xml |
---|