Music library - remote

Trying strm files to still have plugin paths. Will require restart
because I've added a new column to hold the full path for strm in the
event we need to delete them.
This commit is contained in:
angelblue05 2015-08-20 06:42:40 -05:00
parent eae370c33f
commit 88632dad60
4 changed files with 74 additions and 21 deletions

View file

@ -132,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/").decode('utf-8') library = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/themes/").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"])
@ -160,7 +160,7 @@ def getThemeMedia():
# Create library directory # Create library directory
if not xbmcvfs.exists(library): if not xbmcvfs.exists(library):
xbmcvfs.mkdir(library) xbmcvfs.mkdirs(library)
# Get every user view Id # Get every user view Id
userViews = [] userViews = []
@ -186,7 +186,7 @@ def getThemeMedia():
# Get paths for theme videos # Get paths for theme videos
for itemId in itemIds: for itemId in itemIds:
nfo_path = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/%s/" % itemIds[itemId]) nfo_path = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/themes/%s/" % itemIds[itemId])
# Create folders for each content # Create folders for each content
if not xbmcvfs.exists(nfo_path): if not xbmcvfs.exists(nfo_path):
xbmcvfs.mkdir(nfo_path) xbmcvfs.mkdir(nfo_path)
@ -244,7 +244,7 @@ def getThemeMedia():
if itemId in itemIds: if itemId in itemIds:
continue continue
nfo_path = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/%s/" % musicitemIds[itemId]) nfo_path = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/themes/%s/" % musicitemIds[itemId])
# Create folders for each content # Create folders for each content
if not xbmcvfs.exists(nfo_path): if not xbmcvfs.exists(nfo_path):
xbmcvfs.mkdir(nfo_path) xbmcvfs.mkdir(nfo_path)

View file

@ -164,6 +164,9 @@ class LibrarySync(threading.Thread):
try: try:
cursor.execute("ALTER TABLE emby ADD COLUMN kodi_file_id INTEGER") cursor.execute("ALTER TABLE emby ADD COLUMN kodi_file_id INTEGER")
except: pass except: pass
try:
cursor.execute("ALTER TABLE emby ADD COLUMN fullpath TEXT")
except: pass
connection.commit() connection.commit()
self.MusicFullSync(connection,cursor,pDialog) self.MusicFullSync(connection,cursor,pDialog)

View file

@ -310,6 +310,12 @@ def reset():
connection.commit() connection.commit()
cursor.close() cursor.close()
# Remove the strm and nfo
path = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/").decode('utf-8')
if xbmcvfs.exists(path):
xbmc.log("Removing %s." % path)
shutil.rmtree(path)
# reset the install run flag # reset the install run flag
#settings('SyncInstallRunDone', "false") #settings('SyncInstallRunDone', "false")

View file

