def auto_clean(): service = False days = [tools.get_date(), tools.get_date(days=1), tools.get_date(days=3), tools.get_date(days=7), tools.get_date(days=30)] freq = int(float(CONFIG.AUTOFREQ)) if CONFIG.AUTONEXTRUN <= str(tools.get_date()) or freq == 0: service = True next_run = days[freq] CONFIG.set_setting('nextautocleanup', str(next_run)) else: logging.log("[Auto Clean Up] Next Clean Up {0}".format(CONFIG.AUTONEXTRUN), level=xbmc.LOGNOTICE) if service: if CONFIG.AUTOCACHE == 'true': logging.log('[Auto Clean Up] Cache: On', level=xbmc.LOGNOTICE) clear.clear_cache(True) else: logging.log('[Auto Clean Up] Cache: Off', level=xbmc.LOGNOTICE) if CONFIG.AUTOTHUMBS == 'true': logging.log('[Auto Clean Up] Old Thumbs: On', level=xbmc.LOGNOTICE) clear.old_thumbs() else: logging.log('[Auto Clean Up] Old Thumbs: Off', level=xbmc.LOGNOTICE) if CONFIG.AUTOPACKAGES == 'true': logging.log('[Auto Clean Up] Packages: On', level=xbmc.LOGNOTICE) clear.clear_packages_startup() else: logging.log('[Auto Clean Up] Packages: Off', level=xbmc.LOGNOTICE)
def auto_clean(): service = False days = [tools.get_date(formatted=True), tools.get_date(days=1, formatted=True), tools.get_date(days=3, formatted=True), tools.get_date(days=7, formatted=True), tools.get_date(days=30, formatted=True)] freq = int(CONFIG.AUTOFREQ) next_cleanup = time.mktime(time.strptime(CONFIG.NEXTCLEANDATE, "%Y-%m-%d %H:%M:%S")) if next_cleanup <= tools.get_date() or freq == 0: service = True next_run = days[freq] CONFIG.set_setting('nextautocleanup', next_run) else: logging.log("[Auto Clean Up] Next Clean Up {0}".format(CONFIG.NEXTCLEANDATE), level=xbmc.LOGINFO) if service: if CONFIG.AUTOCACHE == 'true': logging.log('[Auto Clean Up] Cache: On', level=xbmc.LOGINFO) clear.clear_cache(True) else: logging.log('[Auto Clean Up] Cache: Off', level=xbmc.LOGINFO) if CONFIG.AUTOTHUMBS == 'true': logging.log('[Auto Clean Up] Old Thumbs: On', level=xbmc.LOGINFO) clear.old_thumbs() else: logging.log('[Auto Clean Up] Old Thumbs: Off', level=xbmc.LOGINFO) if CONFIG.AUTOPACKAGES == 'true': logging.log('[Auto Clean Up] Packages: On', level=xbmc.LOGINFO) clear.clear_packages_startup() else: logging.log('[Auto Clean Up] Packages: Off', level=xbmc.LOGINFO)
def log(msg, level=xbmc.LOGNOTICE): from resources.libs.common import tools if not os.path.exists(CONFIG.PLUGIN_DATA): os.makedirs(CONFIG.PLUGIN_DATA) if not os.path.exists(CONFIG.WIZLOG): f = open(CONFIG.WIZLOG, 'w+') f.close() if CONFIG.WIZDEBUGGING == 'false': return False if CONFIG.DEBUGLEVEL == '0': # No Logging return False if CONFIG.DEBUGLEVEL == '1': # Normal Logging if level not in [xbmc.LOGNOTICE, xbmc.LOGERROR, xbmc.LOGSEVERE, xbmc.LOGFATAL]: return False if CONFIG.DEBUGLEVEL == '2': # Full Logging level = xbmc.LOGNOTICE try: xbmc.log('{0}: {1}'.format(CONFIG.ADDONTITLE, msg), level) except Exception as e: try: xbmc.log('Logging Failure: {0}'.format(e), level) except: pass if CONFIG.ENABLEWIZLOG == 'true': lastcheck = CONFIG.NEXTCLEANDATE if not CONFIG.NEXTCLEANDATE == '' else str(tools.get_date()) if CONFIG.CLEANWIZLOG == 'true' and lastcheck <= str(tools.get_date()): check_log() line = "[{0} {1}] {2}".format(tools.get_date(now=True).date(), str(tools.get_date(now=True).time())[:8], msg) line = line.rstrip('\r\n') + '\n' tools.write_to_file(CONFIG.WIZLOG, line, mode='a')
def check_log(): from resources.libs.common import tools next = tools.get_date(days=1) lines = tools.read_from_file(CONFIG.WIZLOG).split('\n') if CONFIG.CLEANWIZLOGBY == '0': # By Days keep = tools.get_date(days=-CONFIG.MAXWIZDATES[int(float(CONFIG.CLEANDAYS))]) x = 0 for line in lines: if str(line[1:11]) >= str(keep): break x += 1 newfile = lines[x:] tools.write_to_file(CONFIG.WIZLOG, '\n'.join(newfile)) elif CONFIG.CLEANWIZLOGBY == '1': # By Size maxsize = CONFIG.MAXWIZSIZE[int(float(CONFIG.CLEANSIZE))]*1024 if os.path.getsize(CONFIG.WIZLOG) >= maxsize: start = len(lines)/2 newfile = lines[start:] tools.write_to_file(CONFIG.WIZLOG, '\n'.join(newfile)) elif CONFIG.CLEANWIZLOGBY == '2': # By Lines maxlines = CONFIG.MAXWIZLINES[int(float(CONFIG.CLEANLINES))] if len(lines) > maxlines: start = len(lines) - int(maxlines/2) newfile = lines[start:] tools.write_to_file(CONFIG.WIZLOG, '\n'.join(newfile)) CONFIG.set_setting('nextcleandate', str(next))
def log(msg, level=xbmc.LOGNOTICE): if not os.path.exists(CONFIG.PLUGIN_DATA): os.makedirs(CONFIG.PLUGIN_DATA) if not os.path.exists(CONFIG.WIZLOG): f = open(CONFIG.WIZLOG, 'w+') f.close() if CONFIG.WIZDEBUGGING == 'false': return False if CONFIG.DEBUGLEVEL == '0': # No Logging return False if CONFIG.DEBUGLEVEL == '1': # Normal Logging if level not in [xbmc.LOGNOTICE, xbmc.LOGERROR, xbmc.LOGSEVERE, xbmc.LOGFATAL]: return False if CONFIG.DEBUGLEVEL == '2': # Full Logging level = xbmc.LOGNOTICE try: xbmc.log('{0}: {1}'.format(CONFIG.ADDONTITLE, msg), level) except Exception as e: try: xbmc.log('Logging Failure: {0}'.format(e), level) except: pass if CONFIG.ENABLEWIZLOG == 'true': import time lastcheck = CONFIG.NEXTCLEANDATE if not CONFIG.NEXTCLEANDATE == 0 else tools.get_date() if CONFIG.CLEANWIZLOG == 'true' and time.mktime(time.strptime(lastcheck, "%Y-%m-%d %H:%M:%S")) <= tools.get_date(): check_log() line = "[{0}] {1}".format(tools.get_date(formatted=True), msg) line = line.rstrip('\r\n') + '\n' tools.write_to_file(CONFIG.WIZLOG, line, mode='a')
def save_login(): if CONFIG.LOGINSAVE <= str(tools.get_date()): from resources.libs import loginit logging.log("[Login Info] Saving all Data", level=xbmc.LOGNOTICE) loginit.auto_update('all') CONFIG.set_setting('loginlastsave', str(tools.get_date(days=3))) else: logging.log("[Login Info] Next Auto Save isn't until: {0} / TODAY is: {1}".format(CONFIG.LOGINSAVE, str( tools.get_date())), level=xbmc.LOGNOTICE)
def save_debrid(): if CONFIG.DEBRIDSAVE <= str(tools.get_date()): from resources.libs import debridit logging.log("[Debrid Data] Saving all Data", level=xbmc.LOGNOTICE) debridit.auto_update('all') CONFIG.set_setting('debridlastsave', str(tools.get_date(days=3))) else: logging.log("[Debrid Data] Next Auto Save isn't until: {0} / TODAY is: {1}".format(CONFIG.DEBRIDSAVE, str( tools.get_date())), level=xbmc.LOGNOTICE)
def save_trakt(): if CONFIG.TRAKTSAVE <= str(tools.get_date()): from resources.libs import traktit logging.log("[Trakt Data] Saving all Data", level=xbmc.LOGNOTICE) traktit.auto_update('all') CONFIG.set_setting('traktlastsave', str(tools.get_date(days=3))) else: logging.log("[Trakt Data] Next Auto Save isn't until: {0} / TODAY is: {1}".format(CONFIG.TRAKTSAVE, str( tools.get_date())), level=xbmc.LOGNOTICE)
def save_login(): current_time = time.mktime(time.strptime(tools.get_date(formatted=True), "%Y-%m-%d %H:%M:%S")) next_save = time.mktime(time.strptime(CONFIG.get_setting('loginnextsave'), "%Y-%m-%d %H:%M:%S")) if next_save <= current_time: from resources.libs import loginit logging.log("[Login Info] Saving all Data", level=xbmc.LOGINFO) loginit.auto_update('all') CONFIG.set_setting('loginnextsave', tools.get_date(days=3, formatted=True)) else: logging.log("[Login Info] Next Auto Save isn't until: {0} / TODAY is: {1}".format(CONFIG.get_setting('loginnextsave'), tools.get_date(formatted=True)), level=xbmc.LOGINFO)
def do_ignore(self): logging.log("[Current Build Check] [User Selected: Ignore Build Menu] [Next Check: {0}]".format(CONFIG.BUILDCHECK), level=xbmc.LOGINFO) CONFIG.set_setting('nextbuildcheck', tools.get_date(days=CONFIG.UPDATECHECK, formatted=True)) CONFIG.set_setting('installed', 'ignored') self.close()
def login_it(do, who): if not os.path.exists(CONFIG.ADDON_DATA): os.makedirs(CONFIG.ADDON_DATA) if not os.path.exists(CONFIG.LOGINFOLD): os.makedirs(CONFIG.LOGINFOLD) if who == 'all': for log in ORDER: if os.path.exists(LOGINID[log]['path']): try: addonid = tools.get_addon_by_id(LOGINID[log]['plugin']) default = LOGINID[log]['default'] user = addonid.getSetting(default) update_login(do, log) except: pass else: logging.log('[Login Info] {0}({1}) is not installed'.format(LOGINID[log]['name'], LOGINID[log]['plugin']), level=xbmc.LOGERROR) CONFIG.set_setting('loginlastsave', tools.get_date(days=3)) else: if LOGINID[who]: if os.path.exists(LOGINID[who]['path']): update_login(do, who) else: logging.log('[Login Info] Invalid Entry: {0}'.format(who), level=xbmc.LOGERROR)
def debrid_it(do, who): if not os.path.exists(CONFIG.ADDON_DATA): os.makedirs(CONFIG.ADDON_DATA) if not os.path.exists(CONFIG.DEBRIDFOLD): os.makedirs(CONFIG.DEBRIDFOLD) if who == 'all': for log in ORDER: if os.path.exists(DEBRIDID[log]['path']): try: addonid = tools.get_addon_by_id(DEBRIDID[log]['plugin']) default = DEBRIDID[log]['default'] user = addonid.getSetting(default) update_debrid(do, log) except: pass else: logging.log('[Debrid Info] {0}({1}) is not installed'.format( DEBRIDID[log]['name'], DEBRIDID[log]['plugin']), level=xbmc.LOGERROR) CONFIG.set_setting('debridnextsave', tools.get_date(days=3, formatted=True)) else: if DEBRIDID[who]: if os.path.exists(DEBRIDID[who]['path']): update_debrid(do, who) else: logging.log('[Debrid Info] Invalid Entry: {0}'.format(who), level=xbmc.LOGERROR)
def do_ignore(self): from resources.libs.common import logging from resources.libs.common import tools logging.log("[Check Updates] [Installed Version: {0}] [Current Version: {1}] [User Selected: Ignore {2} Days]".format(CONFIG.BUILDVERSION, CONFIG.BUILDLATEST, CONFIG.UPDATECHECK)) logging.log("[Check Updates] [Next Check: {0}]".format(str(tools.get_date(days=CONFIG.UPDATECHECK)))) self.close()
def old_thumbs(): from resources.libs import db from resources.libs.common import tools dbfile = os.path.join(CONFIG.DATABASE, db.latest_db('Textures')) use = 30 week = tools.get_date(days=-7) ids = [] images = [] size = 0 if os.path.exists(dbfile): try: textdb = database.connect(dbfile, isolation_level=None) textexe = textdb.cursor() except Exception as e: logging.log("DB Connection Error: {0}".format(str(e)), level=xbmc.LOGERROR) return False else: logging.log('{0} not found.'.format(dbfile), level=xbmc.LOGERROR) return False textexe.execute( "SELECT idtexture FROM sizes WHERE usecount < ? AND lastusetime < ?", (use, str(week))) found = textexe.fetchall() for rows in found: idfound = rows[0] ids.append(idfound) textexe.execute("SELECT cachedurl FROM texture WHERE id = ?", (idfound, )) found2 = textexe.fetchall() for rows2 in found2: images.append(rows2[0]) logging.log("{0} total thumbs cleaned up.".format(str(len(images))), level=xbmc.LOGNOTICE) for id in ids: textexe.execute("DELETE FROM sizes WHERE idtexture = ?", (id, )) textexe.execute("DELETE FROM texture WHERE id = ?", (id, )) textexe.execute("VACUUM") textdb.commit() textexe.close() for image in images: path = os.path.join(CONFIG.THUMBNAILS, image) try: imagesize = os.path.getsize(path) os.remove(path) size += imagesize except: pass removed = tools.convert_size(size) if len(images) > 0: logging.log_notify( "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, CONFIG.ADDONTITLE), '[COLOR {0}]Clear Thumbs: {1} Files / {2} MB[/COLOR]!'.format( CONFIG.COLOR2, str(len(images)), removed)) else: logging.log_notify( "[COLOR {0}]{1}[/COLOR]".format(CONFIG.COLOR1, CONFIG.ADDONTITLE), '[COLOR {0}]Clear Thumbs: None Found![/COLOR]'.format( CONFIG.COLOR2))
def trakt_it(do, who): if not os.path.exists(CONFIG.ADDON_DATA): os.makedirs(CONFIG.ADDON_DATA) if not os.path.exists(CONFIG.TRAKTFOLD): os.makedirs(CONFIG.TRAKTFOLD) if who == 'all': for log in ORDER: if os.path.exists(TRAKTID[log]['path']): try: addonid = tools.get_addon_by_id(TRAKTID[log]['plugin']) default = TRAKTID[log]['default'] user = addonid.getSetting(default) update_trakt(do, log) except: pass else: logging.log('[Trakt Data] {0}({1}) is not installed'.format( TRAKTID[log]['name'], TRAKTID[log]['plugin']), level=xbmc.LOGERROR) CONFIG.set_setting('traktnextsave', tools.get_date(days=3, formatted=True)) else: if TRAKTID[who]: if os.path.exists(TRAKTID[who]['path']): update_trakt(do, who) else: logging.log('[Trakt Data] Invalid Entry: {0}'.format(who), level=xbmc.LOGERROR)
def do_ignore(self): logging.log("[Verificación Build Actual] [Usuario seleccionado: Ignorar Build Menu] [Siguiente Verificación: {0}]".format(CONFIG.BUILDCHECK), level=xbmc.LOGINFO) CONFIG.set_setting('nextbuildcheck', tools.get_date(days=CONFIG.UPDATECHECK, formatted=True)) CONFIG.set_setting('instalado', 'ignorado') self.close()
def do_ignore(self): logging.log( "[Check Updates] [Installed Version: {0}] [Current Version: {1}] [User Selected: Ignore {2} Days]" .format(CONFIG.BUILDVERSION, CONFIG.BUILDLATEST, CONFIG.UPDATECHECK)) logging.log("[Check Updates] [Next Check: {0}]".format( tools.get_date(days=CONFIG.UPDATECHECK, formatted=True))) self.close()
def save_debrid(): if CONFIG.DEBRIDSAVE <= time.mktime( time.strptime(tools.get_date(formatted=True), "%Y-%m-%d %H:%M:%S")): from resources.libs import debridit logging.log("[Debrid Data] Saving all Data", level=xbmc.LOGNOTICE) debridit.auto_update('all') CONFIG.set_setting('debridnextsave', tools.get_date(days=3, formatted=True)) else: local_time = time.localtime( time.mktime( time.strptime(CONFIG.get_setting('debridnextsave'), "%Y-%m-%d %H:%M:%S"))) logging.log( "[Debrid Data] Next Auto Save isn't until: {0} / TODAY is: {1}". format(local_time, tools.get_date(formatted=True)), level=xbmc.LOGNOTICE)
def do_normal_install(self): from resources.libs.common import logging from resources.libs.common import tools logging.log("[Check Updates] [Installed Version: {0}] [Current Version: {1}] [User Selected: Normal Install build]".format(CONFIG.BUILDVERSION, CONFIG.BUILDLATEST)) logging.log("[Check Updates] [Next Check: {0}]".format(str(tools.get_date(days=CONFIG.UPDATECHECK)))) url = 'plugin://{0}/?mode=install&name={1}&url=normal'.format(CONFIG.ADDON_ID, quote_plus(CONFIG.BUILDNAME)) xbmc.executebuiltin('RunPlugin({0})'.format(url)) self.close()
def do_ignore(self): logging.log( "[Verificar atualizações] [Versão Instalada: {0}] [Versão Atual: {1}] [Selecionado pelo usuário: Ignore {2} Dias]" .format(CONFIG.BUILDVERSION, CONFIG.BUILDLATEST, CONFIG.UPDATECHECK)) logging.log("[Verificar atualizações] [Next Check: {0}]".format( tools.get_date(days=CONFIG.UPDATECHECK, formatted=True))) self.close() if 88 - 88: iIii1I11I1II1 - ooOoO0o + OOooOOo
def save_trakt(): current_time = time.mktime( time.strptime(tools.get_date(formatted=True), "%Y-%m-%d %H:%M:%S")) next_save = time.mktime( time.strptime(CONFIG.get_setting('traktnextsave'), "%Y-%m-%d %H:%M:%S")) if next_save <= current_time: from resources.libs import traktit logging.log("[Trakt Data] Guardar todos los datos", level=xbmc.LOGINFO) traktit.auto_update('all') CONFIG.set_setting('traktnextsave', tools.get_date(days=3, formatted=True)) else: logging.log( "[Trakt Data] Next Auto Save isn't until: {0} / TODAY is: {1}". format(CONFIG.get_setting('traktnextsave'), tools.get_date(formatted=True)), level=xbmc.LOGINFO)
def do_ignore(self): from resources.libs.common import logging from resources.libs.common import tools logging.log("[Current Build Check] [User Selected: Ignore Build Menu] [Next Check: {0}]".format(CONFIG.BUILDCHECK), level=xbmc.LOGNOTICE) CONFIG.set_setting('nextbuildcheck', tools.get_date(days=CONFIG.UPDATECHECK, formatted=True)) CONFIG.set_setting('installed', 'ignored') self.close()
def save_login(): current_time = time.mktime( time.strptime(tools.get_date(formatted=True), "%Y-%m-%d %H:%M:%S")) next_save = time.mktime( time.strptime(CONFIG.get_setting('loginnextsave'), "%Y-%m-%d %H:%M:%S")) if next_save <= current_time: from resources.libs import loginit logging.log("[Login Info] Guardar todos los datos", level=xbmc.LOGINFO) loginit.auto_update('all') CONFIG.set_setting('loginnextsave', tools.get_date(days=3, formatted=True)) else: logging.log( "[Login Info] El siguiente guardado automático no es hasta: {0} / hoy es: {1}" .format(CONFIG.get_setting('loginnextsave'), tools.get_date(formatted=True)), level=xbmc.LOGINFO)
def do_fresh_install(self): logging.log( "[Check Updates] [Installed Version: {0}] [Current Version: {1}] [User Selected: Fresh Install build]" .format(CONFIG.BUILDVERSION, CONFIG.BUILDLATEST)) logging.log("[Check Updates] [Next Check: {0}]".format( tools.get_date(days=CONFIG.UPDATECHECK, formatted=True))) url = 'plugin://{0}/?mode=install&name={1}&action=fresh'.format( CONFIG.ADDON_ID, quote_plus(CONFIG.BUILDNAME)) xbmc.executebuiltin('RunPlugin({0})'.format(url)) self.close()
def do_build_menu(self): logging.log("[Current Build Check] [User Selected: Open Build Menu] [Next Check: {0}]".format(CONFIG.BUILDCHECK), level=xbmc.LOGINFO) CONFIG.set_setting('nextbuildcheck', tools.get_date(days=CONFIG.UPDATECHECK, formatted=True)) CONFIG.set_setting('installed', 'ignored') url = 'plugin://{0}/?mode=builds'.format(CONFIG.ADDON_ID) self.close() xbmc.executebuiltin('ActivateWindow(Programs, {0}, return)'.format(url))
def do_normal_install(self): logging.log( "[Verificar atualizações] [Versão Instalada: {0}] [Versão Atual: {1}] [User Selected: Normal Install build]" .format(CONFIG.BUILDVERSION, CONFIG.BUILDLATEST)) logging.log("[Verificar atualizações] [Next Check: {0}]".format( tools.get_date(days=CONFIG.UPDATECHECK, formatted=True))) oOo = 'plugin://{0}/?mode=install&name={1}&action=normal'.format( CONFIG.ADDON_ID, quote_plus(CONFIG.BUILDNAME)) xbmc.executebuiltin('RunPlugin({0})'.format(oOo)) self.close() if 68 - 68: OOooOOo % I1Ii111
def do_build_menu(self): logging.log("[Verificación Build Actual] [Usuario Seleccionado: Abrir Menu Build] [Siguiente Verificación: {0}]".format(CONFIG.BUILDCHECK), level=xbmc.LOGINFO) CONFIG.set_setting('nextbuildcheck', tools.get_date(days=CONFIG.UPDATECHECK, formatted=True)) CONFIG.set_setting('instalado', 'ignorado') url = 'plugin://{0}/?mode=builds'.format(CONFIG.ADDON_ID) self.close() xbmc.executebuiltin('ActivateWindow(Programs, {0}, return)'.format(url))
def do_ignore(self): logging.log( "[Verificação da compilação atual] [Selecionado pelo usuário: Menu Ignorar compilação] [Verificação seguinte: {0}]" .format(CONFIG.BUILDCHECK), level=xbmc.LOGINFO) CONFIG.set_setting( 'nextbuildcheck', tools.get_date(days=CONFIG.UPDATECHECK, formatted=True)) CONFIG.set_setting('installed', 'ignored') if 29 - 29: OOooOOo + Oo0Ooo.i11iIiiIii - i1IIi / iIii1I11I1II1 self.close() if 26 - 26: I11i.OoooooooOO
def log(msg, level=xbmc.LOGDEBUG): if CONFIG.DEBUGLEVEL == '0': # No Logging return False if CONFIG.DEBUGLEVEL == '1': # Normal Logging pass if CONFIG.DEBUGLEVEL == '2': # Full Logging level = xbmc.LOGNOTICE xbmc.log('{0}: {1}'.format(CONFIG.ADDONTITLE, msg), level) if CONFIG.ENABLEWIZLOG == 'true': if not os.path.exists(CONFIG.WIZLOG): with open(CONFIG.WIZLOG, 'w+') as f: f.close() lastcheck = CONFIG.NEXTCLEANDATE if not CONFIG.NEXTCLEANDATE == 0 else tools.get_date() if CONFIG.CLEANWIZLOG == 'true' and time.mktime(time.strptime(lastcheck, "%Y-%m-%d %H:%M:%S")) <= tools.get_date(): check_log() line = "[{0}] {1}".format(tools.get_date(formatted=True), msg) line = line.rstrip('\r\n') + '\n' tools.write_to_file(CONFIG.WIZLOG, line, mode='a')
def build_update_check(): response = tools.open_url(CONFIG.BUILDFILE, check=True) if not response: logging.log("[Build Check] Not a valid URL for Build File: {0}".format(CONFIG.BUILDFILE), level=xbmc.LOGINFO) elif not CONFIG.BUILDNAME == '': if CONFIG.SKIN in ['skin.confluence', 'skin.estuary', 'skin.estouchy'] and not CONFIG.DEFAULTIGNORE == 'true': check.check_skin() logging.log("[Build Check] Build Installed: Checking Updates", level=xbmc.LOGINFO) check.check_build_update() CONFIG.set_setting('nextbuildcheck', tools.get_date(days=CONFIG.UPDATECHECK, formatted=True))