Convert settings to utils method for addon settings

This commit is contained in:
angelblue05 2015-08-14 04:03:12 -05:00
parent 811e91a0b5
commit c0f9948cf5
18 changed files with 183 additions and 156 deletions

View file

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.video.emby" <addon id="plugin.video.emby"
name="Emby" name="Emby"
version="1.1.31" version="1.1.32~alpha"
provider-name="Emby.media"> provider-name="Emby.media">
<requires> <requires>
<import addon="xbmc.python" version="2.1.0"/> <import addon="xbmc.python" version="2.1.0"/>

View file

@ -6,7 +6,8 @@ from datetime import datetime
from random import randrange from random import randrange
import xbmc import xbmc
import xbmcgui import xbmcgui
import xbmcaddon
import Utils as utils
class API(): class API():
@ -406,7 +407,6 @@ class API():
def getArtwork(self, data, type, mediaType = "", index = "0", userParentInfo = False): def getArtwork(self, data, type, mediaType = "", index = "0", userParentInfo = False):
addonSettings = xbmcaddon.Addon(id='plugin.video.emby')
id = data.get("Id") id = data.get("Id")
getSeriesData = False getSeriesData = False
userData = data.get("UserData") userData = data.get("UserData")
@ -415,7 +415,7 @@ class API():
if data.get("Type") == "Season" or data.get("Type")== "Episode": if data.get("Type") == "Season" or data.get("Type")== "Episode":
id = data.get("SeriesId") id = data.get("SeriesId")
getSeriesData = True getSeriesData = True
elif type == "poster" and data.get("Type") == "Episode" and addonSettings.getSetting('useSeasonPoster')=='true': # Change the Id to the Season to get the season poster elif type == "poster" and data.get("Type") == "Episode" and utils.settings('useSeasonPoster')=='true': # Change the Id to the Season to get the season poster
id = data.get("SeasonId") id = data.get("SeasonId")
if type == "poster" or type == "tvshow.poster": # Now that the Ids are right, change type to MB3 name if type == "poster" or type == "tvshow.poster": # Now that the Ids are right, change type to MB3 name
type="Primary" type="Primary"
@ -478,7 +478,7 @@ class API():
played = "0" played = "0"
totalbackdrops = 0 totalbackdrops = 0
if addonSettings.getSetting('coverArtratio') == "true": if utils.settings('coverArtratio') == "true":
if mediaType in ("movie","boxset","tvshow"): if mediaType in ("movie","boxset","tvshow"):
if "Primary" in type: if "Primary" in type:
# Only force ratio for cover art for main covers # Only force ratio for cover art for main covers
@ -496,7 +496,7 @@ class API():
username = WINDOW.getProperty('currUser') username = WINDOW.getProperty('currUser')
server = WINDOW.getProperty('server%s' % username) server = WINDOW.getProperty('server%s' % username)
if addonSettings.getSetting('compressArt')=='true': if utils.settings('compressArt')=='true':
query = query + "&Quality=90" query = query + "&Quality=90"
if imageTag == None: if imageTag == None:
@ -504,7 +504,7 @@ class API():
artwork = "%s/mediabrowser/Items/%s/Images/%s/%s?MaxWidth=%s&MaxHeight=%s%s%s&Format=original&Tag=%s%s" % (server, id, type, index, maxWidth, maxHeight, height, width, imageTag, query) artwork = "%s/mediabrowser/Items/%s/Images/%s/%s?MaxWidth=%s&MaxHeight=%s%s%s&Format=original&Tag=%s%s" % (server, id, type, index, maxWidth, maxHeight, height, width, imageTag, query)
#artwork = "%s/mediabrowser/Items/%s/Images/%s/%s/%s/original/%s/%s/%s?%s" % (server, id, type, index, imageTag, width, height, played, query) <- broken #artwork = "%s/mediabrowser/Items/%s/Images/%s/%s/%s/original/%s/%s/%s?%s" % (server, id, type, index, imageTag, width, height, played, query) <- broken
if addonSettings.getSetting('disableCoverArt')=='true': if utils.settings('disableCoverArt')=='true':
artwork = artwork + "&EnableImageEnhancers=false" artwork = artwork + "&EnableImageEnhancers=false"
# do not return non-existing images # do not return non-existing images

View file

@ -37,13 +37,11 @@ class ClientInformation():
def getDeviceName(self): def getDeviceName(self):
addon = self.addon if utils.settings('deviceNameOpt') == "false":
if addon.getSetting('deviceNameOpt') == "false":
# Use Kodi's deviceName # Use Kodi's deviceName
deviceName = xbmc.getInfoLabel('System.FriendlyName') deviceName = xbmc.getInfoLabel('System.FriendlyName')
else: else:
deviceName = addon.getSetting('deviceName') deviceName = utils.settings('deviceName')
deviceName = deviceName.replace("\"", "_") deviceName = deviceName.replace("\"", "_")
deviceName = deviceName.replace("/", "_") deviceName = deviceName.replace("/", "_")

View file

@ -42,7 +42,6 @@ class ConnectionManager():
self.WINDOW.setProperty("Server_Checked", "True") self.WINDOW.setProperty("Server_Checked", "True")
self.logMsg("Connection Manager Called", 2) self.logMsg("Connection Manager Called", 2)
addon = self.addon
server = self.user.getServer() server = self.user.getServer()
if server != "": if server != "":
@ -61,11 +60,11 @@ class ConnectionManager():
if setServer == 1: if setServer == 1:
self.logMsg("Server selected. Saving information.", 1) self.logMsg("Server selected. Saving information.", 1)
addon.setSetting("ipaddress", ip.replace("/", "")) utils.settings("ipaddress", ip.replace("/", ""))
addon.setSetting("port", port) utils.settings("port", port)
# If https, enable the setting # If https, enable the setting
if (prefix == 'https'): if (prefix == 'https'):
addon.setSetting('https', "true") utils.settings('https', "true")
else: else:
self.logMsg("No server selected.", 1) self.logMsg("No server selected.", 1)
xbmc.executebuiltin('Addon.OpenSettings(%s)' % self.addonId) xbmc.executebuiltin('Addon.OpenSettings(%s)' % self.addonId)
@ -99,7 +98,7 @@ class ConnectionManager():
if resp > -1: if resp > -1:
selected_user = userList[resp] selected_user = userList[resp]
self.logMsg("Selected User: %s" % selected_user, 1) self.logMsg("Selected User: %s" % selected_user, 1)
self.addon.setSetting("username", selected_user) utils.settings("username", selected_user)
else: else:
self.logMsg("No user selected.", 1) self.logMsg("No user selected.", 1)
xbmc.executebuiltin('Addon.OpenSettings(%s)' % self.addonId) xbmc.executebuiltin('Addon.OpenSettings(%s)' % self.addonId)

View file

@ -135,9 +135,11 @@ class DownloadUtils():
self.logMsg("Requests session started on: %s" % self.server) self.logMsg("Requests session started on: %s" % self.server)
def imageUrl(self, id, type, index, width, height): def stopSession(self):
# To move to API.py try:
return "%s/mediabrowser/Items/%s/Images/%s?MaxWidth=%s&MaxHeight=%s&Index=%s" % (self.server, id, type, width, height, index) self.s.close()
except:
self.logMsg("Requests session could not be terminated.", 1)
def getHeader(self, authenticate=True): def getHeader(self, authenticate=True):
@ -206,10 +208,10 @@ class DownloadUtils():
# IF user enables ssl verification # IF user enables ssl verification
try: try:
if self.addon.getSetting('sslverify') == "true": if utils.settings('sslverify') == "true":
verifyssl = True verifyssl = True
if self.addon.getSetting('sslcert') != "None": if utils.settings('sslcert') != "None":
cert = self.addon.getSetting('sslcert') cert = utils.settings('sslcert')
except: except:
self.logMsg("Could not load SSL settings.", 1) self.logMsg("Could not load SSL settings.", 1)
pass pass

View file

@ -437,7 +437,7 @@ def BrowseChannels(id, folderid=None):
##### GET NEXTUP EPISODES FOR TAGNAME ##### ##### GET NEXTUP EPISODES FOR TAGNAME #####
def getNextUpEpisodes(tagname,limit): def getNextUpEpisodes(tagname,limit):
count=0 count=0
addonSettings = xbmcaddon.Addon(id='plugin.video.emby')
#if the addon is called with nextup parameter, we return the nextepisodes list of the given tagname #if the addon is called with nextup parameter, we return the nextepisodes list of the given tagname
xbmcplugin.setContent(int(sys.argv[1]), 'episodes') xbmcplugin.setContent(int(sys.argv[1]), 'episodes')
# First we get a list of all the in-progress TV shows - filtered by tag # First we get a list of all the in-progress TV shows - filtered by tag
@ -449,7 +449,7 @@ def getNextUpEpisodes(tagname,limit):
for item in json_result['result']['tvshows']: for item in json_result['result']['tvshows']:
# If Ignore Specials is true only choose episodes from seasons greater than 0. # If Ignore Specials is true only choose episodes from seasons greater than 0.
if addonSettings.getSetting("ignoreSpecialsNextEpisodes")=="true": if utils.settings("ignoreSpecialsNextEpisodes")=="true":
json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": { "tvshowid": %d, "sort": {"method":"episode"}, "filter": {"and": [ {"field": "playcount", "operator": "lessthan", "value":"1"}, {"field": "season", "operator": "greaterthan", "value": "0"} ]}, "properties": [ "title", "playcount", "season", "episode", "showtitle", "plot", "file", "rating", "resume", "tvshowid", "art", "streamdetails", "firstaired", "runtime", "writer", "dateadded", "lastplayed" ], "limits":{"end":1}}, "id": "1"}' %item['tvshowid']) json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": { "tvshowid": %d, "sort": {"method":"episode"}, "filter": {"and": [ {"field": "playcount", "operator": "lessthan", "value":"1"}, {"field": "season", "operator": "greaterthan", "value": "0"} ]}, "properties": [ "title", "playcount", "season", "episode", "showtitle", "plot", "file", "rating", "resume", "tvshowid", "art", "streamdetails", "firstaired", "runtime", "writer", "dateadded", "lastplayed" ], "limits":{"end":1}}, "id": "1"}' %item['tvshowid'])
else: else:
json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": { "tvshowid": %d, "sort": {"method":"episode"}, "filter": {"field": "playcount", "operator": "lessthan", "value":"1"}, "properties": [ "title", "playcount", "season", "episode", "showtitle", "plot", "file", "rating", "resume", "tvshowid", "art", "streamdetails", "firstaired", "runtime", "writer", "dateadded", "lastplayed" ], "limits":{"end":1}}, "id": "1"}' %item['tvshowid']) json_query2 = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetEpisodes", "params": { "tvshowid": %d, "sort": {"method":"episode"}, "filter": {"field": "playcount", "operator": "lessthan", "value":"1"}, "properties": [ "title", "playcount", "season", "episode", "showtitle", "plot", "file", "rating", "resume", "tvshowid", "art", "streamdetails", "firstaired", "runtime", "writer", "dateadded", "lastplayed" ], "limits":{"end":1}}, "id": "1"}' %item['tvshowid'])

View file

@ -15,7 +15,6 @@ from PlayUtils import PlayUtils
from DownloadUtils import DownloadUtils from DownloadUtils import DownloadUtils
from PlaybackUtils import PlaybackUtils from PlaybackUtils import PlaybackUtils
addon = xbmcaddon.Addon(id='plugin.video.emby')
class Kodi_Monitor(xbmc.Monitor): class Kodi_Monitor(xbmc.Monitor):
@ -34,7 +33,7 @@ class Kodi_Monitor(xbmc.Monitor):
WINDOW = self.WINDOW WINDOW = self.WINDOW
downloadUtils = DownloadUtils() downloadUtils = DownloadUtils()
#player started playing an item - #player started playing an item -
if ("Playlist.OnAdd" in method or "Player.OnPlay" in method) and addon.getSetting('useDirectPaths')=='true': if ("Playlist.OnAdd" in method or "Player.OnPlay" in method) and utils.settings('useDirectPaths')=='true':
jsondata = json.loads(data) jsondata = json.loads(data)
if jsondata != None: if jsondata != None:

View file

