def update_cache_version(): versionFile = control.joinPath(control.dataPath, 'cache.v') try: if not control.existsPath(versionFile): f = open(versionFile, 'w') f.close() except: log_utils.log( 'Venom Addon Data Path Does not Exist. Creating Folder....', __name__, log_utils.LOGDEBUG) ad_folder = control.transPath( 'special://profile/addon_data/plugin.video.venom') control.makeDirs(ad_folder) try: with open(versionFile, 'r') as fh: oldVersion = fh.read() except: oldVersion = '0' try: curVersion = control.addon('plugin.video.venom').getAddonInfo( 'version') if oldVersion != curVersion: with open(versionFile, 'w') as fh: fh.write(curVersion) return True else: return False except: log_utils.error() return False
def get_video_database_path(): database_path = control.absPath( control.joinPath( control.dataPath, '..', '..', 'Database', )) kodi_version = control.getKodiVersion() if kodi_version == 17: database_path = control.joinPath(database_path, 'MyVideos107.db') elif kodi_version == 18: database_path = control.joinPath(database_path, 'MyVideos116.db') elif kodi_version == 19: database_path = control.joinPath(database_path, 'MyVideos119.db') return database_path
def set_properties(self): try: self.setProperty('dg.total_results', self.total_results) self.setProperty('dg.highlight.color', getHighlightColor()) self.setProperty('dg.trakt_icon', joinPath(artPath(), 'trakt.png')) except: from resources.lib.modules import log_utils log_utils.error()
def strmFile(self, i): try: title, year, imdb, tmdb, tvdb, season, episode, tvshowtitle, premiered = i['title'], i['year'], i['imdb'], i['tmdb'], i['tvdb'], i['season'], i['episode'], i['tvshowtitle'], i['premiered'] episodetitle = quote_plus(title) systitle, syspremiered = quote_plus(tvshowtitle), quote_plus(premiered) transtitle = cleantitle.normalize(tvshowtitle.translate(None, '\/:*?"<>|')) content = '%s?action=play&title=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s&season=%s&episode=%s&tvshowtitle=%s&premiered=%s' % ( sys.argv[0], episodetitle, year, imdb, tmdb, tvdb, season, episode, systitle, syspremiered) folder = lib_tools.make_path(self.library_folder, transtitle, year) if not control.isfilePath(control.joinPath(folder, 'tvshow.nfo')): lib_tools.create_folder(folder) lib_tools.write_file(control.joinPath(folder, 'tvshow.nfo'), lib_tools.nfo_url('tv', i)) folder = lib_tools.make_path(self.library_folder, transtitle, year, season) lib_tools.create_folder(folder) lib_tools.write_file(control.joinPath(folder, lib_tools.legal_filename('%s S%02dE%02d' % (transtitle, int(season), int(episode))) + '.strm'), content) except: log_utils.error()
def get_video_database_path(): database_path = control.absPath( control.joinPath( control.dataPath, '..', '..', 'Database', )) # doesn't work with mysql # path_db = 'special://profile/Database/%s' % db_name kodi_version = control.getKodiVersion() if kodi_version == 17: database_path = control.joinPath(database_path, 'MyVideos107.db') elif kodi_version == 18: database_path = control.joinPath(database_path, 'MyVideos116.db') elif kodi_version == 19: database_path = control.joinPath(database_path, 'MyVideos119.db') return database_path
def get(file): helpFile = control.joinPath(kraken_path, 'resources', 'help', file + '.txt') r = open(helpFile) text = r.read() r.close() control.dialog.textviewer( '[COLOR red]Kraken[/COLOR] - v%s - %s' % (kraken_version, file), text)
def addDirectory(self, items, queue=False, isFolder=True): if items is None or len(items) == 0: control.hide() control.notification(title=32002, message=33049) sys.exit() sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) addonThumb = control.addonThumb() artPath = control.artPath() queueMenu = control.lang(32065) playRandom = control.lang(32535) addToLibrary = control.lang(32551) for i in items: try: name = i['name'] if i['image'].startswith('http'): thumb = i['image'] elif artPath: thumb = control.joinPath(artPath, i['image']) else: thumb = addonThumb item = control.item(label=name) if isFolder: url = '%s?action=%s' % (sysaddon, i['action']) try: url += '&url=%s' % quote_plus(i['url']) except: pass item.setProperty('IsPlayable', 'false') else: url = '%s?action=%s' % (sysaddon, i['action']) try: url += '&url=%s' % i['url'] except: pass item.setProperty('IsPlayable', 'true') item.setInfo("mediatype", "video") item.setInfo("audio", '') item.setArt({ 'icon': thumb, 'thumb': thumb, 'fanart': control.addonFanart() }) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=isFolder) except: pass control.content(syshandle, 'addons') control.directory(syshandle, cacheToDisc=True)
def get_quality_iconPath(self, quality): try: return joinPath( transPath( 'special://home/addons/plugin.video.venom/resources/skins/Default/media/resolution' ), '%s.png' % quality) except: from resources.lib.modules import log_utils log_utils.error()
def log(msg, caller=None, level=LOGINFO): debug_enabled = getSetting('debug.enabled') == 'true' if not debug_enabled: return debug_level = getSetting('debug.level') if level == LOGDEBUG and debug_level != '1': return debug_location = getSetting('debug.location') if isinstance(msg, int): msg = lang(msg) # for strings.po translations try: if not msg.isprintable( ): # ex. "\n" is not a printable character so returns False on those cases msg = '%s (NORMALIZED by log_utils.log())' % normalize(msg) if isinstance(msg, bytes): msg = '%s (ENCODED by log_utils.log())' % msg.decode( 'utf-8', errors='replace') if caller is not None and level != LOGERROR: func = inspect.currentframe().f_back.f_code line_number = inspect.currentframe().f_back.f_lineno caller = "%s.%s()" % (caller, func.co_name) msg = 'From func name: %s Line # :%s\n msg : %s' % ( caller, line_number, msg) elif caller is not None and level == LOGERROR: msg = 'From func name: %s.%s() Line # :%s\n msg : %s' % ( caller[0], caller[1], caller[2], msg) if debug_location == '1': log_file = joinPath(LOGPATH, 'dg.log') if not existsPath(log_file): f = open(log_file, 'w') f.close() reverse_log = getSetting('debug.reversed') == 'true' if not reverse_log: with open(log_file, 'a', encoding='utf-8' ) as f: # with auto cleans up and closes line = '[%s %s] %s: %s' % ( datetime.now().date(), str(datetime.now().time())[:8], DEBUGPREFIX % debug_list[level], msg) f.write(line.rstrip('\r\n') + '\n') # f.writelines([line1, line2]) ## maybe an option for the 2 lines without using "\n" else: with open(log_file, 'r+', encoding='utf-8') as f: line = '[%s %s] %s: %s' % ( datetime.now().date(), str(datetime.now().time())[:8], DEBUGPREFIX % debug_list[level], msg) log_file = f.read() f.seek(0, 0) f.write(line.rstrip('\r\n') + '\n' + log_file) else: import xbmc xbmc.log('%s: %s' % (DEBUGPREFIX % debug_list[level], msg), level) except Exception as e: import traceback traceback.print_exc() import xbmc xbmc.log( '[ plugin.video.dg ] log_utils.log() Logging Failure: %s' % (e), LOGERROR)
def __init__(self): self.library_folder = control.joinPath(control.transPath(control.setting('library.tv')),'') self.library_update = control.setting('library.update') or 'true' self.include_unknown = control.setting('library.include_unknown') or 'true' self.showunaired = control.setting('showunaired') or 'true' # self.date_time = (datetime.utcnow() - timedelta(hours = 5)) self.date_time = datetime.utcnow() if control.setting('library.importdelay') != 'true': self.date = self.date_time.strftime('%Y%m%d') else: self.date = (self.date_time - timedelta(hours = 24)).strftime('%Y%m%d')
def developer(self): try: url = control.joinPath(control.dataPath, 'testings.xml') f = control.openFile(url) ; result = f.read() ; f.close() self.list = self.it_list('', result=result) for i in self.list: i.update({'content': 'videos'}) self.addDirectory(self.list) return self.list except: log_utils.error()
def process(self, url, direct=True): try: if not any(i in url for i in ['.jpg', '.png', '.gif']): raise Exception() ext = url.split('?')[0].split('&')[0].split('|')[0].rsplit('.')[-1].replace('/', '').lower() if not ext in ['jpg', 'png', 'gif']: raise Exception() try: i = control.joinPath(control.dataPath,'img') control.deleteFile(i) f = control.openFile(i, 'w') f.write(client.request(url)) f.close() control.execute('ShowPicture("%s")' % i) return False except: return except: log_utils.error() try: r, x = re.findall(r'(.+?)\|regex=(.+?)$', url)[0] x = regex.fetch(x) r += unquote_plus(x) if not '</regex>' in r: raise Exception() u = regex.resolve(r) if not u is None: url = u except: pass try: if not url.startswith('rtmp'): raise Exception() if len(re.compile(r'\s*timeout=(\d*)').findall(url)) == 0: url += ' timeout=10' return url except: pass try: if not any(i in url for i in ['.m3u8', '.f4m', '.ts']): raise Exception() ext = url.split('?')[0].split('&')[0].split('|')[0].rsplit('.')[-1].replace('/', '').lower() if not ext in ['m3u8', 'f4m', 'ts']: raise Exception() return url except: pass try: preset = re.findall(r'<preset>(.+?)</preset>', url)[0] if not 'search' in preset: raise Exception() title, year, imdb = re.findall(r'<title>(.+?)</title>', url)[0], re.findall('<year>(.+?)</year>', url)[0], re.findall(r'<imdb>(.+?)</imdb>', url)[0] try: tvdb, tvshowtitle, premiered, season, episode = re.findall(r'<tvdb>(.+?)</tvdb>', url)[0], re.findall(r'<tvshowtitle>(.+?)</tvshowtitle>', url)[0], re.findall(r'<premiered>(.+?)</premiered>', url)[0], re.findall(r'<season>(.+?)</season>', url)[0], re.findall(r'<episode>(.+?)</episode>', url)[0] except: tvdb = tvshowtitle = premiered = season = episode = None direct = False quality = 'HD' if not preset == 'searchsd' else 'SD' from resources.lib.modules import sources u = sources.Sources().getSources(title, year, imdb, tvdb, season, episode, tvshowtitle, premiered, quality) if u: return u
def log(msg, caller=None, level=LOGNOTICE): debug_enabled = control.setting('debug.enabled') == 'true' if not debug_enabled: return debug_level = control.setting('debug.level') if level == LOGDEBUG and debug_level != '1': return debug_location = control.setting('debug.location') if isinstance(msg, int): msg = control.lang(msg) # for strings.po translations try: if py_tools.isPY3: if not msg.isprintable( ): # ex. "\n" is not a printable character so returns False on those sort of cases msg = '%s (NORMALIZED by log_utils.log())' % normalize(msg) if isinstance(msg, py_tools.binary_type): msg = '%s (ENCODED by log_utils.log())' % (py_tools.ensure_str( msg, errors='replace')) else: if not is_printable( msg ): # if not all(c in printable for c in msg): # .isprintable() not available in py2 msg = normalize(msg) if isinstance(msg, py_tools.binary_type): msg = '%s (ENCODED by log_utils.log())' % ( py_tools.ensure_text(msg)) if caller is not None and level != LOGERROR: func = inspect.currentframe().f_back.f_code line_number = inspect.currentframe().f_back.f_lineno caller = "%s.%s()" % (caller, func.co_name) msg = 'From func name: %s Line # :%s\n msg : %s' % ( caller, line_number, msg) elif caller is not None and level == LOGERROR: msg = 'From func name: %s.%s() Line # :%s\n msg : %s' % ( caller[0], caller[1], caller[2], msg) if debug_location == '1': log_file = control.joinPath(LOGPATH, 'venom.log') if not control.existsPath(log_file): f = open(log_file, 'w') f.close() with open(log_file, 'a', encoding='utf-8') as f: line = '[%s %s] %s: %s' % ( datetime.now().date(), str(datetime.now().time())[:8], DEBUGPREFIX % debug_list[level], msg) f.write(line.rstrip('\r\n') + '\n') # f.writelines([line1, line2]) ## maybe an option for the 2 lines without using "\n" else: xbmc.log('%s: %s' % (DEBUGPREFIX % debug_list[level], msg, level)) except Exception as e: import traceback traceback.print_exc() xbmc.log( '[ plugin.video.venom ] log_utils.log() Logging Failure: %s' % (e), LOGERROR)
def auto_tv_setup(self): try: control.makeFile(self.library_folder) icon = control.joinPath(control.artPath(), 'libtv.png') icon = 'DefaultTVShows.png' source_name = 'Venom TV Shows' # TVDb scraper source_content = "('%s','tvshows','metadata.tvdb.com','',0,0,'<settings version=\"2\"><setting id=\"absolutenumber\" default=\"true\">false</setting><setting id=\"alsoimdb\">true</setting><setting id=\"dvdorder\" default=\"true\">false</setting><setting id=\"fallback\">true</setting><setting id=\"fallbacklanguage\">es</setting><setting id=\"fanart\">true</setting><setting id=\"language\" default=\"true\">en</setting><setting id=\"RatingS\" default=\"true\">TheTVDB</setting><setting id=\"usefallbacklanguage1\">true</setting></settings>',0,0,NULL,NULL)" % self.library_folder # TMDb scraper # source_content = "('%s','tvshows','metadata.tvshows.themoviedb.org','',0,0,'<settings version=\"2\"><setting id=\"alsoimdb\" default=\"true\">false</setting><setting id=\"certprefix\" default=\"true\"></setting><setting id=\"fallback\">true</setting><setting id=\"fanarttvart\">true</setting><setting id=\"keeporiginaltitle\" default=\"true\">false</setting><setting id=\"language\" default=\"true\">en</setting><setting id=\"RatingS\" default=\"true\">Themoviedb</setting><setting id=\"tmdbart\">true</setting><setting id=\"tmdbcertcountry\" default=\"true\">us</setting></settings>',0,0,NULL,NULL)" % self.library_folder control.add_source(source_name, self.library_folder, source_content, icon) except: log_utils.error()
def upload_LogFile(name): from resources.lib.modules.control import notification url = 'https://paste.kodi.tv/' log_file = joinPath(LOGPATH, '%s.log' % name.lower()) if not existsPath(log_file): return notification( message='Log File not found, likely logging is not enabled.') try: import requests from resources.lib.modules.control import addonVersion, selectDialog, getHighlightColor f = open(log_file, 'r', encoding='utf-8', errors='ignore') text = f.read() f.close() UserAgent = 'DG %s' % addonVersion('plugin.video.dg') response = requests.post(url + 'documents', data=text.encode('utf-8', errors='ignore'), headers={'User-Agent': UserAgent}) # log('log_response=%s' % response) if 'key' in response.json(): result = url + response.json()['key'] log('%s log file uploaded to: %s' % (name, result)) from sys import platform as sys_platform supported_platform = any(value in sys_platform for value in ('win32', 'linux2')) highlight_color = getHighlightColor() list = [ ('[COLOR %s]url:[/COLOR] %s' % (highlight_color, str(result)), str(result)) ] if supported_platform: list += [('[COLOR %s] -- Copy url To Clipboard[/COLOR]' % highlight_color, ' ')] select = selectDialog( [i[0] for i in list], lang(32196) if name.lower() == 'dg' else lang(32199)) if 'Copy url To Clipboard' in list[select][0]: from resources.lib.modules.source_utils import copy2clip copy2clip(list[select - 1][1]) elif 'message' in response.json(): notification(message='%s Log upload failed: %s' % (name, str(response.json()['message']))) log('%s Log upload failed: %s' % (name, str(response.json()['message'])), level=LOGERROR) else: notification(message='%s Log upload failed' % name) log('%s Log upload failed: %s' % (name, response.text), level=LOGERROR) except: error('%s log upload failed' % name) notification(message='pastebin post failed: See log for more info')
def get(file): venom_path = addonPath(addonId()) venom_version = getVenomVersion() helpFile = joinPath(venom_path, 'resources', 'help', file + '.txt') f = open(helpFile, 'r', encoding='utf-8', errors='ignore') text = f.read() f.close() heading = '[B]Venom - v%s - %s[/B]' % (venom_version, file) windows = TextViewerXML('textviewer.xml', venom_path, heading=heading, text=text) windows.run() del windows
def addDirectoryItem(self, name, query, poster, icon, context=None, queue=False, isAction=True, isFolder=True, isPlayable=False, isSearch=False, table=''): try: sysaddon = argv[0] ; syshandle = int(argv[1]) if isinstance(name, int): name = getLS(name) url = '%s?action=%s' % (sysaddon, query) if isAction else query poster = control.joinPath(self.artPath, poster) if self.artPath else icon if not icon.startswith('Default'): icon = control.joinPath(self.artPath, icon) cm = [] queueMenu = getLS(32065) if queue: cm.append((queueMenu, 'RunPlugin(%s?action=playlist_QueueItem)' % sysaddon)) if context: cm.append((getLS(context[0]), 'RunPlugin(%s?action=%s)' % (sysaddon, context[1]))) if isSearch: cm.append(('Clear Search Phrase', 'RunPlugin(%s?action=cache_clearSearchPhrase&source=%s&name=%s)' % (sysaddon, table, quote_plus(name)))) cm.append(('[COLOR red]Venom Settings[/COLOR]', 'RunPlugin(%s?action=tools_openSettings)' % sysaddon)) item = control.item(label=name, offscreen=True) item.addContextMenuItems(cm) if isPlayable: item.setProperty('IsPlayable', 'true') else: item.setProperty('IsPlayable', 'false') item.setArt({'icon': icon, 'poster': poster, 'thumb': poster, 'fanart': control.addonFanart(), 'banner': poster}) item.setInfo(type='video', infoLabels={'plot': name}) control.addItem(handle=syshandle, url=url, listitem=item, isFolder= isFolder) except: from resources.lib.modules import log_utils log_utils.error()
def get(file): venom_path = addonPath(addonId()) venom_version = getVenomVersion() helpFile = joinPath(venom_path, 'resources', 'help', file + '.txt') r = open(helpFile) text = r.read() r.close() heading = '[B]Venom - v%s - %s[/B]' % (venom_version, file) windows = TextViewerXML('textviewer.xml', venom_path, heading=heading, text=text) windows.run() del windows
def get(): venom_path = addonPath(addonId()) venom_version = getVenomVersion() changelogfile = joinPath(venom_path, 'changelog.txt') r = open(changelogfile) text = r.read() r.close() heading = '[B]Venom - v%s - ChangeLog[/B]' % venom_version windows = TextViewerXML('textviewer.xml', venom_path, heading=heading, text=text) windows.run() del windows
def addDirectoryItem(self, name, query, thumb, icon, context=None, queue=False, isAction=True, isFolder=True, isPlayable=False, isSearch=False, table=''): sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) try: if type(name) is str or type(name) is unicode: name = str(name) if type(name) is int: name = control.lang(name) except: log_utils.error() url = '%s?action=%s' % (sysaddon, query) if isAction else query thumb = control.joinPath(artPath, thumb) if artPath else icon if not icon.startswith('Default'): icon = control.joinPath(artPath, icon) cm = [] queueMenu = control.lang(32065) if queue: cm.append((queueMenu, 'RunPlugin(%s?action=playlist_QueueItem)' % sysaddon)) if context: cm.append((control.lang(context[0]), 'RunPlugin(%s?action=%s)' % (sysaddon, context[1]))) if isSearch: try: from urllib import quote_plus except: from urllib.parse import quote_plus cm.append(('Clear Search Phrase', 'RunPlugin(%s?action=cache_clearSearchPhrase&source=%s&name=%s)' % (sysaddon, table, quote_plus(name)))) cm.append(('[COLOR red]Venom Settings[/COLOR]', 'RunPlugin(%s?action=openSettings)' % sysaddon)) item = control.item(label=name) item.addContextMenuItems(cm) if isPlayable: item.setProperty('IsPlayable', 'true') else: item.setProperty('IsPlayable', 'false') item.setArt({'icon': icon, 'poster': thumb, 'thumb': thumb, 'fanart': control.addonFanart(), 'banner': thumb}) control.addItem(handle=syshandle, url=url, listitem=item, isFolder= isFolder)
def run(self): if control.getKodiVersion() < 18: return xbmc.log( '[ plugin.video.venom ] ReuseLanguageInvokerCheck Service Starting...', 2) try: import xml.etree.ElementTree as ET addon_xml = control.joinPath( control.addonPath('plugin.video.venom'), 'addon.xml') tree = ET.parse(addon_xml) root = tree.getroot() current_addon_setting = control.addon( 'plugin.video.venom').getSetting('reuse.languageinvoker') try: current_xml_setting = [ str(i.text) for i in root.iter('reuselanguageinvoker') ][0] except: return xbmc.log( '[ plugin.video.venom ] ReuseLanguageInvokerCheck failed to get settings.xml value', 2) if current_addon_setting == '': current_addon_setting = 'true' control.setSetting('reuse.languageinvoker', current_addon_setting) if current_xml_setting == current_addon_setting: return xbmc.log( '[ plugin.video.venom ] ReuseLanguageInvokerCheck Service Finished', 2) control.okDialog(message='%s\n%s' % (control.lang(33023), control.lang(33020))) for item in root.iter('reuselanguageinvoker'): item.text = current_addon_setting hash_start = control.gen_file_hash(addon_xml) tree.write(addon_xml) hash_end = control.gen_file_hash(addon_xml) xbmc.log( '[ plugin.video.venom ] ReuseLanguageInvokerCheck Service Finished', 2) if hash_start != hash_end: current_profile = control.infoLabel('system.profilename') control.execute('LoadProfile(%s)' % current_profile) else: control.okDialog(title='default', message=33022) return except: log_utils.error() pass
def clearViews(): try: skin = control.skin control.hide() yes = control.yesnoDialog(control.lang(32056), '', '') if not yes: return control.makeFile(control.dataPath) dbcon = database.connect(control.viewsFile) dbcur = dbcon.cursor() for t in ['views']: try: dbcur.execute("DROP TABLE IF EXISTS %s" % t) dbcur.execute("VACUUM") dbcur.execute("CREATE TABLE IF NOT EXISTS views (" "skin TEXT, " "view_type TEXT, " "view_id TEXT, " "UNIQUE(skin, view_type)" ");") dbcur.connection.commit() dbcon.close() except: log_utils.error() pass try: kodiDB = control.transPath('special://home/userdata/Database') kodiViewsDB = control.joinPath(kodiDB, 'ViewModes6.db') dbcon = database.connect(kodiViewsDB) dbcur = dbcon.cursor() dbcur.execute( "DELETE FROM view WHERE path LIKE 'plugin://plugin.video.venom/%'" ) dbcur.connection.commit() dbcon.close() except: log_utils.error() pass skinName = control.addon(skin).getAddonInfo('name') skinIcon = control.addon(skin).getAddonInfo('icon') control.notification( title=skinName, message='View Types Successfully Cleared!', icon=skinIcon, sound=(control.setting('notification.sound') == 'true')) except: log_utils.error() pass
def view_LogFile(name): try: from resources.lib.windows.textviewer import TextViewerXML from resources.lib.modules.control import addonPath log_file = joinPath(LOGPATH, '%s.log' % name.lower()) if not existsPath(log_file): from resources.lib.modules.control import notification return notification(message='Log File not found, likely logging is not enabled.') f = open(log_file, 'r', encoding='utf-8', errors='ignore') text = f.read() f.close() heading = '[B]%s - LogFile[/B]' % name windows = TextViewerXML('textviewer.xml', addonPath('plugin.video.venom'), heading=heading, text=text) windows.run() del windows except: error()
def clear_logFile(): cleared = False try: from resources.lib.modules.control import yesnoDialog if not yesnoDialog(lang(32056), '', ''): return 'canceled' log_file = joinPath(LOGPATH, 'venom.log') if not existsPath(log_file): f = open(log_file, 'w') return f.close() f = open(log_file, 'r+') f.truncate(0) # need '0' when using r f.close() cleared = True except Exception as e: import xbmc xbmc.log('[ plugin.video.venom ] log_utils.clear_logFile() Failure: %s' % (e), LOGERROR) cleared = False return cleared
def get_cache_version(): versionFile = control.joinPath(control.dataPath, 'cache.v') try: if not control.existsPath(versionFile): f = open(versionFile, 'w') f.close() except: log_utils.log( 'Venom Addon Data Path Does not Exist. Creating Folder....', __name__, log_utils.LOGDEBUG) ad_folder = control.transPath( 'special://profile/addon_data/plugin.video.venom') control.makeDirs(ad_folder) try: with open(versionFile, 'r') as fh: oldVersion = fh.read() except: oldVersion = '0' return oldVersion
def log(msg, caller=None, level=LOGNOTICE): debug_enabled = control.setting('addon_debug') debug_log = control.setting('debug.location') print(DEBUGPREFIX + ' Debug Enabled?: ' + str(debug_enabled)) print(DEBUGPREFIX + ' Debug Log?: ' + str(debug_log)) if control.setting('addon_debug') != 'true': return try: if caller is not None and level == LOGDEBUG: func = inspect.currentframe().f_back.f_code line_number = inspect.currentframe().f_back.f_lineno caller = "%s.%s()" % (caller, func.co_name) msg = 'From func name: %s Line # :%s\n msg : %s' % ( caller, line_number, msg) if caller is not None and level == LOGERROR: msg = 'From func name: %s.%s() Line # :%s\n msg : %s' % ( caller[0], caller[1], caller[2], msg) if isinstance(msg, unicode): msg = '%s (ENCODED)' % (msg.encode('utf-8')) if not control.setting('debug.location') == '0': log_file = control.joinPath(LOGPATH, 'venom.log') if not control.existsPath(log_file): f = open(log_file, 'w') f.close() with open(log_file, 'a') as f: line = '[%s %s] %s: %s' % (datetime.now().date(), str(datetime.now().time())[:8], DEBUGPREFIX, msg) f.write(line.rstrip('\r\n') + '\n') else: print('%s: %s' % (DEBUGPREFIX, msg)) except Exception as e: try: xbmc.log('Logging Failure: %s' % (e), level) except: pass
def clearViews(): try: skin = control.skin control.hide() if not control.yesnoDialog(control.lang(32056), '', ''): return control.makeFile(control.dataPath) dbcon = db.connect(control.viewsFile) dbcur = dbcon.cursor() try: dbcur.execute('''DROP TABLE IF EXISTS views''') dbcur.execute('''VACUUM''') dbcur.execute( '''CREATE TABLE IF NOT EXISTS views (skin TEXT, view_type TEXT, view_id TEXT, UNIQUE(skin, view_type));''' ) dbcur.connection.commit() except: from resources.lib.modules import log_utils log_utils.error() finally: dbcur.close() dbcon.close() try: kodiDB = control.transPath('special://home/userdata/Database') kodiViewsDB = control.joinPath(kodiDB, 'ViewModes6.db') dbcon = db.connect(kodiViewsDB) dbcur = dbcon.cursor() dbcur.execute( '''DELETE FROM view WHERE path LIKE "plugin://plugin.video.dg/%"''' ) dbcur.connection.commit() except: from resources.lib.modules import log_utils log_utils.error() finally: dbcur.close() dbcon.close() skinName = control.addon(skin).getAddonInfo('name') skinIcon = control.addon(skin).getAddonInfo('icon') control.notification(title=skinName, message=32087, icon=skinIcon) except: from resources.lib.modules import log_utils log_utils.error()
def log(msg, caller=None, level=LOGNOTICE): debug_enabled = control.setting('debug.enabled') == 'true' if not debug_enabled: return debug_level = control.setting('debug.level') if level == LOGDEBUG and debug_level != '1': return debug_location = control.setting('debug.location') try: if caller is not None and level != LOGERROR: func = inspect.currentframe().f_back.f_code line_number = inspect.currentframe().f_back.f_lineno caller = "%s.%s()" % (caller, func.co_name) msg = 'From func name: %s Line # :%s\n msg : %s' % ( caller, line_number, msg) if caller is not None and level == LOGERROR: msg = 'From func name: %s.%s() Line # :%s\n msg : %s' % ( caller[0], caller[1], caller[2], msg) try: if isinstance(msg, py_tools.text_type): # msg = msg.encode('ascii', errors='ignore').decode('ascii', errors='ignore') moved this to `ensure_str(), check if it's correct. msg = '%s (ENCODED)' % (py_tools.ensure_str(msg, errors='replace')) except: pass if debug_location == '1': log_file = control.joinPath(LOGPATH, 'venom.log') if not control.existsPath(log_file): f = open(log_file, 'w') f.close() with open(log_file, 'a') as f: line = '[%s %s] %s: %s' % ( datetime.now().date(), str(datetime.now().time())[:8], DEBUGPREFIX % debug_list[level], msg) f.write(line.rstrip('\r\n') + '\n') else: xbmc.log('%s: %s' % (DEBUGPREFIX % debug_list[level], msg, level)) except Exception as e: xbmc.log( '[ plugin.video.venom ] log_utils.log() Logging Failure: %s' % (e), LOGERROR)
def run(self): if control.getKodiVersion() < 18: return try: import xml.etree.ElementTree as ET addon_dir = control.transPath( control.addon('plugin.video.venom').getAddonInfo('path')) addon_xml = control.joinPath(addon_dir, 'addon.xml') tree = ET.parse(addon_xml) root = tree.getroot() current_addon_setting = control.addon( 'plugin.video.venom').getSetting('reuse.languageinvoker') if current_addon_setting == '': return try: current_xml_setting = [ str(i.text) for i in root.iter('reuselanguageinvoker') ][0] except: return if current_xml_setting == current_addon_setting: return if not control.yesnoDialog( '[B]Reuse Language Invoker[/B] SETTING/XML mismatch.\nRestore correct status(RECOMMENDED)?', '', ''): return for item in root.iter('reuselanguageinvoker'): item.text = current_addon_setting hash_start = control.gen_file_hash(addon_xml) tree.write(addon_xml) hash_end = control.gen_file_hash(addon_xml) if hash_start != hash_end: control.okDialog( 'Kodi must close and be restarted for the change to take effect.' ) else: control.okDialog('Venom', 'Error setting correct value.') return except: log_utils.error() pass
def run(self): try: profile_dir = xbmc.translatePath( 'special://profile/addon_data/plugin.video.venom/') if not control.existsPath(profile_dir): success = control.makeDirs(profile_dir) if success: xbmc.log('%s : created successfully' % profile_dir, 2) else: xbmc.log('%s : already exists' % profile_dir, 2) settings_xml = control.joinPath(profile_dir, 'settings.xml') if not control.existsPath(settings_xml): control.setSetting('clear.all.cache', '') xbmc.log('%s : created successfully' % settings_xml, 2) else: xbmc.log('%s : already exists' % settings_xml, 2) return except: import traceback traceback.print_exc() pass