mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 10:16:11 +00:00
add support for box sets
This commit is contained in:
parent
c9fb82cf3c
commit
ccf77f3be2
3 changed files with 108 additions and 0 deletions
|
@ -164,6 +164,14 @@ class LibrarySync():
|
||||||
total = len(allMB3Movies) + 1
|
total = len(allMB3Movies) + 1
|
||||||
count = 1
|
count = 1
|
||||||
|
|
||||||
|
# process box sets - TODO cope with movies removed from a set
|
||||||
|
boxsets = ReadEmbyDB().getBoxSets()
|
||||||
|
for boxset in boxsets:
|
||||||
|
boxsetMovies = ReadEmbyDB().getMoviesInBoxSet(boxset["Id"])
|
||||||
|
WriteKodiDB().addBoxsetToKodiLibrary(boxset)
|
||||||
|
for boxsetMovie in boxsetMovies:
|
||||||
|
WriteKodiDB().updateBoxsetToKodiLibrary(boxsetMovie,boxset)
|
||||||
|
|
||||||
#process updates
|
#process updates
|
||||||
allKodiMovies = ReadKodiDB().getKodiMovies(True)
|
allKodiMovies = ReadKodiDB().getKodiMovies(True)
|
||||||
for item in allMB3Movies:
|
for item in allMB3Movies:
|
||||||
|
|
|
@ -273,4 +273,46 @@ class ReadEmbyDB():
|
||||||
'type' : type,
|
'type' : type,
|
||||||
'id' : view.get("Id")})
|
'id' : view.get("Id")})
|
||||||
return collections
|
return collections
|
||||||
|
|
||||||
|
def getBoxSets(self):
|
||||||
|
result = None
|
||||||
|
|
||||||
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||||
|
port = addon.getSetting('port')
|
||||||
|
host = addon.getSetting('ipaddress')
|
||||||
|
server = host + ":" + port
|
||||||
|
|
||||||
|
downloadUtils = DownloadUtils()
|
||||||
|
userid = downloadUtils.getUserId()
|
||||||
|
|
||||||
|
url = server + '/mediabrowser/Users/' + userid + '/Items?SortBy=SortName&IsVirtualUnaired=false&IsMissing=False&Fields=Name,SortName,CumulativeRunTimeTicks&Recursive=true&SortOrder=Ascending&IncludeItemTypes=BoxSet&format=json&ImageTypeLimit=1'
|
||||||
|
|
||||||
|
jsonData = downloadUtils.downloadUrl(url, suppress=True, popup=0)
|
||||||
|
|
||||||
|
if jsonData != None and jsonData != "":
|
||||||
|
result = json.loads(jsonData)
|
||||||
|
if(result.has_key('Items')):
|
||||||
|
result = result['Items']
|
||||||
|
return result
|
||||||
|
|
||||||
|
def getMoviesInBoxSet(self,boxsetId):
|
||||||
|
result = None
|
||||||
|
|
||||||
|
addon = xbmcaddon.Addon(id='plugin.video.mb3sync')
|
||||||
|
port = addon.getSetting('port')
|
||||||
|
host = addon.getSetting('ipaddress')
|
||||||
|
server = host + ":" + port
|
||||||
|
|
||||||
|
downloadUtils = DownloadUtils()
|
||||||
|
userid = downloadUtils.getUserId()
|
||||||
|
|
||||||
|
url = server + '/mediabrowser/Users/' + userid + '/Items?ParentId=' + boxsetId + '&Fields=ItemCounts&format=json&ImageTypeLimit=1'
|
||||||
|
|
||||||
|
jsonData = downloadUtils.downloadUrl(url, suppress=True, popup=0)
|
||||||
|
|
||||||
|
if jsonData != None and jsonData != "":
|
||||||
|
result = json.loads(jsonData)
|
||||||
|
if(result.has_key('Items')):
|
||||||
|
result = result['Items']
|
||||||
|
return result
|
||||||
|
|
||||||
|
|
|
@ -911,3 +911,61 @@ class WriteKodiDB():
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def addBoxsetToKodiLibrary(self, boxset):
|
||||||
|
#use sqlite to set add the set
|
||||||
|
dbPath = xbmc.translatePath("special://userdata/Database/MyVideos%s.db" % utils.DATABASE_VERSION_HELIX)
|
||||||
|
|
||||||
|
connection = sqlite3.connect(dbPath)
|
||||||
|
cursor = connection.cursor()
|
||||||
|
|
||||||
|
strSet = boxset["Name"]
|
||||||
|
# check if exists
|
||||||
|
cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,))
|
||||||
|
result = cursor.fetchone()
|
||||||
|
setid = None
|
||||||
|
if result != None:
|
||||||
|
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]))
|
||||||
|
|
||||||
|
if setid == None:
|
||||||
|
# insert not exists
|
||||||
|
setssql="INSERT INTO sets (idSet, strSet) values(?, ?)"
|
||||||
|
cursor.execute(setssql, (None,strSet))
|
||||||
|
#if OK:
|
||||||
|
result = cursor.fetchone()
|
||||||
|
if result != None:
|
||||||
|
setid = result[0]
|
||||||
|
connection.commit()
|
||||||
|
cursor.close()
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def updateBoxsetToKodiLibrary(self, boxsetmovie, boxset):
|
||||||
|
strSet = boxset["Name"]
|
||||||
|
kodiMovie = ReadKodiDB().getKodiMovie(boxsetmovie["Id"])
|
||||||
|
WriteKodiDB().updateProperty(kodiMovie,"set",strSet,"movie",True)
|
Loading…
Reference in a new issue