@ -43,8 +43,8 @@ class LibrarySync(threading.Thread):
addonName = clientInfo.getAddonName() addonName = clientInfo.getAddonName()
doIncrementalSync = False
updateItems = [] updateItems = []
userdataItems = []
removeItems = [] removeItems = []
def __init__(self, *args): def __init__(self, *args):
@ -59,28 +59,27 @@ class LibrarySync(threading.Thread):
def FullLibrarySync(self,manualRun=False): def FullLibrarySync(self,manualRun=False):
addon = xbmcaddon.Addon(id='plugin.video.emby')
startupDone = WINDOW.getProperty("startup") == "done" startupDone = WINDOW.getProperty("startup") == "done"
syncInstallRunDone = addon.getSetting("SyncInstallRunDone") == "true" syncInstallRunDone = utils.settings("SyncInstallRunDone") == "true"
performMusicSync = addon.getSetting("enableMusicSync") == "true" performMusicSync = utils.settings("enableMusicSync") == "true"
dbSyncIndication = addon.getSetting("dbSyncIndication") == "true" dbSyncIndication = utils.settings("dbSyncIndication") == "true"
### BUILD VIDEO NODES LISTING ### ### BUILD VIDEO NODES LISTING ###
VideoNodes().buildVideoNodesListing() VideoNodes().buildVideoNodesListing()
### CREATE SOURCES ### ### CREATE SOURCES ###
if addon.getSetting("Sources") != "true": if utils.settings("Sources") != "true":
# Only create sources once # Only create sources once
self.logMsg("Sources.xml created.", 0) self.logMsg("Sources.xml created.", 0)
utils.createSources() utils.createSources()
addon.setSetting("Sources", "true") utils.settings("Sources", "true")
# just do a incremental sync if that is what is required # just do a incremental sync if that is what is required
if(addon.getSetting("useIncSync") == "true" and addon.getSetting("SyncInstallRunDone") == "true") and manualRun == False: if(utils.settings("useIncSync") == "true" and utils.settings("SyncInstallRunDone") == "true") and manualRun == False:
utils.logMsg("Sync Database", "Using incremental sync instead of full sync useIncSync=True)", 0) utils.logMsg("Sync Database", "Using incremental sync instead of full sync useIncSync=True)", 0)
du = DownloadUtils() du = DownloadUtils()
lastSync = addon.getSetting("LastIncrenetalSync") lastSync = utils.settings("LastIncrenetalSync")
if(lastSync == None or len(lastSync) == 0): if(lastSync == None or len(lastSync) == 0):
lastSync = "2010-01-01T00:00:00Z" lastSync = "2010-01-01T00:00:00Z"
utils.logMsg("Sync Database", "Incremental Sync Setting Last Run Time Loaded : " + lastSync, 0) utils.logMsg("Sync Database", "Incremental Sync Setting Last Run Time Loaded : " + lastSync, 0)
@ -103,6 +102,8 @@ class LibrarySync(threading.Thread):
LibrarySync().update_items(changedItems) LibrarySync().update_items(changedItems)
LibrarySync().user_data_update(userChanges) LibrarySync().user_data_update(userChanges)
self.SaveLastSync()
return True return True
#set some variable to check if this is the first run #set some variable to check if this is the first run
@ -128,7 +129,10 @@ class LibrarySync(threading.Thread):
cursor = connection.cursor() cursor = connection.cursor()
#Add the special emby table #Add the special emby table
cursor.execute("CREATE TABLE IF NOT EXISTS emby(emby_id TEXT, kodi_id INTEGER, media_type TEXT, checksum TEXT, parent_id INTEGER)") cursor.execute("CREATE TABLE IF NOT EXISTS emby(emby_id TEXT, kodi_id INTEGER, media_type TEXT, checksum TEXT, parent_id INTEGER, kodi_file_id INTEGER)")
try:
cursor.execute("ALTER TABLE emby ADD COLUMN kodi_file_id INTEGER")
except: pass
connection.commit() connection.commit()
# sync movies # sync movies
@ -156,7 +160,10 @@ class LibrarySync(threading.Thread):
cursor = connection.cursor() cursor = connection.cursor()
#Add the special emby table #Add the special emby table
cursor.execute("CREATE TABLE IF NOT EXISTS emby(emby_id TEXT, kodi_id INTEGER, media_type TEXT, checksum TEXT, parent_id INTEGER)") cursor.execute("CREATE TABLE IF NOT EXISTS emby(emby_id TEXT, kodi_id INTEGER, media_type TEXT, checksum TEXT, parent_id INTEGER, kodi_file_id INTEGER)")
try:
cursor.execute("ALTER TABLE emby ADD COLUMN kodi_file_id INTEGER")
except: pass
connection.commit() connection.commit()
self.MusicFullSync(connection,cursor,pDialog) self.MusicFullSync(connection,cursor,pDialog)
@ -164,12 +171,12 @@ class LibrarySync(threading.Thread):
# set the install done setting # set the install done setting
if(syncInstallRunDone == False and completed): if(syncInstallRunDone == False and completed):
addon = xbmcaddon.Addon(id='plugin.video.emby') #force a new instance of the addon utils.settings("SyncInstallRunDone", "true")
addon.setSetting("SyncInstallRunDone", "true")
self.SaveLastSync() self.SaveLastSync()
# Commit all DB changes at once and Force refresh the library # Commit all DB changes at once and Force refresh the library
xbmc.executebuiltin("UpdateLibrary(video)") xbmc.executebuiltin("UpdateLibrary(video)")
#xbmc.executebuiltin("UpdateLibrary(music)")
# set prop to show we have run for the first time # set prop to show we have run for the first time
WINDOW.setProperty("startup", "done") WINDOW.setProperty("startup", "done")
@ -189,10 +196,9 @@ class LibrarySync(threading.Thread):
def SaveLastSync(self): def SaveLastSync(self):
# save last sync time # save last sync time
addon = xbmcaddon.Addon(id='plugin.video.emby')
lastSync = (datetime.utcnow() - timedelta(minutes=5)).strftime('%Y-%m-%dT%H:%M:%SZ') lastSync = (datetime.utcnow() - timedelta(minutes=5)).strftime('%Y-%m-%dT%H:%M:%SZ')
utils.logMsg("Sync Database", "Incremental Sync Setting Last Run Time Saved : " + lastSync, 0) self.logMsg("Sync Database, Incremental Sync Setting Last Run Time Saved: %s" % lastSync, 1)
addon.setSetting("LastIncrenetalSync", lastSync) utils.settings("LastIncrenetalSync", lastSync)
def MoviesFullSync(self,connection,cursor, pDialog): def MoviesFullSync(self,connection,cursor, pDialog):
@ -587,9 +593,8 @@ class LibrarySync(threading.Thread):
if startupDone: if startupDone:
#this will only perform sync for items received by the websocket #this will only perform sync for items received by the websocket
addon = xbmcaddon.Addon(id='plugin.video.emby') dbSyncIndication = utils.settings("dbSyncIndication") == "true"
dbSyncIndication = addon.getSetting("dbSyncIndication") == "true" performMusicSync = utils.settings("enableMusicSync") == "true"
performMusicSync = addon.getSetting("enableMusicSync") == "true"
WINDOW.setProperty("SyncDatabaseRunning", "true") WINDOW.setProperty("SyncDatabaseRunning", "true")
#show the progress dialog #show the progress dialog
@ -689,11 +694,11 @@ class LibrarySync(threading.Thread):
itemType = MBitem.get('Type', "") itemType = MBitem.get('Type', "")
if "MusicArtist" in itemType: if "MusicArtist" in itemType:
WriteKodiMusicDB().addOrUpdateArtistToKodiLibrary(MBitem,connection, cursor) WriteKodiMusicDB().addOrUpdateArtistToKodiLibrary(MBitem, connection, cursor)
if "MusicAlbum" in itemType: if "MusicAlbum" in itemType:
WriteKodiMusicDB().addOrUpdateAlbumToKodiLibrary(MBitem,connection, cursor) WriteKodiMusicDB().addOrUpdateAlbumToKodiLibrary(MBitem, connection, cursor)
if "Audio" in itemType: if "Audio" in itemType:
WriteKodiMusicDB().addOrUpdateSongToKodiLibrary(MBitem,connection, cursor) WriteKodiMusicDB().addOrUpdateSongToKodiLibrary(MBitem, connection, cursor)
connection.commit() connection.commit()
cursor.close() cursor.close()
@ -766,10 +771,7 @@ class LibrarySync(threading.Thread):
connection = connectionmusic connection = connectionmusic
cursor = cursormusic cursor = cursormusic
#Process music library #Process music library
addon = xbmcaddon.Addon() if utils.settings('enableMusicSync') == "true":
if addon.getSetting('enableMusicSync') == "true":
connection = utils.KodiSQL("music")
cursor = connection.cursor()
for item in music: for item in music:
self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteItemFromKodiLibrary (musiclibrary): " + item, 0) self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteItemFromKodiLibrary (musiclibrary): " + item, 0)
@ -786,6 +788,61 @@ class LibrarySync(threading.Thread):
doUtils.downloadUrl(url, type = "DELETE") doUtils.downloadUrl(url, type = "DELETE")
xbmc.executebuiltin("Container.Refresh") xbmc.executebuiltin("Container.Refresh")
def setUserdata(self, listItems):
# We need to sort between video and music database
video = []
music = []
# Database connection to myVideosXX.db
connectionvideo = utils.KodiSQL()
cursorvideo = connectionvideo.cursor()
# Database connection to myMusicXX.db
connectionmusic = utils.KodiSQL('music')
cursormusic = connectionmusic.cursor()
for userdata in listItems:
itemId = userdata['ItemId']
cursorvideo.execute("SELECT media_type FROM emby WHERE emby_id = ?", (itemId,))
try: # Search video database
self.logMsg("Check video database.", 1)
mediatype = cursorvideo.fetchone()[0]
video.append(userdata)
except:
cursormusic.execute("SELECT media_type FROM emby WHERE emby_id = ?", (itemId,))
try: # Search music database
self.logMsg("Check the music database.", 1)
mediatype = cursormusic.fetchone()[0]
music.append(userdata)
except: self.logMsg("Item %s is not found in Kodi database." % itemId, 2)
if len(video) > 0:
connection = connectionvideo
cursor = cursorvideo
# Process the userdata update for video library
for userdata in video:
WriteKodiVideoDB().updateUserdata(userdata, connection, cursor)
connection.commit()
xbmc.executebuiltin("UpdateLibrary(video)")
# Close connection
cursorvideo.close()
'''if len(music) > 0:
connection = connectionmusic
cursor = cursormusic
#Process music library
musicenabled = utils.settings('enableMusicSync') == "true"
# Process the userdata update for music library
if musicenabled:
for userdata in music:
WriteKodiMusicDB().updateUserdata(userdata, connection, cursor)
connection.commit()
xbmc.executebuiltin("UpdateLibrary(music)")'''
# Close connection
cursormusic.close()
self.SaveLastSync()
def remove_items(self, itemsRemoved): def remove_items(self, itemsRemoved):
# websocket client # websocket client
self.removeItems.extend(itemsRemoved) self.removeItems.extend(itemsRemoved)
@ -798,12 +855,7 @@ class LibrarySync(threading.Thread):
def user_data_update(self, userDataList): def user_data_update(self, userDataList):
# websocket client # websocket client
for userData in userDataList: self.userdataItems.extend(userDataList)
itemId = userData.get("ItemId")
if(itemId != None):
self.updateItems.append(itemId)
if(len(self.updateItems) > 0):
self.logMsg("Doing UserDataChanged : Processing Updated : " + str(self.updateItems), 0)
def ShouldStop(self): def ShouldStop(self):
@ -851,13 +903,21 @@ class LibrarySync(threading.Thread):
libSync = self.FullLibrarySync() libSync = self.FullLibrarySync()
self.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Finished) " + str(libSync), 0) self.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Finished) " + str(libSync), 0)
if len(self.updateItems) > 0: if len(self.updateItems) > 0:
# Add or update items # Add or update items
self.logMsg("Processing items: %s" % (str(self.updateItems)), 1) self.logMsg("Processing items: %s" % (str(self.updateItems)), 1)
listItems = self.updateItems listItems = self.updateItems
self.updateItems = [] self.updateItems = []
self.IncrementalSync(listItems) self.IncrementalSync(listItems)
self.SaveLastSync()
if len(self.userdataItems) > 0:
# Process userdata changes only
self.logMsg("Processing items: %s" % (str(self.userdataItems)), 1)
listItems = self.userdataItems
self.userdataItems = []
self.setUserdata(listItems)
if len(self.removeItems) > 0: if len(self.removeItems) > 0:
# Remove item from Kodi library # Remove item from Kodi library
@ -865,7 +925,6 @@ class LibrarySync(threading.Thread):
listItems = self.removeItems listItems = self.removeItems
self.removeItems = [] self.removeItems = []
self.removefromDB(listItems) self.removefromDB(listItems)
self.SaveLastSync()
if self.KodiMonitor.waitForAbort(1): if self.KodiMonitor.waitForAbort(1):
# Abort was requested while waiting. We should exit # Abort was requested while waiting. We should exit

