mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 02:06:09 +00:00
Merge branch 'database_changes' of https://github.com/MediaBrowser/Emby.Kodi into database_changes
This commit is contained in:
commit
34f1b81f10
5 changed files with 104 additions and 13 deletions
|
@ -11,6 +11,7 @@ import json
|
||||||
import Utils as utils
|
import Utils as utils
|
||||||
from WriteKodiDB import WriteKodiDB
|
from WriteKodiDB import WriteKodiDB
|
||||||
from ReadKodiDB import ReadKodiDB
|
from ReadKodiDB import ReadKodiDB
|
||||||
|
from LibrarySync import LibrarySync
|
||||||
from PlayUtils import PlayUtils
|
from PlayUtils import PlayUtils
|
||||||
from DownloadUtils import DownloadUtils
|
from DownloadUtils import DownloadUtils
|
||||||
from PlaybackUtils import PlaybackUtils
|
from PlaybackUtils import PlaybackUtils
|
||||||
|
@ -45,6 +46,12 @@ class Kodi_Monitor(xbmc.Monitor):
|
||||||
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)
|
WriteKodiDB().updatePlayCountFromKodi(item, type, playcount)
|
||||||
|
|
||||||
|
if method == "System.OnWake":
|
||||||
|
xbmc.sleep(10000) #Allow network to wake up
|
||||||
|
utils.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Started)",1)
|
||||||
|
libSync = LibrarySync().FullLibrarySync()
|
||||||
|
utils.logMsg("Doing_Db_Sync Post Resume: syncDatabase (Finished) " + str(libSync),1)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -143,6 +143,31 @@ class LibrarySync():
|
||||||
if kodiMovie[2] != API().getChecksum(item):
|
if kodiMovie[2] != API().getChecksum(item):
|
||||||
WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
|
WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#### PROCESS BOX SETS #####
|
||||||
|
if(pDialog != None):
|
||||||
|
utils.logMsg("Sync Movies", "BoxSet Sync Started", 1)
|
||||||
|
boxsets = ReadEmbyDB().getBoxSets()
|
||||||
|
|
||||||
|
total = len(boxsets) + 1
|
||||||
|
count = 1
|
||||||
|
for boxset in boxsets:
|
||||||
|
progressTitle = "Processing BoxSets"+ " (" + str(count) + " of " + str(total) + ")"
|
||||||
|
pDialog.update(0, "Emby for Kodi - Running Sync", progressTitle)
|
||||||
|
count += 1
|
||||||
|
if(self.ShouldStop()):
|
||||||
|
return False
|
||||||
|
boxsetMovies = ReadEmbyDB().getMoviesInBoxSet(boxset["Id"])
|
||||||
|
WriteKodiDB().addBoxsetToKodiLibrary(boxset,connection, cursor)
|
||||||
|
|
||||||
|
for boxsetMovie in boxsetMovies:
|
||||||
|
if(self.ShouldStop()):
|
||||||
|
return False
|
||||||
|
WriteKodiDB().updateBoxsetToKodiLibrary(boxsetMovie,boxset, connection, cursor)
|
||||||
|
|
||||||
|
utils.logMsg("Sync Movies", "BoxSet Sync Finished", 1)
|
||||||
|
|
||||||
#### PROCESS DELETES #####
|
#### PROCESS DELETES #####
|
||||||
allEmbyMovieIds = set(allEmbyMovieIds)
|
allEmbyMovieIds = set(allEmbyMovieIds)
|
||||||
for kodiId in allKodiMovieIds:
|
for kodiId in allKodiMovieIds:
|
||||||
|
@ -336,6 +361,18 @@ class LibrarySync():
|
||||||
if not item.get('IsFolder'):
|
if not item.get('IsFolder'):
|
||||||
WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
|
WriteKodiDB().addOrUpdateMovieToKodiLibrary(item["Id"],connection, cursor, view.get('title'))
|
||||||
|
|
||||||
|
|
||||||
|
#### PROCESS BOX SETS #####
|
||||||
|
boxsets = ReadEmbyDB().getBoxSets()
|
||||||
|
|
||||||
|
for boxset in boxsets:
|
||||||
|
boxsetMovies = ReadEmbyDB().getMoviesInBoxSet(boxset["Id"])
|
||||||
|
WriteKodiDB().addBoxsetToKodiLibrary(boxset,connection, cursor)
|
||||||
|
|
||||||
|
for boxsetMovie in boxsetMovies:
|
||||||
|
WriteKodiDB().updateBoxsetToKodiLibrary(boxsetMovie,boxset, connection, cursor)
|
||||||
|
|
||||||
|
|
||||||
#### PROCESS TV SHOWS ####
|
#### PROCESS TV SHOWS ####
|
||||||
views = ReadEmbyDB().getCollections("tvshows")
|
views = ReadEmbyDB().getCollections("tvshows")
|
||||||
for view in views:
|
for view in views:
|
||||||
|
|
|
@ -115,8 +115,9 @@ class PlaybackUtils():
|
||||||
if setup == "service":
|
if setup == "service":
|
||||||
xbmc.Player().play(playurl,listItem)
|
xbmc.Player().play(playurl,listItem)
|
||||||
elif setup == "default":
|
elif setup == "default":
|
||||||
listItem = xbmcgui.ListItem(path=playurl)
|
|
||||||
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem)
|
xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, listItem)
|
||||||
|
#artwork only works from widgets with both resolvedurl and player command
|
||||||
|
xbmc.Player().play(playurl,listItem)
|
||||||
|
|
||||||
def setArt(self, list,name,path):
|
def setArt(self, list,name,path):
|
||||||
if name=='thumb' or name=='fanart_image' or name=='small_poster' or name=='tiny_poster' or name == "medium_landscape" or name=='medium_poster' or name=='small_fanartimage' or name=='medium_fanartimage' or name=='fanart_noindicators':
|
if name=='thumb' or name=='fanart_image' or name=='small_poster' or name=='tiny_poster' or name == "medium_landscape" or name=='medium_poster' or name=='small_fanartimage' or name=='medium_fanartimage' or name=='fanart_noindicators':
|
||||||
|
|
|
@ -246,10 +246,10 @@ class ReadEmbyDB():
|
||||||
Name = view[u'Name']
|
Name = view[u'Name']
|
||||||
|
|
||||||
total = str(view[u'ChildCount'])
|
total = str(view[u'ChildCount'])
|
||||||
type = view[u'CollectionType']
|
itemtype = view[u'CollectionType']
|
||||||
if type == None:
|
if itemtype == None:
|
||||||
type = "None" # User may not have declared the type
|
itemtype = "movies" # User may not have declared the type
|
||||||
if type == type:
|
if itemtype == type:
|
||||||
collections.append( {'title' : Name,
|
collections.append( {'title' : Name,
|
||||||
'type' : type,
|
'type' : type,
|
||||||
'id' : view[u'Id']})
|
'id' : view[u'Id']})
|
||||||
|
|
|
@ -992,15 +992,61 @@ class WriteKodiDB():
|
||||||
setssql="INSERT INTO sets (idSet, strSet) values(?, ?)"
|
setssql="INSERT INTO sets (idSet, strSet) values(?, ?)"
|
||||||
cursor.execute(setssql, (None,strSet))
|
cursor.execute(setssql, (None,strSet))
|
||||||
#if OK:
|
#if OK:
|
||||||
|
cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,))
|
||||||
|
|
||||||
result = cursor.fetchone()
|
result = cursor.fetchone()
|
||||||
if result != None:
|
if result != None:
|
||||||
setid = result[0]
|
setid = result[0]
|
||||||
|
|
||||||
|
currentsetartsql = "SELECT type, url FROM art where media_type = ? and media_id = ? and url != ''"
|
||||||
|
cursor.execute(currentsetartsql, ("set", setid))
|
||||||
|
existing_type_map = {}
|
||||||
|
rows = cursor.fetchall()
|
||||||
|
for row in rows:
|
||||||
|
existing_type_map[row[0] ] = row[1]
|
||||||
|
|
||||||
|
artwork = {}
|
||||||
|
artwork["poster"] = API().getArtwork(boxset, "Primary")
|
||||||
|
artwork["banner"] = API().getArtwork(boxset, "Banner")
|
||||||
|
artwork["clearlogo"] = API().getArtwork(boxset, "Logo")
|
||||||
|
artwork["clearart"] = API().getArtwork(boxset, "Art")
|
||||||
|
artwork["landscape"] = API().getArtwork(boxset, "Thumb")
|
||||||
|
artwork["discart"] = API().getArtwork(boxset, "Disc")
|
||||||
|
artwork["fanart"] = API().getArtwork(boxset, "Backdrop")
|
||||||
|
|
||||||
|
art_types = ['poster','fanart','landscape','clearlogo','clearart','banner','discart']
|
||||||
|
for update_type in art_types:
|
||||||
|
if ( update_type in existing_type_map ):
|
||||||
|
if ( existing_type_map[update_type] != artwork[update_type] ) and artwork[update_type] != '':
|
||||||
|
setupdateartsql = "UPDATE art SET url = ? where media_type = ? and media_id = ? and type = ?"
|
||||||
|
cursor.execute(setupdateartsql,(artwork[update_type],"set",setid,update_type))
|
||||||
|
elif artwork[update_type] != '':
|
||||||
|
setartsql = "INSERT INTO art(media_id, media_type, type, url) VALUES(?,?,?,?)"
|
||||||
|
cursor.execute(setartsql,(setid,"set",update_type,artwork[update_type]))
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def updateBoxsetToKodiLibrary(self, boxsetmovie, boxset):
|
def updateBoxsetToKodiLibrary(self, boxsetmovie, boxset, connection, cursor):
|
||||||
strSet = boxset["Name"]
|
strSet = boxset["Name"]
|
||||||
kodiMovie = ReadKodiDB().getKodiMovie(boxsetmovie["Id"])
|
cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?",(boxsetmovie["Id"],))
|
||||||
if kodiMovie != None:
|
result = cursor.fetchone()
|
||||||
WriteKodiDB().updateProperty(kodiMovie,"set",strSet,"movie",True)
|
if result != None:
|
||||||
|
movieid = result[0]
|
||||||
|
else:
|
||||||
|
movieid = None
|
||||||
|
if movieid != None:
|
||||||
|
# check if exists
|
||||||
|
cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
setid = None
|
||||||
|
if result != None:
|
||||||
|
setid = result[0]
|
||||||
|
|
||||||
|
pathsql="update movie SET idSet = ? WHERE idMovie = ?"
|
||||||
|
cursor.execute(pathsql, (setid, movieid))
|
||||||
|
|
||||||
|
#update the checksum in emby table
|
||||||
|
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(boxsetmovie),boxsetmovie["Id"]))
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue