refactor WriteKodiDB.py to WriteKodiVideoDB.py in preparation of adding musicDb support later on

This commit is contained in:
Marcel van der Veldt 2015-05-07 11:45:24 +02:00
parent f3e7ac350d
commit 24c4d267c4
4 changed files with 27 additions and 27 deletions

View file

@ -9,7 +9,7 @@ import xbmcaddon
import json import json
import Utils as utils import Utils as utils
from WriteKodiDB import WriteKodiDB from WriteKodiVideoDB import WriteKodiVideoDB
from ReadKodiDB import ReadKodiDB from ReadKodiDB import ReadKodiDB
from LibrarySync import LibrarySync from LibrarySync import LibrarySync
from PlayUtils import PlayUtils from PlayUtils import PlayUtils
@ -46,7 +46,7 @@ class Kodi_Monitor(xbmc.Monitor):
if (playcount != None) and (prop != "true"): if (playcount != None) and (prop != "true"):
WINDOW.setProperty("Played%s%s" % (type,item), "true") WINDOW.setProperty("Played%s%s" % (type,item), "true")
utils.logMsg("MB# Sync","Kodi_Monitor--> VideoLibrary.OnUpdate : " + str(data),2) utils.logMsg("MB# Sync","Kodi_Monitor--> VideoLibrary.OnUpdate : " + str(data),2)
WriteKodiDB().updatePlayCountFromKodi(item, type, playcount) WriteKodiVideoDB().updatePlayCountFromKodi(item, type, playcount)
self.clearProperty(type,item) self.clearProperty(type,item)

View file