View file

@ -21,12 +21,8 @@ class PlayUtils():
clientInfo = ClientInformation() clientInfo = ClientInformation()
addonName = clientInfo.getAddonName() addonName = clientInfo.getAddonName()
addon = xbmcaddon.Addon()
WINDOW = xbmcgui.Window(10000) WINDOW = xbmcgui.Window(10000)
audioPref = addon.getSetting('Audiopref')
subsPref = addon.getSetting('Subspref')
def __init__(self): def __init__(self):
self.__dict__ = self._shared_state self.__dict__ = self._shared_state
@ -70,9 +66,8 @@ class PlayUtils():
def isDirectPlay(self, result, dialog=False): def isDirectPlay(self, result, dialog=False):
# Requirements for Direct play: # Requirements for Direct play:
# FileSystem, Accessible path # FileSystem, Accessible path
self.addon = xbmcaddon.Addon()
playhttp = self.addon.getSetting('playFromStream') playhttp = utils.settings('playFromStream')
# User forcing to play via HTTP instead of SMB # User forcing to play via HTTP instead of SMB
if playhttp == "true": if playhttp == "true":
self.logMsg("Can't direct play: Play from HTTP is enabled.", 1) self.logMsg("Can't direct play: Play from HTTP is enabled.", 1)
@ -98,7 +93,7 @@ class PlayUtils():
resp = dialog.select('Warning: Unable to direct play.', ['Play from HTTP', 'Play from HTTP and remember next time.']) resp = dialog.select('Warning: Unable to direct play.', ['Play from HTTP', 'Play from HTTP and remember next time.'])
if resp == 1: if resp == 1:
# Remember next time # Remember next time
self.addon.setSetting('playFromStream', "true") utils.settings('playFromStream', "true")
elif resp < 0: elif resp < 0:
# User decided not to proceed. # User decided not to proceed.
self.logMsg("User cancelled HTTP selection dialog.", 1) self.logMsg("User cancelled HTTP selection dialog.", 1)
@ -109,7 +104,6 @@ class PlayUtils():
def directPlay(self, result): def directPlay(self, result):
addon = self.addon
try: try:
try: try:
playurl = result[u'MediaSources'][0][u'Path'] playurl = result[u'MediaSources'][0][u'Path']
@ -128,8 +122,8 @@ class PlayUtils():
# Network - SMB protocol # Network - SMB protocol
if "\\\\" in playurl: if "\\\\" in playurl:
smbuser = addon.getSetting('smbusername') smbuser = utils.settings('smbusername')
smbpass = addon.getSetting('smbpassword') smbpass = utils.settings('smbpassword')
# Network share # Network share
if smbuser: if smbuser:
playurl = playurl.replace("\\\\", "smb://%s:%s@" % (smbuser, smbpass)) playurl = playurl.replace("\\\\", "smb://%s:%s@" % (smbuser, smbpass))
@ -238,7 +232,7 @@ class PlayUtils():
def getVideoBitRate(self): def getVideoBitRate(self):
# get the addon video quality # get the addon video quality
videoQuality = self.addon.getSetting('videoBitRate') videoQuality = utils.settings('videoBitRate')
if (videoQuality == "0"): if (videoQuality == "0"):
return 664 return 664

