Correct the merging
This commit is contained in:
parent
076a998f67
commit
e3a81da2a5
5 changed files with 292 additions and 265 deletions
|
@ -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:
|
||||||
|
|
|
@ -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")
|
||||||
|
@ -155,9 +156,7 @@ def getThemeMedia():
|
||||||
dialog = xbmcgui.Dialog()
|
dialog = xbmcgui.Dialog()
|
||||||
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,16 +174,15 @@ 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)
|
if result[u'TotalRecordCount'] != 0:
|
||||||
if result[u'TotalRecordCount'] != 0:
|
for item in result[u'Items']:
|
||||||
for item in result[u'Items']:
|
itemId = item[u'Id']
|
||||||
itemId = item[u'Id']
|
folderName = item[u'Name']
|
||||||
folderName = item[u'Name']
|
folderName = utils.normalize_string(folderName.encode('utf-8'))
|
||||||
folderName = utils.normalize_string(folderName.encode('utf-8'))
|
itemIds[itemId] = folderName
|
||||||
itemIds[itemId] = folderName
|
|
||||||
|
|
||||||
# Get paths for theme videos
|
# Get paths for theme videos
|
||||||
for itemId in itemIds:
|
for itemId in itemIds:
|
||||||
|
@ -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
|
||||||
|
@ -660,4 +658,4 @@ def doMainListing():
|
||||||
addDirectoryItem("Cache all images to Kodi texture cache (advanced)", "plugin://plugin.video.emby/?mode=texturecache")
|
addDirectoryItem("Cache all images to Kodi texture cache (advanced)", "plugin://plugin.video.emby/?mode=texturecache")
|
||||||
addDirectoryItem("Sync Emby Theme Media to Kodi", "plugin://plugin.video.emby/?mode=thememedia")
|
addDirectoryItem("Sync Emby Theme Media to Kodi", "plugin://plugin.video.emby/?mode=thememedia")
|
||||||
|
|
||||||
xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
xbmcplugin.endOfDirectory(int(sys.argv[1]))
|
|
@ -148,37 +148,41 @@ 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
|
||||||
|
|
||||||
sources = open(xmlpath, 'w')
|
if xbmcvfs.exists(xmlpath):
|
||||||
sources.write(
|
# add some way to writing dummy path to existing sources.xml
|
||||||
|
pass
|
||||||
'<sources>\n\t'
|
else:
|
||||||
'<programs>\n\t\t'
|
sources = open(xmlpath, 'w')
|
||||||
'<default pathversion="1"></default>\n\t'
|
sources.write(
|
||||||
'</programs>\n\t'
|
|
||||||
'<video>\n\t\t'
|
'<sources>\n\t'
|
||||||
'<default pathversion="1"></default>\n\t\t'
|
'<programs>\n\t\t'
|
||||||
'<source>\n\t\t\t'
|
'<default pathversion="1"></default>\n\t'
|
||||||
'<name>dummy one</name>\n\t\t\t'
|
'</programs>\n\t'
|
||||||
'<path pathversion="1">smb://embydummy/dummypath1/</path>\n\t\t\t'
|
'<video>\n\t\t'
|
||||||
'<allowsharing>true</allowsharing>\n\t\t'
|
'<default pathversion="1"></default>\n\t\t'
|
||||||
'</source>\n\t\t'
|
'<source>\n\t\t\t'
|
||||||
'<source>\n\t\t\t'
|
'<name>dummy one</name>\n\t\t\t'
|
||||||
'<name>dummy two</name>\n\t\t\t'
|
'<path pathversion="1">smb://embydummy/dummypath1/</path>\n\t\t\t'
|
||||||
'<path pathversion="1">smb://embydummy/dummypath2/</path>\n\t\t\t'
|
'<allowsharing>true</allowsharing>\n\t\t'
|
||||||
'<allowsharing>true</allowsharing>\n\t\t'
|
'</source>\n\t\t'
|
||||||
'</source>\n\t'
|
'<source>\n\t\t\t'
|
||||||
'</video>\n\t'
|
'<name>dummy two</name>\n\t\t\t'
|
||||||
'<music>\n\t\t'
|
'<path pathversion="1">smb://embydummy/dummypath2/</path>\n\t\t\t'
|
||||||
'<default pathversion="1"></default>\n\t'
|
'<allowsharing>true</allowsharing>\n\t\t'
|
||||||
'</music>\n\t'
|
'</source>\n\t'
|
||||||
'<pictures>\n\t\t'
|
'</video>\n\t'
|
||||||
'<default pathversion="1"></default>\n\t'
|
'<music>\n\t\t'
|
||||||
'</pictures>\n\t'
|
'<default pathversion="1"></default>\n\t'
|
||||||
'<files>\n\t\t'
|
'</music>\n\t'
|
||||||
'<default pathversion="1"></default>\n\t'
|
'<pictures>\n\t\t'
|
||||||
'</files>\n'
|
'<default pathversion="1"></default>\n\t'
|
||||||
'</sources>'
|
'</pictures>\n\t'
|
||||||
)
|
'<files>\n\t\t'
|
||||||
|
'<default pathversion="1"></default>\n\t'
|
||||||
|
'</files>\n'
|
||||||
|
'</sources>'
|
||||||
|
)
|
||||||
|
|
||||||
def CleanName(filename):
|
def CleanName(filename):
|
||||||
validFilenameChars = "-_.() %s%s" % (string.ascii_letters, string.digits)
|
validFilenameChars = "-_.() %s%s" % (string.ascii_letters, string.digits)
|
||||||
|
|
|
@ -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)
|
||||||
|
@ -234,7 +235,7 @@ class WriteKodiMusicDB():
|
||||||
cursor.execute(query, (artistid, name, str(year)))
|
cursor.execute(query, (artistid, name, str(year)))
|
||||||
|
|
||||||
def addOrUpdateSongToKodiLibrary(self, embyId, connection, cursor):
|
def addOrUpdateSongToKodiLibrary(self, embyId, connection, cursor):
|
||||||
|
|
||||||
kodiVersion = self.kodiversion
|
kodiVersion = self.kodiversion
|
||||||
|
|
||||||
MBitem = ReadEmbyDB().getFullItem(embyId)
|
MBitem = ReadEmbyDB().getFullItem(embyId)
|
||||||
|
@ -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]
|
||||||
|
|
|
@ -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()
|
||||||
|
@ -73,12 +72,12 @@ class WriteKodiVideoDB():
|
||||||
cursor.close
|
cursor.close
|
||||||
|
|
||||||
def addOrUpdateMovieToKodiLibrary(self, embyId, connection, cursor, viewTag):
|
def addOrUpdateMovieToKodiLibrary(self, embyId, connection, cursor, viewTag):
|
||||||
|
|
||||||
addon = self.addon
|
addon = self.addon
|
||||||
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,8 +88,9 @@ 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)
|
||||||
people = API().getPeople(MBitem)
|
people = API().getPeople(MBitem)
|
||||||
|
@ -132,52 +132,53 @@ class WriteKodiVideoDB():
|
||||||
trailerUrl = "plugin://plugin.video.youtube/play/?video_id=%s" % trailerId
|
trailerUrl = "plugin://plugin.video.youtube/play/?video_id=%s" % trailerId
|
||||||
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)
|
||||||
try:
|
|
||||||
if "plugin://" in playurl:
|
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:
|
||||||
|
if "plugin://" in playurl:
|
||||||
|
fileext = ""
|
||||||
|
else:
|
||||||
|
path, fileext = ntsplit(playurl)
|
||||||
|
except: # The playurl may return False
|
||||||
fileext = ""
|
fileext = ""
|
||||||
|
|
||||||
|
filename = "plugin://plugin.video.emby/movies/%s/?filename=%s&id=%s&mode=play" % (embyId, fileext, embyId)
|
||||||
|
path = "plugin://plugin.video.emby/movies/%s/" % embyId
|
||||||
|
|
||||||
|
# If the bookmark was created from widget
|
||||||
|
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ?", (fileext,))
|
||||||
|
try: # Remove Kodi bookmark - messes with plugin path bookmark
|
||||||
|
result = cursor.fetchone()[0]
|
||||||
|
self.setKodiResumePoint(result, 0, 0, cursor)
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
# If the bookmark was created within the library
|
||||||
|
plugindummy = "plugin://plugin.video.emby/"
|
||||||
|
cursor.execute("SELECT idPath FROM path WHERE strPath = ?", (plugindummy,))
|
||||||
|
try:
|
||||||
|
pathiddummy = cursor.fetchone()[0]
|
||||||
|
except: pass
|
||||||
else:
|
else:
|
||||||
path, fileext = ntsplit(playurl)
|
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?", (filename, pathiddummy,))
|
||||||
except: return # playurl returned False
|
try: # Remove Kodi bookmark - creates a ghost bookmark for widgets
|
||||||
else: # Set filename and path
|
|
||||||
|
|
||||||
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)
|
|
||||||
path = "plugin://plugin.video.emby/movies/%s/" % embyId
|
|
||||||
|
|
||||||
# If the bookmark was created from widget
|
|
||||||
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ?", (fileext,))
|
|
||||||
try: # Remove Kodi bookmark - messes with plugin path bookmark
|
|
||||||
result = cursor.fetchone()[0]
|
result = cursor.fetchone()[0]
|
||||||
self.setKodiResumePoint(result, 0, 0, cursor)
|
self.setKodiResumePoint(result, 0, 0, cursor)
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
# If the bookmark was created within the library
|
|
||||||
plugindummy = "plugin://plugin.video.emby/"
|
|
||||||
cursor.execute("SELECT idPath FROM path WHERE strPath = ?", (plugindummy,))
|
|
||||||
try:
|
|
||||||
pathiddummy = cursor.fetchone()[0]
|
|
||||||
except: pass
|
|
||||||
else:
|
|
||||||
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?", (filename, pathiddummy,))
|
|
||||||
try: # Remove Kodi bookmark - creates a ghost bookmark for widgets
|
|
||||||
result = cursor.fetchone()[0]
|
|
||||||
self.setKodiResumePoint(result, 0, 0, cursor)
|
|
||||||
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,))
|
||||||
|
@ -235,7 +236,7 @@ class WriteKodiVideoDB():
|
||||||
|
|
||||||
|
|
||||||
# Update or insert actors
|
# Update or insert actors
|
||||||
self.AddPeopleToMedia(movieid ,MBitem.get('People'), "movie", connection, cursor)
|
self.AddPeopleToMedia(movieid, MBitem.get('People'), "movie", connection, cursor)
|
||||||
|
|
||||||
# Update artwork
|
# Update artwork
|
||||||
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary", mediaType = "movie"), movieid, "movie", "thumb", cursor)
|
self.addOrUpdateArt(API().getArtwork(MBitem, "Primary", mediaType = "movie"), movieid, "movie", "thumb", cursor)
|
||||||
|
@ -274,124 +275,135 @@ class WriteKodiVideoDB():
|
||||||
resume = resume - jumpback
|
resume = resume - jumpback
|
||||||
self.setKodiResumePoint(fileid, resume, total, cursor)
|
self.setKodiResumePoint(fileid, resume, total, cursor)
|
||||||
|
|
||||||
def addOrUpdateMusicVideoToKodiLibrary(self, embyId ,connection, cursor):
|
def addOrUpdateMusicVideoToKodiLibrary( self, embyId ,connection, cursor):
|
||||||
|
|
||||||
|
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()
|
||||||
|
|
||||||
addon = self.addon
|
|
||||||
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 = PlayUtils().directPlay(MBitem)
|
||||||
# playurl can return False
|
#use the direct file path
|
||||||
playurl = PlayUtils().directPlay(MBitem)
|
if "\\" in playurl:
|
||||||
try:
|
filename = playurl.rsplit("\\",1)[-1]
|
||||||
path, filename = ntsplit(playurl)
|
path = playurl.replace(filename,"")
|
||||||
if "\\" in path:
|
elif "/" in playurl:
|
||||||
path = "%s\\" % path
|
filename = playurl.rsplit("/",1)[-1]
|
||||||
elif "/" in path:
|
path = playurl.replace(filename,"")
|
||||||
path = "%s/" % path
|
else:
|
||||||
except:
|
|
||||||
#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
|
#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)
|
path = server + "/Video/%s/" %MBitem["Id"]
|
||||||
filename = "stream.mp4"
|
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)
|
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
|
|
||||||
cursor.execute("select coalesce(max(idMVideo),0) as idMVideo from musicvideo")
|
|
||||||
idMVideo = cursor.fetchone()[0] + 1
|
|
||||||
query = "INSERT INTO musicvideo(idMVideo, idFile, c00, c04, c05, c06, c07, c08, c09, c10, c11, c12) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
|
|
||||||
cursor.execute(query, (idMVideo, fileid, title, runtime, director, studio, year, plot, album, artist, genre, track))
|
|
||||||
|
|
||||||
# Create the reference in emby table
|
|
||||||
query = "INSERT INTO emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
|
||||||
cursor.execute(query, (embyId, idMVideo, "musicvideo", checksum))
|
|
||||||
|
|
||||||
|
|
||||||
# Update or insert actors
|
#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")
|
||||||
|
idMVideo = cursor.fetchone()[0]
|
||||||
|
idMVideo = idMVideo + 1
|
||||||
|
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
|
||||||
|
pathsql = "INSERT into emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)"
|
||||||
|
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 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)
|
||||||
|
|
||||||
def addOrUpdateTvShowToKodiLibrary(self, embyId, connection, cursor, viewTag):
|
|
||||||
|
|
||||||
|
#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 ):
|
||||||
|
|
||||||
|
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)
|
||||||
|
@ -464,7 +482,7 @@ class WriteKodiVideoDB():
|
||||||
# Local path
|
# Local path
|
||||||
path = "%s\\" % playurl
|
path = "%s\\" % playurl
|
||||||
toplevelpath = "%s\\" % dirname(dirname(path))
|
toplevelpath = "%s\\" % dirname(dirname(path))
|
||||||
else: # Set plugin path
|
else:# Set plugin path
|
||||||
path = "plugin://plugin.video.emby/tvshows/%s/" % embyId
|
path = "plugin://plugin.video.emby/tvshows/%s/" % embyId
|
||||||
toplevelpath = "plugin://plugin.video.emby/"
|
toplevelpath = "plugin://plugin.video.emby/"
|
||||||
|
|
||||||
|
@ -546,6 +564,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):
|
||||||
|
|
||||||
|
@ -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,55 +604,58 @@ 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)
|
||||||
try:
|
|
||||||
if "plugin://" in playurl:
|
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:
|
||||||
|
if "plugin://" in playurl:
|
||||||
|
fileext = ""
|
||||||
|
else:
|
||||||
|
path, fileext = ntsplit(playurl)
|
||||||
|
except: # The playurl may return False
|
||||||
fileext = ""
|
fileext = ""
|
||||||
|
|
||||||
|
filename = "plugin://plugin.video.emby/tvshows/%s/?filename=%s&id=%s&mode=play" % (seriesId, fileext, embyId)
|
||||||
|
path = "plugin://plugin.video.emby/tvshows/%s/" % seriesId
|
||||||
|
|
||||||
|
# If the bookmark was created from widget
|
||||||
|
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ?", (fileext,))
|
||||||
|
try: # Remove Kodi bookmark - messes with plugin path bookmark
|
||||||
|
result = cursor.fetchone()[0]
|
||||||
|
self.setKodiResumePoint(result, 0, 0, cursor)
|
||||||
|
except: pass
|
||||||
|
|
||||||
|
# If the bookmark was created within the library
|
||||||
|
plugindummy = "plugin://plugin.video.emby/"
|
||||||
|
cursor.execute("SELECT idPath FROM path WHERE strPath = ?", (plugindummy,))
|
||||||
|
try:
|
||||||
|
pathiddummy = cursor.fetchone()[0]
|
||||||
|
except: pass
|
||||||
else:
|
else:
|
||||||
path, fileext = ntsplit(playurl)
|
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?", (filename, pathiddummy,))
|
||||||
except: return # playurl returned False
|
try: # Remove Kodi bookmark - creates a ghost bookmark for widgets
|
||||||
else: # Set filename and path
|
|
||||||
|
|
||||||
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)
|
|
||||||
path = "plugin://plugin.video.emby/tvshows/%s/" % seriesId
|
|
||||||
|
|
||||||
# If the bookmark was created from widget
|
|
||||||
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ?", (fileext,))
|
|
||||||
try: # Remove Kodi bookmark - messes with plugin path bookmark
|
|
||||||
result = cursor.fetchone()[0]
|
result = cursor.fetchone()[0]
|
||||||
self.setKodiResumePoint(result, 0, 0, cursor)
|
self.setKodiResumePoint(result, 0, 0, cursor)
|
||||||
except: pass
|
except: pass
|
||||||
|
|
||||||
# If the bookmark was created within the library
|
|
||||||
plugindummy = "plugin://plugin.video.emby/"
|
|
||||||
cursor.execute("SELECT idPath FROM path WHERE strPath = ?", (plugindummy,))
|
|
||||||
try:
|
|
||||||
pathiddummy = cursor.fetchone()[0]
|
|
||||||
except: pass
|
|
||||||
else:
|
|
||||||
cursor.execute("SELECT idFile as fileid FROM files WHERE strFilename = ? and idPath = ?", (filename, pathiddummy,))
|
|
||||||
try: # Remove Kodi bookmark - creates a ghost bookmark for widgets
|
|
||||||
result = cursor.fetchone()[0]
|
|
||||||
self.setKodiResumePoint(result, 0, 0, cursor)
|
|
||||||
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,))
|
||||||
|
@ -657,7 +681,7 @@ class WriteKodiVideoDB():
|
||||||
else: # File exists
|
else: # File exists
|
||||||
query = "UPDATE files SET playCount = ?, lastPlayed = ? WHERE idFile = ?"
|
query = "UPDATE files SET playCount = ?, lastPlayed = ? WHERE idFile = ?"
|
||||||
cursor.execute(query, (playcount, dateplayed, fileid))
|
cursor.execute(query, (playcount, dateplayed, fileid))
|
||||||
|
|
||||||
# Validate the season exists in Emby and in database
|
# Validate the season exists in Emby and in database
|
||||||
if season is None:
|
if season is None:
|
||||||
self.logMsg("SKIP adding episode to Kodi Library, no ParentIndexNumber - ID: %s - %s" % (embyId, title))
|
self.logMsg("SKIP adding episode to Kodi Library, no ParentIndexNumber - ID: %s - %s" % (embyId, title))
|
||||||
|
@ -714,7 +738,7 @@ class WriteKodiVideoDB():
|
||||||
resume = resume - jumpback
|
resume = resume - jumpback
|
||||||
self.setKodiResumePoint(fileid, resume, total, cursor)
|
self.setKodiResumePoint(fileid, resume, total, cursor)
|
||||||
|
|
||||||
def deleteItemFromKodiLibrary(self, id, connection, cursor ):
|
def deleteItemFromKodiLibrary(self, id, connection, cursor):
|
||||||
|
|
||||||
cursor.execute("SELECT kodi_id, media_type FROM emby WHERE emby_id = ?", (id,))
|
cursor.execute("SELECT kodi_id, media_type FROM emby WHERE emby_id = ?", (id,))
|
||||||
try:
|
try:
|
||||||
|
@ -742,7 +766,7 @@ class WriteKodiVideoDB():
|
||||||
# Delete the record in emby table
|
# Delete the record in emby table
|
||||||
cursor.execute("DELETE FROM emby WHERE emby_id = ?", (id,))
|
cursor.execute("DELETE FROM emby WHERE emby_id = ?", (id,))
|
||||||
|
|
||||||
def updateSeasons(self,embyTvShowId, kodiTvShowId, connection, cursor):
|
def updateSeasons(self, embyTvShowId, kodiTvShowId, connection, cursor):
|
||||||
|
|
||||||
seasonData = ReadEmbyDB().getTVShowSeasons(embyTvShowId)
|
seasonData = ReadEmbyDB().getTVShowSeasons(embyTvShowId)
|
||||||
|
|
||||||
|
@ -786,11 +810,11 @@ class WriteKodiVideoDB():
|
||||||
self.addOrUpdateArt(imageUrl, seasonid, "season", "poster", cursor)
|
self.addOrUpdateArt(imageUrl, seasonid, "season", "poster", cursor)
|
||||||
|
|
||||||
def addOrUpdateArt(self, imageUrl, kodiId, mediaType, imageType, cursor):
|
def addOrUpdateArt(self, imageUrl, kodiId, mediaType, imageType, cursor):
|
||||||
|
|
||||||
if imageUrl:
|
if imageUrl:
|
||||||
|
|
||||||
cacheimage = False
|
|
||||||
|
|
||||||
|
cacheimage = False
|
||||||
|
|
||||||
cursor.execute("SELECT url FROM art WHERE media_id = ? AND media_type = ? AND type = ?", (kodiId, mediaType, imageType,))
|
cursor.execute("SELECT url FROM art WHERE media_id = ? AND media_type = ? AND type = ?", (kodiId, mediaType, imageType,))
|
||||||
try: # Update the artwork
|
try: # Update the artwork
|
||||||
url = cursor.fetchone()[0]
|
url = cursor.fetchone()[0]
|
||||||
|
@ -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"):
|
||||||
|
@ -836,7 +860,7 @@ class WriteKodiVideoDB():
|
||||||
cursor.execute("SELECT actor_id as actorid FROM actor WHERE name = ?", (name,))
|
cursor.execute("SELECT actor_id as actorid FROM actor WHERE name = ?", (name,))
|
||||||
else:
|
else:
|
||||||
# Kodi Gotham or Helix
|
# Kodi Gotham or Helix
|
||||||
cursor.execute("SELECT idActor as actorid FROM actors WHERE strActor = ?",(name,))
|
cursor.execute("SELECT idActor as actorid FROM actors WHERE strActor = ?", (name,))
|
||||||
|
|
||||||
try: # Update person in database
|
try: # Update person in database
|
||||||
actorid = cursor.fetchone()[0]
|
actorid = cursor.fetchone()[0]
|
||||||
|
@ -951,7 +975,7 @@ class WriteKodiVideoDB():
|
||||||
genre_id = cursor.fetchone()[0] + 1
|
genre_id = cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
query = "INSERT INTO genre(genre_id, name) values(?, ?)"
|
query = "INSERT INTO genre(genre_id, name) values(?, ?)"
|
||||||
cursor.execute(query, (genre_id,genre))
|
cursor.execute(query, (genre_id, genre))
|
||||||
self.logMsg("Add Genres to media, processing: %s" % genre, 1)
|
self.logMsg("Add Genres to media, processing: %s" % genre, 1)
|
||||||
finally:
|
finally:
|
||||||
# Assign genre to item
|
# Assign genre to item
|
||||||
|
@ -968,7 +992,7 @@ class WriteKodiVideoDB():
|
||||||
idGenre = cursor.fetchone()[0] + 1
|
idGenre = cursor.fetchone()[0] + 1
|
||||||
|
|
||||||
query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)"
|
query = "INSERT INTO genre(idGenre, strGenre) values(?, ?)"
|
||||||
cursor.execute(query, (idGenre,genre))
|
cursor.execute(query, (idGenre, genre))
|
||||||
self.logMsg("Add Genres to media, processing: %s" % genre, 1)
|
self.logMsg("Add Genres to media, processing: %s" % genre, 1)
|
||||||
finally:
|
finally:
|
||||||
# Assign genre to item
|
# Assign genre to item
|
||||||
|
@ -978,8 +1002,10 @@ 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):
|
||||||
|
|
||||||
kodiVersion = self.kodiversion
|
kodiVersion = self.kodiversion
|
||||||
|
@ -1031,7 +1057,7 @@ class WriteKodiVideoDB():
|
||||||
|
|
||||||
if kodiVersion == 15 or kodiVersion == 16:
|
if kodiVersion == 15 or kodiVersion == 16:
|
||||||
# Kodi Isengard
|
# Kodi Isengard
|
||||||
cursor.execute("SELECT studio_id as studio_id FROM studio WHERE name = ?",(studio,))
|
cursor.execute("SELECT studio_id as studio_id FROM studio WHERE name = ?", (studio,))
|
||||||
try:
|
try:
|
||||||
studio_id = cursor.fetchone()[0]
|
studio_id = cursor.fetchone()[0]
|
||||||
except: # Studio does not exists.
|
except: # Studio does not exists.
|
||||||
|
@ -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:
|
||||||
|
@ -1070,7 +1094,7 @@ class WriteKodiVideoDB():
|
||||||
query = "INSERT OR REPLACE INTO studiolinkepisode(idstudio, idEpisode) values(?, ?)"
|
query = "INSERT OR REPLACE INTO studiolinkepisode(idstudio, idEpisode) values(?, ?)"
|
||||||
cursor.execute(query, (idstudio, id))
|
cursor.execute(query, (idstudio, id))
|
||||||
|
|
||||||
def AddTagToMedia(self, id, tag, mediatype, cursor, doRemove = False):
|
def AddTagToMedia(self, id, tag, mediatype, cursor, doRemove=False):
|
||||||
|
|
||||||
kodiVersion = self.kodiversion
|
kodiVersion = self.kodiversion
|
||||||
|
|
||||||
|
@ -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,))
|
||||||
|
@ -1114,8 +1139,9 @@ class WriteKodiVideoDB():
|
||||||
if not doRemove:
|
if not doRemove:
|
||||||
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:
|
||||||
|
@ -1184,7 +1210,7 @@ class WriteKodiVideoDB():
|
||||||
|
|
||||||
strSet = boxset['Name']
|
strSet = boxset['Name']
|
||||||
boxsetmovieid = boxsetmovie['Id']
|
boxsetmovieid = boxsetmovie['Id']
|
||||||
cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?",(boxsetmovieid,))
|
cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?", (boxsetmovieid,))
|
||||||
try:
|
try:
|
||||||
movieid = cursor.fetchone()[0]
|
movieid = cursor.fetchone()[0]
|
||||||
cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,))
|
cursor.execute("SELECT idSet FROM sets WHERE strSet = ?", (strSet,))
|
||||||
|
|
Loading…
Reference in a new issue