@ -11,6 +11,7 @@ from ntpath import split as ntsplit
import xbmc import xbmc
import xbmcgui import xbmcgui
import xbmcaddon import xbmcaddon
import xbmcvfs
from ClientInformation import ClientInformation from ClientInformation import ClientInformation
import Utils as utils import Utils as utils
@ -201,9 +202,14 @@ class WriteKodiMusicDB():
query = "INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID, strArtists, iYear, strGenres, strReview, strImage, lastScraped, dateAdded) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" query = "INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID, strArtists, iYear, strGenres, strReview, strImage, lastScraped, dateAdded) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"
cursor.execute(query, (albumid, name, musicBrainzId, artists, year, genre, bio, thumb, lastScraped, dateadded)) cursor.execute(query, (albumid, name, musicBrainzId, artists, year, genre, bio, thumb, lastScraped, dateadded))
fullpath = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/music/%s/" % embyId).decode('utf-8')
# Create the album folder
if not xbmcvfs.exists(fullpath):
xbmcvfs.mkdir(fullpath)
# Create the reference in emby table # Create the reference in emby table
query = "INSERT INTO emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)" query = "INSERT INTO emby(emby_id, kodi_id, media_type, checksum, fullpath) values(?, ?, ?, ?, ?)"
cursor.execute(query, (embyId, albumid, "album", checksum)) cursor.execute(query, (embyId, albumid, "album", checksum, fullpath))
# Add genres # Add genres
@ -270,20 +276,41 @@ class WriteKodiMusicDB():
year = MBitem.get('ProductionYear') year = MBitem.get('ProductionYear')
bio = API().getOverview(MBitem) bio = API().getOverview(MBitem)
duration = timeInfo.get('TotalTime') duration = timeInfo.get('TotalTime')
albumId = MBitem.get('AlbumId')
# Get the path and filename fullpath = ""
playurl = PlayUtils().directPlay(MBitem) if self.directpath:
# Get the path and filename
playurl = PlayUtils().directPlay(MBitem)
try:
path, filename = ntsplit(playurl)
if "/" in playurl:
path = "%s/" % path
elif "\\" in playurl:
path = "%s\\" % path
except: return # playurl returned False
else:
# Plugin path via strm file. We need the album Id for directory and itemId for filename. To maintain, we'll add the path to the emby database.
library = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/music/").decode('utf-8')
try: # Create the music library
path, filename = ntsplit(playurl) if not xbmcvfs.exists(library):
if "/" in playurl: xbmcvfs.mkdirs(library)
path = "%s/" % path
elif "\\" in playurl: path = xbmc.translatePath("special://profile/addon_data/plugin.video.emby/library/music/%s/" % albumId).decode('utf-8')
path = "%s\\" % path
except: # playurl returned false - using server streaming path, because could not figure out plugin paths for music DB # Create the album folder
playurl = PlayUtils().directstream(MBitem, self.server, embyId, "Audio") if not xbmcvfs.exists(path):
filename = "stream.mp3" xbmcvfs.mkdir(path)
path = playurl.replace(filename, "")
filename = "%s.strm" % embyId
fullpath = "%s%s" % (path, filename)
# Create the strm file
strm = open(fullpath, 'w')
pluginpath = "plugin://plugin.video.emby/music/%s/?id=%s&mode=play" % (albumId, embyId)
strm.write(pluginpath)
strm.close()
# Validate the path in database # Validate the path in database
@ -297,7 +324,7 @@ class WriteKodiMusicDB():
cursor.execute(query, (pathid, path)) cursor.execute(query, (pathid, path))
# Get the album # Get the album
cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?", (MBitem.get("AlbumId"),)) cursor.execute("SELECT kodi_id FROM emby WHERE emby_id = ?", (albumId,))
try: try:
albumid = cursor.fetchone()[0] albumid = cursor.fetchone()[0]
except: except:
@ -346,8 +373,8 @@ class WriteKodiMusicDB():
cursor.execute(query, (songid, albumid, pathid, artists, genre, name, track, duration, year, filename, musicBrainzId, playcount, lastplayed)) cursor.execute(query, (songid, albumid, pathid, artists, genre, name, track, duration, year, filename, musicBrainzId, playcount, lastplayed))
# Create the reference in emby table # Create the reference in emby table
query = "INSERT INTO emby(emby_id, kodi_id, media_type, checksum) values(?, ?, ?, ?)" query = "INSERT INTO emby(emby_id, kodi_id, media_type, checksum, fullpath) values(?, ?, ?, ?, ?)"
cursor.execute(query, (embyId, songid, "song", checksum)) cursor.execute(query, (embyId, songid, "song", checksum, fullpath))
# Add genres # Add genres
@ -393,10 +420,27 @@ class WriteKodiMusicDB():
elif "song" in media_type: elif "song" in media_type:
self.logMsg("Deleting song from Kodi library, Id: %s" % id, 1) self.logMsg("Deleting song from Kodi library, Id: %s" % id, 1)
cursor.execute("DELETE FROM song WHERE idSong = ?", (kodi_id,)) cursor.execute("DELETE FROM song WHERE idSong = ?", (kodi_id,))
cursor.execute("SELECT fullpath FROM emby WHERE emby_id = ?", (id,))
try: # Delete the strm file
fullpath = cursor.fetchone()[0]
except: pass
else:
self.logMsg("Delete the strm %s." % fullpath)
xbmcvfs.delete(fullpath)
elif "album" in media_type: elif "album" in media_type:
self.logMsg("Deleting album from Kodi library, Id: %s" % id, 1) self.logMsg("Deleting album from Kodi library, Id: %s" % id, 1)
cursor.execute("DELETE FROM album WHERE idAlbum = ?", (kodi_id,)) cursor.execute("DELETE FROM album WHERE idAlbum = ?", (kodi_id,))
cursor.execute("SELECT fullpath FROM emby WHERE emby_id = ?", (id,))
try: # Delete the folder
fullpath = cursor.fetchone()[0]
except: pass
else:
self.logMsg("Delete the album folder %s." % fullpath)
xbmcvfs.rmdir(fullpath)
# 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,))