@ -21,7 +21,7 @@ import Utils as utils
from DownloadUtils import DownloadUtils from DownloadUtils import DownloadUtils
from ReadEmbyDB import ReadEmbyDB from ReadEmbyDB import ReadEmbyDB
from ReadKodiDB import ReadKodiDB from ReadKodiDB import ReadKodiDB
from WriteKodiDB import WriteKodiDB from WriteKodiVideoDB import WriteKodiVideoDB
from VideoNodes import VideoNodes from VideoNodes import VideoNodes
addondir = xbmc.translatePath(xbmcaddon.Addon(id='plugin.video.emby').getAddonInfo('profile')) addondir = xbmc.translatePath(xbmcaddon.Addon(id='plugin.video.emby').getAddonInfo('profile'))
@ -142,10 +142,10 @@ class LibrarySync():
kodiMovie = kodimovie kodiMovie = kodimovie
if kodiMovie == None: if kodiMovie == None:
WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) WriteKodiVideoDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
else: else:
if kodiMovie[2] != API().getChecksum(item): if kodiMovie[2] != API().getChecksum(item):
WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) WriteKodiVideoDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
@ -163,12 +163,12 @@ class LibrarySync():
if(self.ShouldStop()): if(self.ShouldStop()):
return False return False
boxsetMovies = ReadEmbyDB().getMoviesInBoxSet(boxset["Id"]) boxsetMovies = ReadEmbyDB().getMoviesInBoxSet(boxset["Id"])
WriteKodiDB().addBoxsetToKodiLibrary(boxset,connection, cursor) WriteKodiVideoDB().addBoxsetToKodiLibrary(boxset,connection, cursor)
for boxsetMovie in boxsetMovies: for boxsetMovie in boxsetMovies:
if(self.ShouldStop()): if(self.ShouldStop()):
return False return False
WriteKodiDB().updateBoxsetToKodiLibrary(boxsetMovie,boxset, connection, cursor) WriteKodiVideoDB().updateBoxsetToKodiLibrary(boxsetMovie,boxset, connection, cursor)
utils.logMsg("Sync Movies", "BoxSet Sync Finished", 1) utils.logMsg("Sync Movies", "BoxSet Sync Finished", 1)
@ -177,7 +177,7 @@ class LibrarySync():
for kodiId in allKodiMovieIds: for kodiId in allKodiMovieIds:
if not kodiId in allEmbyMovieIds: if not kodiId in allEmbyMovieIds:
WINDOW.setProperty(kodiId,"deleted") WINDOW.setProperty(kodiId,"deleted")
WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor) WriteKodiVideoDB().deleteItemFromKodiLibrary(kodiId, connection, cursor)
### commit all changes to database ### ### commit all changes to database ###
connection.commit() connection.commit()
@ -216,17 +216,17 @@ class LibrarySync():
kodiVideo = kodivideo kodiVideo = kodivideo
if kodiVideo == None: if kodiVideo == None:
WriteKodiDB().addOrUpdateMusicVideoToKodiLibrary(item["Id"],connection, cursor) WriteKodiVideoDB().addOrUpdateMusicVideoToKodiLibrary(item["Id"],connection, cursor)
else: else:
if kodiVideo[2] != API().getChecksum(item): if kodiVideo[2] != API().getChecksum(item):
WriteKodiDB().addOrUpdateMusicVideoToKodiLibrary(item["Id"],connection, cursor) WriteKodiVideoDB().addOrUpdateMusicVideoToKodiLibrary(item["Id"],connection, cursor)
#### PROCESS DELETES ##### #### PROCESS DELETES #####
allEmbyMusicvideoIds = set(allEmbyMusicvideoIds) allEmbyMusicvideoIds = set(allEmbyMusicvideoIds)
for kodiId in allKodiMusicvideoIds: for kodiId in allKodiMusicvideoIds:
if not kodiId in allEmbyMusicvideoIds: if not kodiId in allEmbyMusicvideoIds:
WINDOW.setProperty(kodiId,"deleted") WINDOW.setProperty(kodiId,"deleted")
WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor) WriteKodiVideoDB().deleteItemFromKodiLibrary(kodiId, connection, cursor)
### commit all changes to database ### ### commit all changes to database ###
connection.commit() connection.commit()
@ -271,11 +271,11 @@ class LibrarySync():
if kodiShow == None: if kodiShow == None:
# Tv show doesn't exist in Kodi yet so proceed and add it # Tv show doesn't exist in Kodi yet so proceed and add it
WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title')) WriteKodiVideoDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
else: else:
# If there are changes to the item, perform a full sync of the item # If there are changes to the item, perform a full sync of the item
if kodiShow[2] != API().getChecksum(item): if kodiShow[2] != API().getChecksum(item):
WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title')) WriteKodiVideoDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
#### PROCESS EPISODES ###### #### PROCESS EPISODES ######
self.EpisodesFullSync(connection,cursor,item["Id"]) self.EpisodesFullSync(connection,cursor,item["Id"])
@ -285,7 +285,7 @@ class LibrarySync():
for kodiId in allKodiTvShowIds: for kodiId in allKodiTvShowIds:
if not kodiId in allEmbyTvShowIds: if not kodiId in allEmbyTvShowIds:
WINDOW.setProperty(kodiId,"deleted") WINDOW.setProperty(kodiId,"deleted")
WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor) WriteKodiVideoDB().deleteItemFromKodiLibrary(kodiId, connection, cursor)
### commit all changes to database ### ### commit all changes to database ###
connection.commit() connection.commit()
@ -323,18 +323,18 @@ class LibrarySync():
if kodiEpisode == None: if kodiEpisode == None:
# Episode doesn't exist in Kodi yet so proceed and add it # Episode doesn't exist in Kodi yet so proceed and add it
WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodiShowId, connection, cursor) WriteKodiVideoDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodiShowId, connection, cursor)
else: else:
# If there are changes to the item, perform a full sync of the item # If there are changes to the item, perform a full sync of the item
if kodiEpisode[2] != API().getChecksum(item): if kodiEpisode[2] != API().getChecksum(item):
WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodiShowId, connection, cursor) WriteKodiVideoDB().addOrUpdateEpisodeToKodiLibrary(item["Id"], kodiShowId, connection, cursor)
#### EPISODES: PROCESS DELETES ##### #### EPISODES: PROCESS DELETES #####
allEmbyEpisodeIds = set(allEmbyEpisodeIds) allEmbyEpisodeIds = set(allEmbyEpisodeIds)
for kodiId in allKodiEpisodeIds: for kodiId in allKodiEpisodeIds:
if (not kodiId in allEmbyEpisodeIds): if (not kodiId in allEmbyEpisodeIds):
WINDOW.setProperty(kodiId,"deleted") WINDOW.setProperty(kodiId,"deleted")
WriteKodiDB().deleteItemFromKodiLibrary(kodiId, connection, cursor) WriteKodiVideoDB().deleteItemFromKodiLibrary(kodiId, connection, cursor)
def IncrementalSync(self, itemList): def IncrementalSync(self, itemList):
@ -360,7 +360,7 @@ class LibrarySync():
for item in allEmbyMovies: for item in allEmbyMovies:
if not item.get('IsFolder'): if not item.get('IsFolder'):
WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title')) WriteKodiVideoDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
#### PROCESS BOX SETS ##### #### PROCESS BOX SETS #####
@ -368,10 +368,10 @@ class LibrarySync():
for boxset in boxsets: for boxset in boxsets:
boxsetMovies = ReadEmbyDB().getMoviesInBoxSet(boxset["Id"]) boxsetMovies = ReadEmbyDB().getMoviesInBoxSet(boxset["Id"])
WriteKodiDB().addBoxsetToKodiLibrary(boxset,connection, cursor) WriteKodiVideoDB().addBoxsetToKodiLibrary(boxset,connection, cursor)
for boxsetMovie in boxsetMovies: for boxsetMovie in boxsetMovies:
WriteKodiDB().updateBoxsetToKodiLibrary(boxsetMovie,boxset, connection, cursor) WriteKodiVideoDB().updateBoxsetToKodiLibrary(boxsetMovie,boxset, connection, cursor)
#### PROCESS TV SHOWS #### #### PROCESS TV SHOWS ####
@ -380,7 +380,7 @@ class LibrarySync():
allEmbyTvShows = ReadEmbyDB().getTvShows(view.get('id'),itemList) allEmbyTvShows = ReadEmbyDB().getTvShows(view.get('id'),itemList)
for item in allEmbyTvShows: for item in allEmbyTvShows:
if item.get('IsFolder') and item.get('RecursiveItemCount') != 0: if item.get('IsFolder') and item.get('RecursiveItemCount') != 0:
kodiId = WriteKodiDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title')) kodiId = WriteKodiVideoDB().addOrUpdateTvShowToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
#### PROCESS EPISODES ###### #### PROCESS EPISODES ######
for item in itemList: for item in itemList:
@ -397,13 +397,13 @@ class LibrarySync():
kodi_show_id = None kodi_show_id = None
if kodi_show_id: if kodi_show_id:
WriteKodiDB().addOrUpdateEpisodeToKodiLibrary(MBitem["Id"], kodi_show_id, connection, cursor) WriteKodiVideoDB().addOrUpdateEpisodeToKodiLibrary(MBitem["Id"], kodi_show_id, connection, cursor)
#### PROCESS MUSICVIDEOS #### #### PROCESS MUSICVIDEOS ####
allEmbyMusicvideos = ReadEmbyDB().getMusicVideos(itemList) allEmbyMusicvideos = ReadEmbyDB().getMusicVideos(itemList)
for item in allEmbyMusicvideos: for item in allEmbyMusicvideos:
if not item.get('IsFolder'): if not item.get('IsFolder'):
WriteKodiDB().addOrUpdateMusicVideoToKodiLibrary(item["Id"],connection, cursor) WriteKodiVideoDB().addOrUpdateMusicVideoToKodiLibrary(item["Id"],connection, cursor)
### commit all changes to database ### ### commit all changes to database ###
connection.commit() connection.commit()