View file

@ -16,11 +16,10 @@ from ReadKodiDB import ReadKodiDB
from ReadEmbyDB import ReadEmbyDB from ReadEmbyDB import ReadEmbyDB
import Utils as utils import Utils as utils
from API import API from API import API
import Utils as utils
import os import os
import xbmcvfs import xbmcvfs
addon = xbmcaddon.Addon(id='plugin.video.emby') addon = xbmcaddon.Addon()
addondir = xbmc.translatePath(addon.getAddonInfo('profile')) addondir = xbmc.translatePath(addon.getAddonInfo('profile'))
WINDOW = xbmcgui.Window( 10000 ) WINDOW = xbmcgui.Window( 10000 )
@ -54,7 +53,7 @@ class PlaybackUtils():
# BOOKMARK - RESUME POINT # BOOKMARK - RESUME POINT
timeInfo = API().getTimeInfo(result) timeInfo = API().getTimeInfo(result)
jumpBackSec = int(addon.getSetting("resumeJumpBack")) jumpBackSec = int(utils.settings("resumeJumpBack"))
seekTime = round(float(timeInfo.get('ResumeTime')), 6) seekTime = round(float(timeInfo.get('ResumeTime')), 6)
if seekTime > jumpBackSec: if seekTime > jumpBackSec:
# To avoid negative bookmark # To avoid negative bookmark

View file

@ -33,8 +33,6 @@ class Player( xbmc.Player ):
ws = WebSocketThread() ws = WebSocketThread()
addonName = clientInfo.getAddonName() addonName = clientInfo.getAddonName()
addonId = clientInfo.getAddonId()
addon = xbmcaddon.Addon(id=addonId)
WINDOW = xbmcgui.Window(10000) WINDOW = xbmcgui.Window(10000)
@ -73,7 +71,6 @@ class Player( xbmc.Player ):
if(len(self.played_information) == 0): if(len(self.played_information) == 0):
return return
addonSettings = xbmcaddon.Addon(id='plugin.video.emby')
self.logMsg("emby Service -> played_information : " + str(self.played_information)) self.logMsg("emby Service -> played_information : " + str(self.played_information))
for item_url in self.played_information: for item_url in self.played_information:
@ -107,9 +104,9 @@ class Player( xbmc.Player ):
self.stopPlayback(data) self.stopPlayback(data)
offerDelete=False offerDelete=False
if data.get("Type") == "Episode" and addonSettings.getSetting("offerDeleteTV")=="true": if data.get("Type") == "Episode" and utils.settings("offerDeleteTV")=="true":
offerDelete = True offerDelete = True
elif data.get("Type") == "Movie" and addonSettings.getSetting("offerDeleteMovies")=="true": elif data.get("Type") == "Movie" and utils.settings("offerDeleteMovies")=="true":
offerDelete = True offerDelete = True
if percentComplete > .80 and offerDelete == True: if percentComplete > .80 and offerDelete == True:
@ -258,7 +255,6 @@ class Player( xbmc.Player ):
def onPlayBackStarted( self ): def onPlayBackStarted( self ):
# Will be called when xbmc starts playing a file # Will be called when xbmc starts playing a file
WINDOW = xbmcgui.Window(10000) WINDOW = xbmcgui.Window(10000)
addon = self.addon
xbmcplayer = self.xbmcplayer xbmcplayer = self.xbmcplayer
self.stopAll() self.stopAll()

View file

