Correct the merging

This commit is contained in:
angelblue05 2015-07-26 07:09:09 -05:00
parent 076a998f67
commit e3a81da2a5
5 changed files with 292 additions and 265 deletions

View file

@ -18,9 +18,7 @@ class API():
try: try:
people = item['People'] people = item['People']
except: pass except: pass
else: else:
for person in people: for person in people:

View file

@ -124,6 +124,7 @@ def addUser():
# THEME MUSIC/VIDEOS # THEME MUSIC/VIDEOS
def getThemeMedia(): def getThemeMedia():
doUtils = DownloadUtils() doUtils = DownloadUtils()
playUtils = PlayUtils() playUtils = PlayUtils()
@ -131,7 +132,7 @@ def getThemeMedia():
server = WINDOW.getProperty('server%s' % currUser) server = WINDOW.getProperty('server%s' % currUser)
playback = None playback = None
library = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/") library = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/").decode('utf-8')
# Choose playback method # Choose playback method
resp = xbmcgui.Dialog().select("Choose playback method for your themes", ["Direct Play", "Direct Stream"]) resp = xbmcgui.Dialog().select("Choose playback method for your themes", ["Direct Play", "Direct Stream"])
@ -144,7 +145,7 @@ def getThemeMedia():
else:return else:return
# Set custom path for user # Set custom path for user
tvtunes_path = xbmc.translatePath("special://profile/addon_data/script.tvtunes/") tvtunes_path = xbmc.translatePath("special://profile/addon_data/script.tvtunes/").decode('utf-8')
if xbmcvfs.exists(tvtunes_path): if xbmcvfs.exists(tvtunes_path):
tvtunes = xbmcaddon.Addon(id="script.tvtunes") tvtunes = xbmcaddon.Addon(id="script.tvtunes")
tvtunes.setSetting('custom_path_enable', "true") tvtunes.setSetting('custom_path_enable', "true")
@ -156,8 +157,6 @@ def getThemeMedia():
dialog.ok('Warning', 'The settings file does not exist in tvtunes. Go to the tvtunes addon and change a setting, then come back and re-run') dialog.ok('Warning', 'The settings file does not exist in tvtunes. Go to the tvtunes addon and change a setting, then come back and re-run')
return return
# Offer to exclude video themes
includeVideoThemes = xbmcgui.Dialog().yesno("Theme Types", "Should video themes be included?")
# Create library directory # Create library directory
if not xbmcvfs.exists(library): if not xbmcvfs.exists(library):
@ -175,7 +174,6 @@ def getThemeMedia():
# Get Ids with Theme Videos # Get Ids with Theme Videos
itemIds = {} itemIds = {}
if includeVideoThemes:
for view in userViews: for view in userViews:
url = "{server}/mediabrowser/Users/{UserId}/Items?HasThemeVideo=True&ParentId=%s&format=json" % view url = "{server}/mediabrowser/Users/{UserId}/Items?HasThemeVideo=True&ParentId=%s&format=json" % view
result = doUtils.downloadUrl(url) result = doUtils.downloadUrl(url)
@ -206,7 +204,7 @@ def getThemeMedia():
if playback == "DirectPlay": if playback == "DirectPlay":
playurl = playUtils.directPlay(theme) playurl = playUtils.directPlay(theme)
else: else:
playurl = playUtils.directStream(result, server, theme[u'Id']) playurl = playUtils.directStream(result, server, theme[u'Id'], "ThemeVideo")
pathstowrite += ('<file>%s</file>' % playurl.encode('utf-8')) pathstowrite += ('<file>%s</file>' % playurl.encode('utf-8'))
# Check if the item has theme songs and add them # Check if the item has theme songs and add them

View file

