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

Last change on this file since 39027 was 38996, checked in by obi, 8 years ago

[tithek] add local python hoster openload / allmyvideos / nosvideo / vidup

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