@ -29,8 +29,7 @@ class UserClient(threading.Thread):
KodiMonitor = KodiMonitor.Kodi_Monitor() KodiMonitor = KodiMonitor.Kodi_Monitor()
addonName = clientInfo.getAddonName() addonName = clientInfo.getAddonName()
addonId = clientInfo.getAddonId() addon = xbmcaddon.Addon()
addon = xbmcaddon.Addon(id=addonId)
WINDOW = xbmcgui.Window(10000) WINDOW = xbmcgui.Window(10000)
stopClient = False stopClient = False
@ -57,8 +56,7 @@ class UserClient(threading.Thread):
def getUsername(self): def getUsername(self):
addon = xbmcaddon.Addon(id=self.addonId) username = utils.settings('username')
username = addon.getSetting('username')
if (username == ""): if (username == ""):
self.logMsg("No username saved.", 2) self.logMsg("No username saved.", 2)
@ -69,7 +67,7 @@ class UserClient(threading.Thread):
def getLogLevel(self): def getLogLevel(self):
try: try:
logLevel = int(self.addon.getSetting('logLevel')) logLevel = int(utils.settings('logLevel'))
except: except:
logLevel = 0 logLevel = 0
@ -79,7 +77,7 @@ class UserClient(threading.Thread):
username = self.getUsername() username = self.getUsername()
w_userId = self.WINDOW.getProperty('userId%s' % username) w_userId = self.WINDOW.getProperty('userId%s' % username)
s_userId = self.addon.getSetting('userId%s' % username) s_userId = utils.settings('userId%s' % username)
# Verify the window property # Verify the window property
if (w_userId != ""): if (w_userId != ""):
@ -97,13 +95,12 @@ class UserClient(threading.Thread):
def getServer(self, prefix=True): def getServer(self, prefix=True):
# For https support # For https support
addon = xbmcaddon.Addon(id=self.addonId) HTTPS = utils.settings('https')
HTTPS = addon.getSetting('https') host = utils.settings('ipaddress')
host = addon.getSetting('ipaddress') port = utils.settings('port')
port = addon.getSetting('port')
# Alternate host # Alternate host
if addon.getSetting('altip') == "true": if utils.settings('altip') == "true":
host = addon.getSetting('secondipaddress') host = utils.settings('secondipaddress')
server = host + ":" + port server = host + ":" + port
@ -127,7 +124,7 @@ class UserClient(threading.Thread):
username = self.getUsername() username = self.getUsername()
w_token = self.WINDOW.getProperty('accessToken%s' % username) w_token = self.WINDOW.getProperty('accessToken%s' % username)
s_token = self.addon.getSetting('accessToken') s_token = utils.settings('accessToken')
# Verify the window property # Verify the window property
if (w_token != ""): if (w_token != ""):
@ -144,7 +141,7 @@ class UserClient(threading.Thread):
def getSSLverify(self): def getSSLverify(self):
# Verify host certificate # Verify host certificate
s_sslverify = self.addon.getSetting('sslverify') s_sslverify = utils.settings('sslverify')
if s_sslverify == "true": if s_sslverify == "true":
return True return True
@ -153,7 +150,7 @@ class UserClient(threading.Thread):
def getSSL(self): def getSSL(self):
# Client side certificate # Client side certificate
s_cert = self.addon.getSetting('sslcert') s_cert = utils.settings('sslcert')
if s_cert == "None": if s_cert == "None":
return None return None
@ -165,22 +162,10 @@ class UserClient(threading.Thread):
player = Player() player = Player()
server = self.getServer() server = self.getServer()
userId = self.getUserId() userId = self.getUserId()
addon = self.addon
url = "{server}/mediabrowser/Users/{UserId}?format=json" url = "{server}/mediabrowser/Users/{UserId}?format=json"
result = self.doUtils.downloadUrl(url) result = self.doUtils.downloadUrl(url)
audio = result[u'Configuration'].get(u'AudioLanguagePreference', "default")
subs = result[u'Configuration'].get(u'SubtitleLanguagePreference', "default")
addon.setSetting('Audiopref', audio)
addon.setSetting('Subspref', subs)
# Set the setting in Player
player.setAudioSubsPref(audio.encode('utf-8'), subs.encode('utf-8'))
self.logMsg("Audio preference: %s" % audio, 2)
self.logMsg("Subtitles preference: %s" % subs, 2)
# Set user image for skin display # Set user image for skin display
self.WINDOW.setProperty("EmbyUserImage",API().getUserArtwork(result,"Primary")) self.WINDOW.setProperty("EmbyUserImage",API().getUserArtwork(result,"Primary"))
@ -279,7 +264,7 @@ class UserClient(threading.Thread):
username = self.getUsername() username = self.getUsername()
server = self.getServer() server = self.getServer()
addondir = xbmc.translatePath(self.addon.getAddonInfo('profile')) addondir = xbmc.translatePath(self.addon.getAddonInfo('profile')).decode('utf-8')
hasSettings = xbmcvfs.exists("%ssettings.xml" % addondir) hasSettings = xbmcvfs.exists("%ssettings.xml" % addondir)
# If there's no settings.xml # If there's no settings.xml
@ -351,8 +336,8 @@ class UserClient(threading.Thread):
self.currUser = username self.currUser = username
xbmcgui.Dialog().notification("Emby server", "Welcome %s!" % self.currUser) xbmcgui.Dialog().notification("Emby server", "Welcome %s!" % self.currUser)
userId = result[u'User'][u'Id'] userId = result[u'User'][u'Id']
addon.setSetting("accessToken", accessToken) utils.settings("accessToken", accessToken)
addon.setSetting("userId%s" % username, userId) utils.settings("userId%s" % username, userId)
self.logMsg("User Authenticated: %s" % accessToken) self.logMsg("User Authenticated: %s" % accessToken)
self.loadCurrUser(authenticated=True) self.loadCurrUser(authenticated=True)
self.WINDOW.setProperty("Server_status", "") self.WINDOW.setProperty("Server_status", "")
@ -360,8 +345,8 @@ class UserClient(threading.Thread):
return return
else: else:
self.logMsg("User authentication failed.") self.logMsg("User authentication failed.")
addon.setSetting("accessToken", "") utils.settings("accessToken", "")
addon.setSetting("userId%s" % username, "") utils.settings("userId%s" % username, "")
xbmcgui.Dialog().ok("Error connecting", "Invalid username or password.") xbmcgui.Dialog().ok("Error connecting", "Invalid username or password.")
# Give two attempts at entering password # Give two attempts at entering password
@ -380,7 +365,7 @@ class UserClient(threading.Thread):
self.logMsg("Reset UserClient authentication.", 1) self.logMsg("Reset UserClient authentication.", 1)
if (self.currToken != None): if (self.currToken != None):
# In case of 401, removed saved token # In case of 401, removed saved token
self.addon.setSetting("accessToken", "") utils.settings("accessToken", "")
self.WINDOW.setProperty("accessToken%s" % username, "") self.WINDOW.setProperty("accessToken%s" % username, "")
self.currToken = None self.currToken = None
self.logMsg("User token has been removed.", 1) self.logMsg("User token has been removed.", 1)
@ -396,8 +381,6 @@ class UserClient(threading.Thread):
while not self.KodiMonitor.abortRequested(): while not self.KodiMonitor.abortRequested():
# Get the latest addon settings
self.addon = xbmcaddon.Addon(id=self.addonId)
# Verify the log level # Verify the log level
currLogLevel = self.getLogLevel() currLogLevel = self.getLogLevel()
if self.logLevel != currLogLevel: if self.logLevel != currLogLevel:
@ -448,6 +431,7 @@ class UserClient(threading.Thread):
# Abort was requested while waiting. We should exit # Abort was requested while waiting. We should exit
break break
self.doUtils.stopSession()
self.logMsg("|---- UserClient Stopped ----|", 0) self.logMsg("|---- UserClient Stopped ----|", 0)
def stopClient(self): def stopClient(self):

View file

@ -20,6 +20,7 @@ import unicodedata
from API import API from API import API
from PlayUtils import PlayUtils from PlayUtils import PlayUtils
from DownloadUtils import DownloadUtils from DownloadUtils import DownloadUtils
downloadUtils = DownloadUtils() downloadUtils = DownloadUtils()
addon = xbmcaddon.Addon() addon = xbmcaddon.Addon()
language = addon.getLocalizedString language = addon.getLocalizedString
@ -184,7 +185,7 @@ def createSources():
'</sources>' '</sources>'
) )
def settings(setting, value=""): def settings(setting, value = None):
# Get or add addon setting # Get or add addon setting
addon = xbmcaddon.Addon() addon = xbmcaddon.Addon()
if value: if value:
@ -231,6 +232,11 @@ def normalize_nodes(text):
return text return text
def reloadProfile():
# Useful to reload the add-on without restarting Kodi.
profile = xbmc.getInfoLabel('System.ProfileName')
xbmc.executebuiltin("LoadProfile(%s)" % profile)
def reset(): def reset():
@ -252,10 +258,17 @@ def reset():
if file.startswith("emby"): if file.startswith("emby"):
xbmcvfs.delete(path + file) xbmcvfs.delete(path + file)
settings('SyncInstallRunDone', "false")
# Ask if user information should be deleted too. # Ask if user information should be deleted too.
return_user = xbmcgui.Dialog().yesno("Warning", "Reset all Emby Addon settings?") return_user = xbmcgui.Dialog().yesno("Warning", "Reset all Emby Addon settings?")
if return_user == 1: if return_user == 1:
WINDOW.setProperty('deletesettings', "true") WINDOW.setProperty('deletesettings', "true")
addon = xbmcaddon.Addon()
addondir = xbmc.translatePath(addon.getAddonInfo('profile')).decode('utf-8')
dataPath = "%ssettings.xml" % addondir
xbmcvfs.delete(dataPath)
logMsg("EMBY", "Deleting: settings.xml", 1)
# first stop any db sync # first stop any db sync
WINDOW.setProperty("SyncDatabaseShouldStop", "true") WINDOW.setProperty("SyncDatabaseShouldStop", "true")
@ -283,7 +296,7 @@ def reset():
connection.commit() connection.commit()
cursor.close() cursor.close()
if addon.getSetting("enableMusicSync") == "true": if settings('enableMusicSync') == "true":
# delete video db table data # delete video db table data
print "Doing Music DB Reset" print "Doing Music DB Reset"
connection = KodiSQL("music") connection = KodiSQL("music")
@ -299,8 +312,13 @@ def reset():
# reset the install run flag # reset the install run flag
WINDOW.setProperty("SyncInstallRunDone", "false") #settings('SyncInstallRunDone', "false")
#WINDOW.setProperty("SyncInstallRunDone", "false")
dialog = xbmcgui.Dialog() dialog = xbmcgui.Dialog()
# Reload would work instead of restart since the add-on is a service.
#dialog.ok('Emby Reset', 'Database reset has completed, Kodi will now restart to apply the changes.')
#WINDOW.clearProperty("SyncDatabaseShouldStop")
#reloadProfile()
dialog.ok('Emby Reset', 'Database reset has completed, Kodi will now restart to apply the changes.') dialog.ok('Emby Reset', 'Database reset has completed, Kodi will now restart to apply the changes.')
xbmc.executebuiltin("RestartApp") xbmc.executebuiltin("RestartApp")

View file

@ -18,7 +18,7 @@ import Utils as utils
from ReadEmbyDB import ReadEmbyDB from ReadEmbyDB import ReadEmbyDB
WINDOW = xbmcgui.Window(10000) WINDOW = xbmcgui.Window(10000)
addonSettings = xbmcaddon.Addon(id='plugin.video.emby') addonSettings = xbmcaddon.Addon()
language = addonSettings.getLocalizedString language = addonSettings.getLocalizedString
class VideoNodes(): class VideoNodes():

View file

@ -79,7 +79,6 @@ class WebSocketThread(threading.Thread):
def on_message(self, ws, message): def on_message(self, ws, message):
WINDOW = xbmcgui.Window(10000) WINDOW = xbmcgui.Window(10000)
addon = xbmcaddon.Addon()
self.logMsg("Message: %s" % message, 1) self.logMsg("Message: %s" % message, 1)
result = json.loads(message) result = json.loads(message)
@ -229,7 +228,7 @@ class WebSocketThread(threading.Thread):
self.logMsg("Unknown command.", 1) self.logMsg("Unknown command.", 1)
elif messageType == "ServerRestarting": elif messageType == "ServerRestarting":
if addon.getSetting('supressRestartMsg') == "true": if utils.settings('supressRestartMsg') == "true":
xbmcgui.Dialog().notification("Emby server", "Server is restarting.", icon="special://home/addons/plugin.video.emby/icon.png") xbmcgui.Dialog().notification("Emby server", "Server is restarting.", icon="special://home/addons/plugin.video.emby/icon.png")
def on_error(self, ws, error): def on_error(self, ws, error):

View file

@ -26,7 +26,6 @@ class WriteKodiMusicDB():
textureCache = TextureCache() textureCache = TextureCache()
kodiversion = int(xbmc.getInfoLabel("System.BuildVersion")[:2]) kodiversion = int(xbmc.getInfoLabel("System.BuildVersion")[:2])
addon = xbmcaddon.Addon()
addonName = ClientInformation().getAddonName() addonName = ClientInformation().getAddonName()
WINDOW = xbmcgui.Window(10000) WINDOW = xbmcgui.Window(10000)
@ -34,7 +33,7 @@ class WriteKodiMusicDB():
userid = WINDOW.getProperty('userId%s' % username) userid = WINDOW.getProperty('userId%s' % username)
server = WINDOW.getProperty('server%s' % username) server = WINDOW.getProperty('server%s' % username)
directpath = addon.getSetting('useDirectPaths') == "true" directpath = utils.settings('useDirectPaths') == "true"
def logMsg(self, msg, lvl = 1): def logMsg(self, msg, lvl = 1):

View file

