def writeConfig(cfile, value): cfgfile = OSPJoin(writeConfig.configPath, cfile) cfglockfile = OSPJoin(writeConfig.configPath, cfile + '.lock') if not xbmcvfs.exists(writeConfig.configPath): xbmcvfs.mkdirs(writeConfig.configPath) while True: if not xbmcvfs.exists(cfglockfile): l = xbmcvfs.File(cfglockfile, 'w') l.write(str(time.time())) l.close() if value == '': xbmcvfs.delete(cfgfile) else: f = xbmcvfs.File(cfgfile, 'w') f.write(value.__str__()) f.close() xbmcvfs.delete(cfglockfile) return True else: l = xbmcvfs.File(cfglockfile) modified = float(l.read()) l.close() if time.time() - modified > 0.1: xbmcvfs.delete(cfglockfile)
def _LoadCache(self): """ Load cached catalog and video data """ from os.path import join as OSPJoin from xbmcvfs import exists self._catalogCache = OSPJoin(self._g.DATA_PATH, 'PVCatalog{0}.pvcp'.format(self._g.MarketID)) self._videodataCache = OSPJoin(self._g.DATA_PATH, 'PVVideoData{0}.pvdp'.format(self._g.MarketID)) if exists(self._videodataCache): with open(self._videodataCache, 'r') as fp: self._videodata = pickle.load(fp) if exists(self._catalogCache): with open(self._catalogCache, 'r') as fp: cached = pickle.load(fp) if time.time() < cached['expiration']: self._catalog = cached
def getConfig(cfile, defvalue=''): cfgfile = OSPJoin(getConfig.configPath, cfile) value = '' if xbmcvfs.exists(cfgfile): f = xbmcvfs.File(cfgfile, 'r') value = f.read() f.close() return value if value else defvalue
def WriteLog(data, fn=''): if not s.verbLog: return fn = '-' + fn if fn else '' fn = 'avod{}.log'.format(fn) path = OSPJoin(g.HOME_PATH, fn) logfile = xbmcvfs.File(path, 'w') logfile.write(py2_encode(data)) logfile.close()
def __init__(self): try: from urllib.parse import urlparse except ImportError: from urlparse import urlparse # argv[0] can contain the entire path, so we limit ourselves to the base url pid = urlparse(argv[0]) self.pluginid = '{}://{}/'.format(pid.scheme, pid.netloc) self.pluginhandle = int(argv[1]) if (1 < len(argv)) and self.pluginid else -1 self._globals['monitor'] = xbmc.Monitor() self._globals['addon'] = xbmcaddon.Addon() self._globals['dialog'] = xbmcgui.Dialog() self._globals['dialogProgressBG'] = xbmcgui.DialogProgressBG() self._globals['DATA_PATH'] = py2_decode(xbmc.translatePath(self.addon.getAddonInfo('profile'))) self._globals['CONFIG_PATH'] = OSPJoin(self.DATA_PATH, 'config') self._globals['HOME_PATH'] = py2_decode(xbmc.translatePath('special://home')) self._globals['PLUGIN_ID'] = py2_decode(self.addon.getAddonInfo('id')) self._globals['PLUGIN_PATH'] = py2_decode(self.addon.getAddonInfo('path')) self._globals['PLUGIN_NAME'] = self.addon.getAddonInfo('name') self._globals['PLUGIN_VERSION'] = self.addon.getAddonInfo('version') self._globals['MEDIA_FANART'] = OSPJoin(self.PLUGIN_PATH, 'resources/media/fanart.png') self._globals['MEDIA_FOLDER'] = OSPJoin(self.PLUGIN_PATH, 'resources/media/folderIcon.png') self._globals['MEDIA_ICON'] = OSPJoin(self.PLUGIN_PATH, 'resources/media/icon.png') self._globals['MEDIA_REMOVE'] = OSPJoin(self.PLUGIN_PATH, 'resources/media/iconRemove.png') self._globals['MEDIA_UPDATE'] = OSPJoin(self.PLUGIN_PATH, 'resources/media/updateIcon.png') self._globals['DATABASES'] = [ {'dbtype': 'movies', 'db': {'sqliteDB': None, 'mysqlDBType': 'Movies'}}, {'dbtype': 'tvshows', 'db': {'sqliteDB': None, 'mysqlDBType': 'TVShows'}}, {'dbtype': 'music', 'db': {'sqliteDB': None, 'mysqlDBType': 'Music'}} ] self._globals['DATABASE_SQLLITE_OSMOSIS_SCHEMA_VERSION_FILES_PATH'] = OSPJoin(self.PLUGIN_PATH, 'resources/db/migrate') bv = xbmc.getInfoLabel('System.BuildVersion') self._globals['KODI_VERSION'] = int(bv.split('.')[0]) cdate = None if search('Git:(\d+-.*)', bv): cdate = search('Git:(\d+)', bv) cdate = date.fromtimestamp(mktime(strptime(cdate.group(1), '%Y%m%d'))) if cdate else None self._globals['KODI_COMPILE_DATE'] = cdate self._globals['FEATURE_PLUGIN_RESUME_SYNC'] = self.KODI_VERSION >= 19 and self.KODI_COMPILE_DATE and self.KODI_COMPILE_DATE >= date(2020, 1, 28) self._globals['WATCHDOG_ID'] = 'service.librarywatchdog' if self.KODI_VERSION >= 19 else 'service.watchdog' try: import StorageServer except: import storageserverdummy as StorageServer self._globals['CACHE_TVSHOWS'] = StorageServer.StorageServer(py2_encode('{0}TVShowsTVDB1').format(self.PLUGIN_NAME), 24 * 30) self._globals['CACHE_EPISODES'] = StorageServer.StorageServer(py2_encode('{0}EpisodesTVDB1').format(self.PLUGIN_NAME), 24 * 30) self._globals['CACHE_EPISODES_MANUAL'] = StorageServer.StorageServer(py2_encode('{0}EpisodesManual1').format(self.PLUGIN_NAME), 24 * 365) self._globals['CACHE_TVDB_DATA'] = tvdbDataCache = StorageServer.StorageServer(py2_encode('{0}TVDBData1').format(self.PLUGIN_NAME), 1) self._globals['CACHE_ADDONNAME'] = StorageServer.StorageServer(py2_encode('{0}Addonname1').format(self.PLUGIN_NAME), 24)
def WriteLog(data, fn=''): if not s.verbLog: return fn = '-' + fn if fn else '' fn = 'avod%s.log' % fn path = OSPJoin(g.HOME_PATH, fn) if isinstance(data, unicode): data = data.encode('utf-8') logfile = xbmcvfs.File(path, 'w') logfile.write(data.__str__()) logfile.close()
def remLoginData(info=True): for fn in xbmcvfs.listdir(g.DATA_PATH)[1]: if fn.startswith('cookie'): xbmcvfs.delete(OSPJoin(g.DATA_PATH, fn)) writeConfig('accounts', '') writeConfig('login_name', '') writeConfig('login_pass', '') if info: writeConfig('accounts.lst', '') g.addon.setSetting('login_acc', '') g.dialog.notification(g.__plugin__, getString(30211), xbmcgui.NOTIFICATION_INFO)
def LogJSON(o, url): from json import dump if not o: return from codecs import open as co from datetime import datetime try: LogJSON.counter += 1 except: LogJSON.counter = 0 with co(OSPJoin(g.DATA_PATH, '{}_{}.json'.format(datetime.now().strftime('%Y%m%d_%H%M%S%f'), LogJSON.counter)), 'w+', 'utf-8') as f: f.write('/* %s */\n' % url) dump(o, f, sort_keys=True, indent=4)
def LogJSON(o, comment=None, optionalName=None): from json import dump if (not o) or (not s.dumpJSON): return from codecs import open as co from datetime import datetime try: LogJSON.counter += 1 except: LogJSON.counter = 0 fn = '{}_{}{}.json'.format(datetime.now().strftime('%Y%m%d_%H%M%S%f'), LogJSON.counter, '_' + optionalName if optionalName else '') with co(OSPJoin(g.DATA_PATH, fn), 'w+', 'utf-8') as f: if comment: f.write('/* %s */\n' % comment) dump(o, f, sort_keys=True, indent=4) Log('Saved JSON data with filename “{}”'.format(fn), Log.DEBUG)
def __getattr__(self, name): if 'CLEAR_STRMS' == name: return self._gs('Clear_Strms') == 'true' elif 'CONFIRM_USER_ENTRIES' == name: return self._gs('confirm_user_entries') == 'true' elif 'DATABASE_MYSQL_KODI_MUSIC_DATABASENAME' == name: return self._gs('KMusic-DB name') elif 'DATABASE_MYSQL_KODI_MUSIC_IP' == name: return self._gs('KMusic-DB IP') elif 'DATABASE_MYSQL_KODI_MUSIC_PASSWORD' == name: return self._gs('KMusic-DB password') elif 'DATABASE_MYSQL_KODI_MUSIC_PORT' == name: return self._gs('KMusic-DB port') elif 'DATABASE_MYSQL_KODI_MUSIC_USERNAME' == name: return self._gs('KMusic-DB username') elif 'DATABASE_MYSQL_KODI_VIDEO_DATABASENAME' == name: return self._gs('KMovie-DB name') elif 'DATABASE_MYSQL_KODI_VIDEO_IP' == name: return self._gs('KMovie-DB IP') elif 'DATABASE_MYSQL_KODI_VIDEO_PASSWORD' == name: return self._gs('KMovie-DB password') elif 'DATABASE_MYSQL_KODI_VIDEO_PORT' == name: return self._gs('KMovie-DB port') elif 'DATABASE_MYSQL_KODI_VIDEO_USERNAME' == name: return self._gs('KMovie-DB username') elif 'DATABASE_MYSQL_OSMOSIS_MOVIE_DATABASENAME' == name: return self._gs('Movies-DB name') elif 'DATABASE_MYSQL_OSMOSIS_MOVIE_IP' == name: return self._gs('Movies-DB IP') elif 'DATABASE_MYSQL_OSMOSIS_MOVIE_PASSWORD' == name: return self._gs('Movies-DB password') elif 'DATABASE_MYSQL_OSMOSIS_MOVIE_PORT' == name: return self._gs('Movies-DB port') elif 'DATABASE_MYSQL_OSMOSIS_MOVIE_USERNAME' == name: return self._gs('Movies-DB username') elif 'DATABASE_MYSQL_OSMOSIS_MUSIC_DATABASENAME' == name: return self._gs('Music-DB name') elif 'DATABASE_MYSQL_OSMOSIS_MUSIC_IP' == name: return self._gs('Music-DB IP') elif 'DATABASE_MYSQL_OSMOSIS_MUSIC_PASSWORD' == name: return self._gs('Music-DB password') elif 'DATABASE_MYSQL_OSMOSIS_MUSIC_PORT' == name: return self._gs('Music-DB port') elif 'DATABASE_MYSQL_OSMOSIS_MUSIC_USERNAME' == name: return self._gs('Music-DB username') elif 'DATABASE_MYSQL_OSMOSIS_TVSHOW_DATABASENAME' == name: return self._gs('TV-Show-DB name') elif 'DATABASE_MYSQL_OSMOSIS_TVSHOW_IP' == name: return self._gs('TV-Show-DB IP') elif 'DATABASE_MYSQL_OSMOSIS_TVSHOW_PASSWORD' == name: return self._gs('TV-Show-DB password') elif 'DATABASE_MYSQL_OSMOSIS_TVSHOW_PORT' == name: return self._gs('TV-Show-DB port') elif 'DATABASE_MYSQL_OSMOSIS_TVSHOW_USERNAME' == name: return self._gs('TV-Show-DB username') elif 'DATABASE_SQLLITE_KODI_MUSIC_FILENAME_AND_PATH' == name: return py2_decode(xbmc.translatePath(self._gs('KMusic-DB path'))) elif 'DATABASE_SQLLITE_KODI_VIDEO_FILENAME_AND_PATH' == name: return py2_decode(xbmc.translatePath(self._gs('KMovie-DB path'))) elif 'DATABASE_SQLLITE_OSMOSIS_MOVIE_PATH' == name: return py2_decode(xbmc.translatePath(self._gs('Movies-DB path'))) elif 'DATABASE_SQLLITE_OSMOSIS_MOVIE_FILENAME_AND_PATH' == name: return py2_decode( xbmc.translatePath( OSPJoin(self._gs('Movies-DB path'), 'Movies.db'))) elif 'DATABASE_SQLLITE_OSMOSIS_MUSIC_PATH' == name: return py2_decode(xbmc.translatePath(self._gs('Music-DB path'))) elif 'DATABASE_SQLLITE_OSMOSIS_MUSIC_FILENAME_AND_PATH' == name: return py2_decode( xbmc.translatePath( OSPJoin(self._gs('Music-DB path'), 'Musik.db'))) elif 'DATABASE_SQLLITE_OSMOSIS_TVSHOW_PATH' == name: return py2_decode(xbmc.translatePath(self._gs('TV-Show-DB path'))) elif 'DATABASE_SQLLITE_OSMOSIS_TVSHOW_FILENAME_AND_PATH' == name: return py2_decode( xbmc.translatePath( OSPJoin(self._gs('TV-Show-DB path'), 'Shows.db'))) elif 'FIND_SQLLITE_DB' == name: return self._gs('Find_SQLite_DB') == 'true' elif 'KEEP_MOVIE_YEAR' == name: return self._gs('keep_movie_year') == 'true' elif 'FOLDER_MEDIALISTENTRY_MOVIE' == name: return self._gs('folder_medialistentry_movie') == 'true' elif 'FOLDER_MOVIE' == name: return self._gs('folder_movie') == 'true' elif 'HIDE_TITLE_IN_OV' == name: return self._gs('Hide_title_in_OV') == 'true' elif 'INFOLABELS_ADD_ADDON_STRING' == name: return self._gs('infolabels_add_addon_string') elif 'LINK_TYPE' == name: return int(self._gs('Link_Type')) elif 'MEDIALIST_PATH' == name: return py2_decode(xbmc.translatePath(self._gs('MediaList_LOC'))) elif 'MEDIALIST_FILENNAME_AND_PATH' == name: return py2_decode(OSPJoin(self.MEDIALIST_PATH, 'MediaList.xml')) elif 'MYVIDEOS_SELECTACTION' == name: return jsonrpc('Settings.GetSettingValue', dict(setting='myvideos.selectaction')).get('value') elif 'NO_E0_STRMS_EXPORT' == name: return self._gs('noE0_Strms_Export') == 'true' elif 'PAGING_MOVIES' == name: return int(self._gs('paging_movies')) elif 'PAGING_TVSHOWS' == name: return int(self._gs('paging_tvshows')) elif 'PLAYBACK_DIALOG' == name: return int(self._gs('playback_dialog')) elif 'PLAYBACK_IGNORE_ADDON_STRING' == name: return self._gs('playback_ignore_addon_string') elif 'PLAYBACK_REWIND' == name: return int(self._gs('playback_rewind')) elif 'SCHEDULED_UPDATE' == name: return int(self._gs('scheduled_update')) elif 'SCHEDULED_UPDATE_INTERVAL' == name: return int(self._gs('scheduled_update_interval')) elif 'SCHEDULED_UPDATE_INTERVAL_FILENNAME_AND_PATH' == name: return py2_decode( OSPJoin(self.MEDIALIST_PATH, 'scheduled_update_interval.txt')) elif 'SCHEDULED_UPDATE_TIME' == name: return strptime(self._gs('scheduled_update_time'), '%H:%M') elif 'SEARCH_THETVDB' == name: return int(self._gs('search_thetvdb')) elif 'STRM_LOC' == name: return py2_decode(xbmc.translatePath(self._gs('STRM_LOC'))) elif 'TVDB_DIALOG_AUTOCLOSE_TIME' == name: return int(self._gs('tvdb_dialog_autoclose_time')) elif 'TVDB_TOKEN_FILENNAME_AND_PATH' == name: return py2_decode(OSPJoin(self.MEDIALIST_PATH, 'tvdb_token.txt')) elif 'UPDATE_AT_STARTUP' == name: return self._gs('Update_at_startup') == 'true' elif 'USE_MYSQL' == name: return self._gs('USE_MYSQL') == 'true'