View file

@ -19,7 +19,7 @@ from ClientInformation import ClientInformation
from DownloadUtils import DownloadUtils from DownloadUtils import DownloadUtils
from PlaybackUtils import PlaybackUtils from PlaybackUtils import PlaybackUtils
from LibrarySync import LibrarySync from LibrarySync import LibrarySync
from WriteKodiDB import WriteKodiDB from WriteKodiVideoDB import WriteKodiVideoDB
from ReadEmbyDB import ReadEmbyDB from ReadEmbyDB import ReadEmbyDB
pendingUserDataList = [] pendingUserDataList = []
@ -184,7 +184,7 @@ class WebSocketThread(threading.Thread):
cursor = connection.cursor() cursor = connection.cursor()
for item in itemsRemoved: for item in itemsRemoved:
self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteEpisodeFromKodiLibraryByMbId: " + item, 0) self.logMsg("Message : Doing LibraryChanged : Items Removed : Calling deleteEpisodeFromKodiLibraryByMbId: " + item, 0)
WriteKodiDB().deleteItemFromKodiLibrary(item, connection, cursor) WriteKodiVideoDB().deleteItemFromKodiLibrary(item, connection, cursor)
connection.commit() connection.commit()
cursor.close() cursor.close()

View file

@ -1,5 +1,5 @@
################################################################################################# #################################################################################################
# WriteKodiDB # WriteKodiVideoDB
################################################################################################# #################################################################################################
@ -25,7 +25,7 @@ from xml.etree import ElementTree
from xml.dom import minidom from xml.dom import minidom
import xml.etree.cElementTree as ET import xml.etree.cElementTree as ET
class WriteKodiDB(): class WriteKodiVideoDB():
def updatePlayCountFromKodi(self, id, type, playcount=0): def updatePlayCountFromKodi(self, id, type, playcount=0):
#when user marks item watched from kodi interface update this in Emby #when user marks item watched from kodi interface update this in Emby