def execute(self): url = base64.b64decode( "aHR0cDovL3ZveW8uYmcvYmluL2VzaG9wL3dzL2FwaS9qc29uLnBocD9qc29ucnBjPSVz" ) % self.get_encoded_calls() log(url) try: r = requests.get(url) self.response = r.json() return self.response except: log("Error during execute()", 4) return []
def save(self, path, type="to_string"): if type == "to_string": file_path = os.path.join(path, self.name) else: file_path = os.path.join(path, '.playlist') log("Запазване на плейлистата: %s " % file_path) if os.path.exists(path): with open(file_path, 'w') as f: if type == "to_string": content = self.to_string().encode('utf-8', 'replace') else: content = json.dumps(self.to_json(), ensure_ascii=False) f.write(content)
def __init__(self, attr): self.id = attr[0] self.channel_id = attr[1] self.url = attr[2] self.page_url = attr[3] self.player_url = attr[4] self.disabled = attr[5] == 1 self.comment = attr[6] self.user_agent = False if attr[9] == None else attr[9] if self.url == None: self.url = self.resolve() else: log('Извлечен видео поток %s' % self.url) if self.url != '' and self.user_agent: self.url += '|User-Agent=%s' % self.user_agent
def update(self, url): try: log('Downloading assets from url: %s' % url) self.download(url) log('Assets file downloaded and saved as %s' % self.file) return True except Exception as ex: log(ex, 4) log('Unable to update assets file!', 4) return False
def is_old(self, interval=24): ''' Checks whether the asset file is older than the time interval in hours or that its older than the back_up file (in case of addon updates) ''' try: from datetime import datetime, timedelta if os.path.isfile(self.file): treshold = datetime.now() - timedelta(hours=interval) modified = datetime.fromtimestamp(os.path.getmtime(self.file)) if modified < treshold: #file is more than a day old return True backup_modified = datetime.fromtimestamp( os.path.getmtime(self.backup_file)) if modified < backup_modified: return True return False else: #file does not exist, perhaps first run return True except Exception, er: log(str(er), 4) return True
def update(self, url): try: log('Downloading assets from url: %s' % url) self.download(url) log('Assets file downloaded and saved as %s' % self.file) return None except Exception, er: log('Unable to update assets file!', 4) log_last_exception() return str(er)
def resolve(self): headers = {'User-agent': self.user_agent, 'Referer': self.page_url} res = requests.get(self.player_url, headers=headers) m = re.compile('(//.*\.m3u.*?)[\s\'"]+').findall(res.text) if len(m) == 0: log(res.text) else: if not m[0].startswith("http:") and not m[0].startswith( "https:"): #some links omit the http prefix m[0] = "http:" + m[0] log('Намерени %s съвпадения в %s' % (len(m), self.player_url)) stream = None if len(m) == 0 else m[0] log('Извлечен видео поток %s' % stream) return stream
def get_encoded_calls(self): log(",".join(self.calls)) __calls__ = ",".join(self.calls) __calls__ = "[%s]" % __calls__.replace(', ', ',').replace(': ', ':') return urllib.quote_plus(__calls__)
from xbmc import executebuiltin, Monitor from resources.lib.server import create_server from resources.lib.wsgi_app import * from kodibgcommon.utils import notify_success, log, translate executebuiltin(RUNSCRIPT) monitor = Monitor() httpd = create_server(BIND_IP, app, port=port) httpd.timeout = 0.1 starting = True while not monitor.abortRequested(): httpd.handle_request() if starting: notify_success(translate(32006) % port) starting = False httpd.socket.close() settings.first_request = False log(translate(32003))
def extract(self, compressed_file): log("Extracting file %s" % compressed_file) with gzip.GzipFile(self.file, 'rb') as gz, open(self.file, 'wb') as out_file: out_file.write(gz.read()) log("Extracted file saved to %s" % self.file)