@ -26,7 +26,6 @@ class WriteKodiVideoDB():
doUtils = DownloadUtils() doUtils = DownloadUtils()
kodiversion = int(xbmc.getInfoLabel("System.BuildVersion")[:2]) kodiversion = int(xbmc.getInfoLabel("System.BuildVersion")[:2])
addon = xbmcaddon.Addon()
addonName = ClientInformation().getAddonName() addonName = ClientInformation().getAddonName()
WINDOW = xbmcgui.Window(10000) WINDOW = xbmcgui.Window(10000)
@ -34,7 +33,7 @@ class WriteKodiVideoDB():
userid = WINDOW.getProperty('userId%s' % username) userid = WINDOW.getProperty('userId%s' % username)
server = WINDOW.getProperty('server%s' % username) server = WINDOW.getProperty('server%s' % username)
directpath = addon.getSetting('useDirectPaths') == "true" directpath = utils.settings('useDirectPaths') == "true"
def logMsg(self, msg, lvl = 1): def logMsg(self, msg, lvl = 1):
@ -73,7 +72,6 @@ class WriteKodiVideoDB():
def addOrUpdateMovieToKodiLibrary(self, embyId, connection, cursor, viewTag): def addOrUpdateMovieToKodiLibrary(self, embyId, connection, cursor, viewTag):
addon = self.addon
MBitem = ReadEmbyDB().getFullItem(embyId) MBitem = ReadEmbyDB().getFullItem(embyId)
if not MBitem: if not MBitem:
@ -222,8 +220,8 @@ class WriteKodiVideoDB():
self.AddTagToMedia(movieid, viewTag, "movie", cursor) self.AddTagToMedia(movieid, viewTag, "movie", cursor)
# Create the reference in emby table # Create the reference in emby table
query = "INSERT INTO emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)" query = "INSERT INTO emby(emby_id, kodi_id, kodi_file_id, media_type, checksum) values(?, ?, ?, ?, ?)"
cursor.execute(query, (embyId, movieid, "movie", checksum)) cursor.execute(query, (embyId, movieid, fileid, "movie", checksum))
# Update or insert actors # Update or insert actors
@ -260,7 +258,7 @@ class WriteKodiVideoDB():
# Set resume point and round to 6th decimal # Set resume point and round to 6th decimal
resume = round(float(timeInfo.get('ResumeTime')), 6) resume = round(float(timeInfo.get('ResumeTime')), 6)
total = round(float(timeInfo.get('TotalTime')), 6) total = round(float(timeInfo.get('TotalTime')), 6)
jumpback = int(addon.getSetting('resumeJumpBack')) jumpback = int(utils.settings('resumeJumpBack'))
if resume > jumpback: if resume > jumpback:
# To avoid negative bookmark # To avoid negative bookmark
resume = resume - jumpback resume = resume - jumpback
@ -268,7 +266,6 @@ class WriteKodiVideoDB():
def addOrUpdateMusicVideoToKodiLibrary( self, embyId ,connection, cursor): def addOrUpdateMusicVideoToKodiLibrary( self, embyId ,connection, cursor):
addon = xbmcaddon.Addon(id='plugin.video.emby')
WINDOW = xbmcgui.Window(10000) WINDOW = xbmcgui.Window(10000)
username = WINDOW.getProperty('currUser') username = WINDOW.getProperty('currUser')
userid = WINDOW.getProperty('userId%s' % username) userid = WINDOW.getProperty('userId%s' % username)
@ -433,7 +430,6 @@ class WriteKodiVideoDB():
def addOrUpdateTvShowToKodiLibrary(self, embyId, connection, cursor, viewTag ): def addOrUpdateTvShowToKodiLibrary(self, embyId, connection, cursor, viewTag ):
addon = self.addon
MBitem = ReadEmbyDB().getFullItem(embyId) MBitem = ReadEmbyDB().getFullItem(embyId)
if not MBitem: if not MBitem:
@ -571,7 +567,6 @@ class WriteKodiVideoDB():
def addOrUpdateEpisodeToKodiLibrary(self, embyId, showid, connection, cursor): def addOrUpdateEpisodeToKodiLibrary(self, embyId, showid, connection, cursor):
addon = self.addon
MBitem = ReadEmbyDB().getFullItem(embyId) MBitem = ReadEmbyDB().getFullItem(embyId)
if not MBitem: if not MBitem:
@ -708,8 +703,8 @@ class WriteKodiVideoDB():
cursor.execute(query, (episodeid, fileid, title, plot, rating, writer, premieredate, runtime, director, season, episode, title, showid, "-1", "-1")) cursor.execute(query, (episodeid, fileid, title, plot, rating, writer, premieredate, runtime, director, season, episode, title, showid, "-1", "-1"))
# Create the reference in emby table # Create the reference in emby table
query = "INSERT INTO emby(emby_id, kodi_id, media_type, checksum, parent_id) values(?, ?, ?, ?, ?)" query = "INSERT INTO emby(emby_id, kodi_id, kodi_file_id, media_type, checksum, parent_id) values(?, ?, ?, ?, ?, ?)"
cursor.execute(query, (embyId, episodeid, "episode", checksum, showid)) cursor.execute(query, (embyId, episodeid, fileid, "episode", checksum, showid))
# Update or insert actors # Update or insert actors
self.AddPeopleToMedia(episodeid, MBitem.get('People'), "episode", connection, cursor) self.AddPeopleToMedia(episodeid, MBitem.get('People'), "episode", connection, cursor)
@ -723,7 +718,7 @@ class WriteKodiVideoDB():
# Set resume point and round to 6th decimal # Set resume point and round to 6th decimal
resume = round(float(timeInfo.get('ResumeTime')), 6) resume = round(float(timeInfo.get('ResumeTime')), 6)
total = round(float(timeInfo.get('TotalTime')), 6) total = round(float(timeInfo.get('TotalTime')), 6)
jumpback = int(addon.getSetting('resumeJumpBack')) jumpback = int(utils.settings('resumeJumpBack'))
if resume > jumpback: if resume > jumpback:
# To avoid negative bookmark # To avoid negative bookmark
resume = resume - jumpback resume = resume - jumpback

View file

@ -10,8 +10,8 @@ import xbmc
import xbmcgui import xbmcgui
import xbmcvfs import xbmcvfs
addon_ = xbmcaddon.Addon(id='plugin.video.emby') _addon = xbmcaddon.Addon(id='plugin.video.emby')
addon_path = addon_.getAddonInfo('path').decode('utf-8') addon_path = _addon.getAddonInfo('path').decode('utf-8')
base_resource_path = xbmc.translatePath(os.path.join(addon_path, 'resources', 'lib')).decode('utf-8') base_resource_path = xbmc.translatePath(os.path.join(addon_path, 'resources', 'lib')).decode('utf-8')
sys.path.append(base_resource_path) sys.path.append(base_resource_path)
@ -90,7 +90,6 @@ class Service():
def ServiceEntryPoint(self): def ServiceEntryPoint(self):
WINDOW = self.WINDOW WINDOW = self.WINDOW
addon = xbmcaddon.Addon()
# Server auto-detect # Server auto-detect
ConnectionManager().checkServer() ConnectionManager().checkServer()
@ -106,9 +105,6 @@ class Service():
while not self.KodiMonitor.abortRequested(): while not self.KodiMonitor.abortRequested():
# Refresh with the latest addon settings
addon = xbmcaddon.Addon()
# Before proceeding, need to make sure: # Before proceeding, need to make sure:
# 1. Server is online # 1. Server is online
# 2. User is set # 2. User is set
@ -153,7 +149,7 @@ class Service():
else: else:
# Start up events # Start up events
self.warn_auth = True self.warn_auth = True
if addon.getSetting('supressConnectMsg') == "false": if utils.settings('supressConnectMsg') == "false":
if self.welcome_msg: if self.welcome_msg:
# Reset authentication warnings # Reset authentication warnings
self.welcome_msg = False self.welcome_msg = False
@ -237,16 +233,6 @@ class Service():
# Abort was requested while waiting. We should exit # Abort was requested while waiting. We should exit
break break
# If user reset library database.
if WINDOW.getProperty('SyncInstallRunDone') == "false":
addon.setSetting('SyncInstallRunDone', "false")
# If user delete Emby settings
if WINDOW.getProperty('deletesettings') == "true":
addondir = xbmc.translatePath(addon.getAddonInfo('profile')).decode('utf-8')
dataPath = "%ssettings.xml" % addondir
xbmcvfs.delete(dataPath)
self.logMsg("Deleting: settings.xml", 1)
if (self.newWebSocketThread is not None): if (self.newWebSocketThread is not None):
ws.stopClient() ws.stopClient()