@ -148,6 +148,10 @@ def createSources():
path = xbmc.translatePath("special://profile/").decode("utf-8") path = xbmc.translatePath("special://profile/").decode("utf-8")
xmlpath = "%ssources.xml" % path xmlpath = "%ssources.xml" % path
if xbmcvfs.exists(xmlpath):
# add some way to writing dummy path to existing sources.xml
pass
else:
sources = open(xmlpath, 'w') sources = open(xmlpath, 'w')
sources.write( sources.write(

View file

@ -137,6 +137,7 @@ class WriteKodiMusicDB():
albumid = None albumid = None
genres = MBitem.get('Genres') genres = MBitem.get('Genres')
##### The album details ##### ##### The album details #####
lastScraped = datetime.now().strftime('%Y-%m-%d %H:%M:%S') lastScraped = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
dateadded = API().getDateCreated(MBitem) dateadded = API().getDateCreated(MBitem)
@ -269,12 +270,13 @@ class WriteKodiMusicDB():
# Get the path and filename # Get the path and filename
playurl = PlayUtils().directPlay(MBitem) playurl = PlayUtils().directPlay(MBitem)
try: try:
path, filename = ntsplit(playurl) path, filename = ntsplit(playurl)
if "\\" in playurl: if "/" in playurl:
path = "%s\\" % path
elif "/" in playurl:
path = "%s/" % path path = "%s/" % path
elif "\\" in playurl:
path = "%s\\" % path
except: # playurl returned false - using server streaming path, because could not figure out plugin paths for music DB except: # playurl returned false - using server streaming path, because could not figure out plugin paths for music DB
playurl = PlayUtils().directstream(MBitem, self.server, embyId, "Audio") playurl = PlayUtils().directstream(MBitem, self.server, embyId, "Audio")
filename = "stream.mp3" filename = "stream.mp3"
@ -426,7 +428,6 @@ class WriteKodiMusicDB():
for genre in genres: for genre in genres:
idGenre = None
cursor.execute("SELECT idGenre as idGenre FROM genre WHERE strGenre = ?", (genre,)) cursor.execute("SELECT idGenre as idGenre FROM genre WHERE strGenre = ?", (genre,))
try: try:
idGenre = cursor.fetchone()[0] idGenre = cursor.fetchone()[0]

View file

@ -20,7 +20,6 @@ from ReadKodiDB import ReadKodiDB
from ReadEmbyDB import ReadEmbyDB from ReadEmbyDB import ReadEmbyDB
from TextureCache import TextureCache from TextureCache import TextureCache
class WriteKodiVideoDB(): class WriteKodiVideoDB():
textureCache = TextureCache() textureCache = TextureCache()
@ -78,7 +77,7 @@ class WriteKodiVideoDB():
MBitem = ReadEmbyDB().getFullItem(embyId) MBitem = ReadEmbyDB().getFullItem(embyId)
if not MBitem: if not MBitem:
self.logMsg("ADD movie to Kodi library FAILED, Item %s not found on server!" % embyId) self.logMsg("ADD movie to Kodi library FAILED, Item %s not found on server!" % embyId, 1)
return return
# If the item already exist in the local Kodi DB we'll perform a full item update # If the item already exist in the local Kodi DB we'll perform a full item update
@ -89,7 +88,8 @@ class WriteKodiVideoDB():
movieid = cursor.fetchone()[0] movieid = cursor.fetchone()[0]
except: except:
movieid = None movieid = None
self.logMsg("Movie Id: %s not found." % embyId, 2) self.logMsg("Movie Id: %s not found." % embyId, 1)
timeInfo = API().getTimeInfo(MBitem) timeInfo = API().getTimeInfo(MBitem)
userData = API().getUserData(MBitem) userData = API().getUserData(MBitem)
@ -133,28 +133,29 @@ class WriteKodiVideoDB():
except: except:
trailerUrl = None trailerUrl = None
#### ADD OR UPDATE THE FILE AND PATH ########### ##### ADD OR UPDATE THE FILE AND PATH #####
#### NOTE THAT LASTPLAYED AND PLAYCOUNT ARE STORED AT THE FILE ENTRY ##### NOTE THAT LASTPLAYED AND PLAYCOUNT ARE STORED AT THE FILE ENTRY #####
# Get the real filename for direct path or media flags for plugin path
playurl = PlayUtils().directPlay(MBitem) playurl = PlayUtils().directPlay(MBitem)
if self.directpath:
if playurl == False:
return
elif "\\" in playurl:
filename = playurl.rsplit("\\",1)[-1]
path = playurl.replace(filename, "")
elif "/" in playurl:
filename = playurl.rsplit("/",1)[-1]
path = playurl.replace(filename, "")
else: # Set plugin path and media flags using real filename
try: try:
if "plugin://" in playurl: if "plugin://" in playurl:
fileext = "" fileext = ""
else: else:
path, fileext = ntsplit(playurl) path, fileext = ntsplit(playurl)
except: return # playurl returned False except: # The playurl may return False
else: # Set filename and path fileext = ""
if self.directpath:
# Use direct paths instead of add-on redirect
filename = fileext
if "\\" in path:
path = "%s\\" % path
elif "/" in path:
path = "%s/" % path
else: # Set plugin path and media flags using real filename
filename = "plugin://plugin.video.emby/movies/%s/?filename=%s&id=%s&mode=play" % (embyId, fileext, embyId) filename = "plugin://plugin.video.emby/movies/%s/?filename=%s&id=%s&mode=play" % (embyId, fileext, embyId)
path = "plugin://plugin.video.emby/movies/%s/" % embyId path = "plugin://plugin.video.emby/movies/%s/" % embyId
@ -276,122 +277,133 @@ class WriteKodiVideoDB():
def addOrUpdateMusicVideoToKodiLibrary( self, embyId ,connection, cursor): def addOrUpdateMusicVideoToKodiLibrary( self, embyId ,connection, cursor):
addon = self.addon addon = xbmcaddon.Addon(id='plugin.video.emby')
WINDOW = xbmcgui.Window(10000)
username = WINDOW.getProperty('currUser')
userid = WINDOW.getProperty('userId%s' % username)
server = WINDOW.getProperty('server%s' % username)
downloadUtils = DownloadUtils()
MBitem = ReadEmbyDB().getFullItem(embyId) MBitem = ReadEmbyDB().getFullItem(embyId)
if not MBitem: if not MBitem:
self.logMsg("ADD musicvideo to Kodi library FAILED, Item %s not found on server!" % embyId, 1) utils.logMsg("ADD musicvideo to Kodi library FAILED", "Item %s not found on server!" %embyId)
return return
# If the item already exist in the local Kodi DB we'll perform a full item update # If the item already exist in the local Kodi DB we'll perform a full item update
# If the item doesn't exist, we'll add it to the database # If the item doesn't exist, we'll add it to the database
cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?", (embyId,)) cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?",(MBitem["Id"],))
try: result = cursor.fetchone()
idMVideo = cursor.fetchone()[0] if result != None:
except: idMVideo = result[0]
else:
idMVideo = None idMVideo = None
timeInfo = API().getTimeInfo(MBitem) timeInfo = API().getTimeInfo(MBitem)
userData=API().getUserData(MBitem) userData=API().getUserData(MBitem)
people = API().getPeople(MBitem) people = API().getPeople(MBitem)
genres = MBitem.get('Genres')
studios = API().getStudios(MBitem)
#### The video details #### #### The video details #########
playcount = userData.get('PlayCount')
dateplayed = userData.get('LastPlayedDate')
dateadded = API().getDateCreated(MBitem)
checksum = API().getChecksum(MBitem)
title = MBitem['Name']
runtime = timeInfo.get('TotalTime') runtime = timeInfo.get('TotalTime')
director = " / ".join(people.get('Director')) plot = utils.convertEncoding(API().getOverview(MBitem))
studio = " / ".join(studios) title = utils.convertEncoding(MBitem["Name"])
year = MBitem.get('ProductionYear') year = MBitem.get("ProductionYear")
plot = API().getOverview(MBitem) genres = MBitem.get("Genres")
album = MBitem.get('Album')
artist = " / ".join(MBitem.get('Artists'))
genre = " / ".join(genres) genre = " / ".join(genres)
track = MBitem.get('Track') studios = API().getStudios(MBitem)
studio = " / ".join(studios)
director = " / ".join(people.get("Director"))
artist = " / ".join(MBitem.get("Artists"))
album = MBitem.get("Album")
track = MBitem.get("Track")
if MBitem.get("DateCreated") != None:
dateadded = MBitem["DateCreated"].split('.')[0].replace('T', " ")
else:
dateadded = None
if userData.get("PlayCount") != "0":
playcount = int(userData.get('PlayCount'))
else:
playcount = None #playcount must be set to NULL in the db
#### ADD OR UPDATE THE FILE AND PATH ########### #### ADD OR UPDATE THE FILE AND PATH ###########
#### NOTE THAT LASTPLAYED AND PLAYCOUNT ARE STORED AT THE FILE ENTRY #### NOTE THAT LASTPLAYED AND PLAYCOUNT ARE STORED AT THE FILE ENTRY
if addon.getSetting('useDirectPaths')=='true':
# Set filename and path if PlayUtils().isDirectPlay(MBitem):
if addon.getSetting('useDirectPaths') == "true":
# playurl can return False
playurl = PlayUtils().directPlay(MBitem) playurl = PlayUtils().directPlay(MBitem)
try: #use the direct file path
path, filename = ntsplit(playurl) if "\\" in playurl:
if "\\" in path: filename = playurl.rsplit("\\",1)[-1]
path = "%s\\" % path path = playurl.replace(filename,"")
elif "/" in path: elif "/" in playurl:
path = "%s/" % path filename = playurl.rsplit("/",1)[-1]
except: path = playurl.replace(filename,"")
#for transcoding we just use the server's streaming path because I couldn't figure out how to set the plugin path in the music DB
path = "%s/Video/%s/" % (self.server, embyId)
filename = "stream.mp4"
else: # Set plugin path
path = "plugin://plugin.video.emby/musicvideos/%s/" % embyId
filename = "plugin://plugin.video.emby/musicvideos/%s/?id=%s&mode=play" % (embyId, embyId)
# Validate the path in database
cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?", (path,))
try:
pathid = cursor.fetchone()[0]
except:
# Path does not exist yet
cursor.execute("select coalesce(max(idPath),0) as pathid from path")
pathid = cursor.fetchone()[0] + 1
query = "INSERT INTO path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
cursor.execute(query, (pathid, path, "musicvideos", "metadata.local", 1))
# Validate the file in database
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?", (filename, pathid,))
try:
fileid = cursor.fetchone()[0]
query = "UPDATE files SET playCount = ?, lastPlayed = ? WHERE idFile = ?"
cursor.execute(query, (playcount, dateplayed, fileid))
except:
# File does not exist yet
cursor.execute("select coalesce(max(idFile),0) as fileid from files")
fileid = cursor.fetchone()[0] + 1
query = "INSERT INTO files(idFile, idPath, strFilename, playCount, lastPlayed, dateAdded) values(?, ?, ?, ?, ?, ?)"
cursor.execute(query, (fileid, pathid, filename, playcount, dateplayed, dateadded))
##### UPDATE THE MVIDEO #####
if idMVideo:
self.logMsg("UPDATE musicvideo to Kodi Library, Id: %s - Title: %s" % (embyId, title), 1)
query = "UPDATE musicvideo SET c00 = ?, c04 = ?, c05 = ?, c06 = ?, c07 = ?, c08 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ? WHERE idMVideo = ?"
cursor.execute(query, (title, runtime, director, studio, year, plot, album, artist, genre, track, idMVideo))
# Update the checksum in emby table
query = "UPDATE emby SET checksum = ? WHERE emby_id = ?"
cursor.execute(query, (checksum, embyId))
##### OR ADD THE MVIDEO #####
else: else:
self.logMsg("ADD musicvideo to Kodi Library, Id: %s - Title: %s" % (embyId, title), 1) #for transcoding we just use the server's streaming path because I couldn't figure out how to set the plugin path in the music DB
path = server + "/Video/%s/" %MBitem["Id"]
filename = "stream.mp4"
else:
path = "plugin://plugin.video.emby/musicvideos/%s/" % MBitem["Id"]
filename = "plugin://plugin.video.emby/musicvideos/%s/?id=%s&mode=play" % (MBitem["Id"], MBitem["Id"])
# Create the video #create the path
cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?",(path,))
result = cursor.fetchone()
if result != None:
pathid = result[0]
else:
cursor.execute("select coalesce(max(idPath),0) as pathid from path")
pathid = cursor.fetchone()[0]
pathid = pathid + 1
pathsql = "insert into path(idPath, strPath, strContent, strScraper, noUpdate) values(?, ?, ?, ?, ?)"
cursor.execute(pathsql, (pathid,path,"musicvideos","metadata.local",1))
#create the file if not exists
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?",(filename,pathid,))
result = cursor.fetchone()
if result != None:
fileid = result[0]
if result == None:
cursor.execute("select coalesce(max(idFile),0) as fileid from files")
fileid = cursor.fetchone()[0]
fileid = fileid + 1
pathsql="insert into files(idFile, idPath, strFilename, playCount, lastPlayed, dateAdded) values(?, ?, ?, ?, ?, ?)"
cursor.execute(pathsql, (fileid,pathid,filename,playcount,userData.get("LastPlayedDate"),dateadded))
else:
pathsql="update files SET playCount = ?, lastPlayed = ? WHERE idFile = ?"
cursor.execute(pathsql, (playcount,userData.get("LastPlayedDate"), fileid))
##### ADD THE VIDEO ############
if idMVideo == None:
utils.logMsg("ADD musicvideo to Kodi library","Id: %s - Title: %s" % (embyId, title))
#create the video
cursor.execute("select coalesce(max(idMVideo),0) as idMVideo from musicvideo") cursor.execute("select coalesce(max(idMVideo),0) as idMVideo from musicvideo")
idMVideo = cursor.fetchone()[0] + 1 idMVideo = cursor.fetchone()[0]
query = "INSERT INTO musicvideo(idMVideo, idFile, c00, c04, c05, c06, c07, c08, c09, c10, c11, c12) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" idMVideo = idMVideo + 1
cursor.execute(query, (idMVideo, fileid, title, runtime, director, studio, year, plot, album, artist, genre, track)) pathsql="insert into musicvideo(idMVideo, idFile, c00, c04, c05, c06, c07, c08, c09, c10, c11, c12) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
cursor.execute(pathsql, (idMVideo, fileid, title, runtime, director, studio, year, plot, album, artist, genre, track))
# Create the reference in emby table #create the reference in emby table
query = "INSERT INTO emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)" pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
cursor.execute(query, (embyId, idMVideo, "musicvideo", checksum)) cursor.execute(pathsql, (MBitem["Id"], idMVideo, "musicvideo", API().getChecksum(MBitem)))
#### UPDATE THE VIDEO #####
else:
utils.logMsg("UPDATE musicvideo to Kodi library","Id: %s - Title: %s" % (embyId, title))
pathsql="update musicvideo SET c00 = ?, c04 = ?, c05 = ?, c06 = ?, c07 = ?, c08 = ?, c09 = ?, c10 = ?, c11 = ?, c12 = ? WHERE idMVideo = ?"
cursor.execute(pathsql, (title, runtime, director, studio, year, plot, album, artist, genre, track, idMVideo))
# Update or insert actors #update the checksum in emby table
cursor.execute("UPDATE emby SET checksum = ? WHERE emby_id = ?", (API().getChecksum(MBitem),MBitem["Id"]))
#update or insert actors
self.AddPeopleToMedia(idMVideo,MBitem.get("People"),"musicvideo", connection, cursor) self.AddPeopleToMedia(idMVideo,MBitem.get("People"),"musicvideo", connection, cursor)
# Update artwork #update artwork
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary", mediaType = "musicvideo"), idMVideo, "musicvideo", "thumb", cursor) self.addOrUpdateArt(API().getArtwork(MBitem, "Primary", mediaType = "musicvideo"), idMVideo, "musicvideo", "thumb", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary", mediaType = "musicvideo"), idMVideo, "musicvideo", "poster", cursor) self.addOrUpdateArt(API().getArtwork(MBitem, "Primary", mediaType = "musicvideo"), idMVideo, "musicvideo", "poster", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Banner", mediaType = "musicvideo"), idMVideo, "musicvideo", "banner", cursor) self.addOrUpdateArt(API().getArtwork(MBitem, "Banner", mediaType = "musicvideo"), idMVideo, "musicvideo", "banner", cursor)
@ -401,17 +413,23 @@ class WriteKodiVideoDB():
self.addOrUpdateArt(API().getArtwork(MBitem, "Disc", mediaType = "musicvideo"), idMVideo, "musicvideo", "discart", cursor) self.addOrUpdateArt(API().getArtwork(MBitem, "Disc", mediaType = "musicvideo"), idMVideo, "musicvideo", "discart", cursor)
self.addOrUpdateArt(API().getArtwork(MBitem, "Backdrop", mediaType = "musicvideo"), idMVideo, "musicvideo", "fanart", cursor) self.addOrUpdateArt(API().getArtwork(MBitem, "Backdrop", mediaType = "musicvideo"), idMVideo, "musicvideo", "fanart", cursor)
# Update genres #update genres
self.AddGenresToMedia(idMVideo, genres, "musicvideo", cursor) self.AddGenresToMedia(idMVideo, genres, "musicvideo", cursor)
# Update studios #update studios
self.AddStudiosToMedia(idMVideo, studios, "musicvideo", cursor) self.AddStudiosToMedia(idMVideo, studios, "musicvideo", cursor)
# Add streamdetails #add streamdetails
self.AddStreamDetailsToMedia(API().getMediaStreams(MBitem), fileid, cursor) self.AddStreamDetailsToMedia(API().getMediaStreams(MBitem), fileid, cursor)
#set resume point
resume = int(round(float(timeInfo.get("ResumeTime"))))*60
total = int(round(float(timeInfo.get("TotalTime"))))*60
self.setKodiResumePoint(fileid, resume, total, cursor)
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:
@ -426,6 +444,8 @@ class WriteKodiVideoDB():
showid = cursor.fetchone()[0] showid = cursor.fetchone()[0]
except: except:
showid = None showid = None
self.logMsg("TV Show Id: %s not found." % embyId, 1)
timeInfo = API().getTimeInfo(MBitem) timeInfo = API().getTimeInfo(MBitem)
userData = API().getUserData(MBitem) userData = API().getUserData(MBitem)
@ -449,10 +469,8 @@ class WriteKodiVideoDB():
studio = " / ".join(studios) studio = " / ".join(studios)
sorttitle = MBitem['SortName'] sorttitle = MBitem['SortName']
#### ADD OR UPDATE THE FILE AND PATH ###########
#### TOP LEVEL PATH AS MONITORED SOURCE IS REQUIRED - for actors, etc. (no clue why)
# Set filename and path #create toplevel path as monitored source - needed for things like actors and stuff to work (no clue why)
if self.directpath: if self.directpath:
# Network share # Network share
playurl = PlayUtils().directPlay(MBitem) playurl = PlayUtils().directPlay(MBitem)
@ -547,6 +565,7 @@ class WriteKodiVideoDB():
# Update season details # Update season details
self.updateSeasons(embyId, showid, connection, cursor) self.updateSeasons(embyId, showid, connection, cursor)
def addOrUpdateEpisodeToKodiLibrary(self, embyId, showid, connection, cursor): def addOrUpdateEpisodeToKodiLibrary(self, embyId, showid, connection, cursor):
addon = self.addon addon = self.addon
@ -559,11 +578,13 @@ class WriteKodiVideoDB():
# If the episode already exist in the local Kodi DB we'll perform a full item update # If the episode already exist in the local Kodi DB we'll perform a full item update
# If the item doesn't exist, we'll add it to the database # If the item doesn't exist, we'll add it to the database
cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?",(embyId,)) cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?", (MBitem['Id'],))
try: try:
episodeid = cursor.fetchone()[0] episodeid = cursor.fetchone()[0]
except: except:
episodeid = None episodeid = None
self.logMsg("Episode Id: %s not found." % embyId, 1)
timeInfo = API().getTimeInfo(MBitem) timeInfo = API().getTimeInfo(MBitem)
userData = API().getUserData(MBitem) userData = API().getUserData(MBitem)
@ -583,33 +604,35 @@ class WriteKodiVideoDB():
title = MBitem['Name'] title = MBitem['Name']
plot = API().getOverview(MBitem) plot = API().getOverview(MBitem)
rating = MBitem.get('CommunityRating') rating = MBitem.get('CommunityRating')
writer = " / ".join(people.get("Writer")) writer = " / ".join(people.get('Writer'))
premieredate = API().getPremiereDate(MBitem) premieredate = API().getPremiereDate(MBitem)
runtime = timeInfo.get('TotalTime') runtime = timeInfo.get('TotalTime')
director = " / ".join(people.get("Director")) director = " / ".join(people.get('Director'))
#### ADD OR UPDATE THE FILE AND PATH ########### #### ADD OR UPDATE THE FILE AND PATH ###########
#### NOTE THAT LASTPLAYED AND PLAYCOUNT ARE STORED AT THE FILE ENTRY #### NOTE THAT LASTPLAYED AND PLAYCOUNT ARE STORED AT THE FILE ENTRY
#### ORDERING FOR SORTING C15 C16 TO DISPLAY SPECIALS WITHIN REGULAR EPISODES
# Get the real filename
playurl = PlayUtils().directPlay(MBitem) playurl = PlayUtils().directPlay(MBitem)
if self.directpath:
if playurl == False:
return
elif "\\" in playurl:
filename = playurl.rsplit("\\",1)[-1]
path = playurl.replace(filename, "")
elif "/" in playurl:
filename = playurl.rsplit("/",1)[-1]
path = playurl.replace(filename, "")
else: # Set plugin path and media flags - real filename with extension
try: try:
if "plugin://" in playurl: if "plugin://" in playurl:
fileext = "" fileext = ""
else: else:
path, fileext = ntsplit(playurl) path, fileext = ntsplit(playurl)
except: return # playurl returned False except: # The playurl may return False
else: # Set filename and path fileext = ""
if self.directpath:
filename = fileext
if "\\" in playurl:
path = "%s\\" % path
elif "/" in playurl:
path = "%s/" % path
else: # Set plugin path and media flags - real filename with extension
filename = "plugin://plugin.video.emby/tvshows/%s/?filename=%s&id=%s&mode=play" % (seriesId, fileext, embyId) filename = "plugin://plugin.video.emby/tvshows/%s/?filename=%s&id=%s&mode=play" % (seriesId, fileext, embyId)
path = "plugin://plugin.video.emby/tvshows/%s/" % seriesId path = "plugin://plugin.video.emby/tvshows/%s/" % seriesId
@ -633,6 +656,7 @@ class WriteKodiVideoDB():
self.setKodiResumePoint(result, 0, 0, cursor) self.setKodiResumePoint(result, 0, 0, cursor)
except: pass except: pass
# Validate the path in database # Validate the path in database
cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?", (path,)) cursor.execute("SELECT idPath as pathid FROM path WHERE strPath = ?", (path,))
try: try:
@ -803,8 +827,8 @@ class WriteKodiVideoDB():
if url != imageUrl: if url != imageUrl:
cacheimage = True cacheimage = True
self.logMsg("Updating Art Link for kodiId: %s (%s) -> (%s)" % (kodiId, url, imageUrl), 1) self.logMsg("Updating Art Link for kodiId: %s (%s) -> (%s)" % (kodiId, url, imageUrl), 1)
query = "INSERT INTO art(media_id, media_type, type, url) values(?, ?, ?, ?)" query = "UPDATE art set url = ? WHERE media_id = ? AND media_type = ? AND type = ?"
cursor.execute(query, (kodiId, mediaType, imageType, imageUrl)) cursor.execute(query, (imageUrl, kodiId, mediaType, imageType))
# Cache fanart and poster in Kodi texture cache # Cache fanart and poster in Kodi texture cache
if cacheimage and imageType in ("fanart", "poster"): if cacheimage and imageType in ("fanart", "poster"):
@ -978,6 +1002,8 @@ class WriteKodiVideoDB():
query = "INSERT OR REPLACE into genrelinktvshow(idGenre, idShow) values(?, ?)" query = "INSERT OR REPLACE into genrelinktvshow(idGenre, idShow) values(?, ?)"
elif "musicvideo" in mediatype: elif "musicvideo" in mediatype:
query = "INSERT OR REPLACE into genrelinkmusicvideo(idGenre, idMVideo) values(?, ?)" query = "INSERT OR REPLACE into genrelinkmusicvideo(idGenre, idMVideo) values(?, ?)"
else: # Item is invalid
return
cursor.execute(query, (idGenre, id)) cursor.execute(query, (idGenre, id))
def AddCountriesToMedia(self, id, countries, mediatype, cursor): def AddCountriesToMedia(self, id, countries, mediatype, cursor):
@ -1041,7 +1067,6 @@ class WriteKodiVideoDB():
query = "INSERT INTO studio(studio_id, name) values(?, ?)" query = "INSERT INTO studio(studio_id, name) values(?, ?)"
cursor.execute(query, (studio_id,studio)) cursor.execute(query, (studio_id,studio))
self.logMsg("Add Studios to media, processing: %s" % studio, 1) self.logMsg("Add Studios to media, processing: %s" % studio, 1)
finally: # Assign studio to item finally: # Assign studio to item
query = "INSERT OR REPLACE INTO studio_link(studio_id, media_id, media_type) values(?, ?, ?)" query = "INSERT OR REPLACE INTO studio_link(studio_id, media_id, media_type) values(?, ?, ?)"
cursor.execute(query, (studio_id, id, mediatype)) cursor.execute(query, (studio_id, id, mediatype))
@ -1050,7 +1075,6 @@ class WriteKodiVideoDB():
cursor.execute("SELECT idstudio as idstudio FROM studio WHERE strstudio = ?",(studio,)) cursor.execute("SELECT idstudio as idstudio FROM studio WHERE strstudio = ?",(studio,))
try: try:
idstudio = cursor.fetchone()[0] idstudio = cursor.fetchone()[0]
except: # Studio does not exists. except: # Studio does not exists.
cursor.execute("select coalesce(max(idstudio),0) as idstudio from studio") cursor.execute("select coalesce(max(idstudio),0) as idstudio from studio")
idstudio = cursor.fetchone()[0] + 1 idstudio = cursor.fetchone()[0] + 1
@ -1058,8 +1082,8 @@ class WriteKodiVideoDB():
query = "INSERT INTO studio(idstudio, strstudio) values(?, ?)" query = "INSERT INTO studio(idstudio, strstudio) values(?, ?)"
cursor.execute(query, (idstudio,studio)) cursor.execute(query, (idstudio,studio))
self.logMsg("Add Studios to media, processing: %s" % studio, 1) self.logMsg("Add Studios to media, processing: %s" % studio, 1)
finally: # Assign studio to item finally: # Assign studio to item
if "movie" in mediatype: if "movie" in mediatype:
query = "INSERT OR REPLACE INTO studiolinkmovie(idstudio, idMovie) values(?, ?)" query = "INSERT OR REPLACE INTO studiolinkmovie(idstudio, idMovie) values(?, ?)"
elif "musicvideo" in mediatype: elif "musicvideo" in mediatype:
@ -1095,7 +1119,8 @@ class WriteKodiVideoDB():
query = "INSERT OR REPLACE INTO tag_link(tag_id, media_id, media_type) values(?, ?, ?)" query = "INSERT OR REPLACE INTO tag_link(tag_id, media_id, media_type) values(?, ?, ?)"
cursor.execute(query, (tag_id, id, mediatype)) cursor.execute(query, (tag_id, id, mediatype))
else: else:
cursor.execute("DELETE FROM tag_link WHERE media_id = ? AND media_type = ? AND tag_id = ?", (id, mediatype, tag_id,)) query = "DELETE FROM tag_link WHERE media_id = ? AND media_type = ? AND tag_id = ?"
cursor.execute(query, (id, mediatype, tag_id))
else: else:
# Kodi Gotham or Helix # Kodi Gotham or Helix
cursor.execute("SELECT idTag as idTag FROM tag WHERE strTag = ?", (tag,)) cursor.execute("SELECT idTag as idTag FROM tag WHERE strTag = ?", (tag,))
@ -1115,7 +1140,8 @@ class WriteKodiVideoDB():
query = "INSERT OR REPLACE INTO taglinks(idTag, idMedia, media_type) values(?, ?, ?)" query = "INSERT OR REPLACE INTO taglinks(idTag, idMedia, media_type) values(?, ?, ?)"
cursor.execute(query, (idTag, id, mediatype)) cursor.execute(query, (idTag, id, mediatype))
else: else:
cursor.execute("DELETE FROM taglinks WHERE idMedia = ? AND media_type = ? AND idTag = ?", (id, mediatype, idTag,)) query = "DELETE FROM taglinks WHERE idMedia = ? AND media_type = ? AND idTag = ?"
cursor.execute(query, (id, mediatype, idTag))
def AddStreamDetailsToMedia(self, streamdetails, fileid, cursor): def AddStreamDetailsToMedia(self, streamdetails, fileid, cursor):
@ -1152,8 +1178,8 @@ class WriteKodiVideoDB():
setid = cursor.fetchone()[0] setid = cursor.fetchone()[0]
finally: finally:
# Assign artwork # Assign artwork
currentsetartsql = 'SELECT type, url FROM art where media_type = ? and media_id = ? and url != ""' cursor.execute('SELECT type, url FROM art WHERE media_type = ? AND media_id = ? and url != ""', ("set", setid,))
cursor.execute(currentsetartsql, ("set", setid))
existing_type_map = {} existing_type_map = {}
rows = cursor.fetchall() rows = cursor.fetchall()
for row in rows: for row in rows: