mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-12-25 02:06:09 +00:00
Fix artists/music
This commit is contained in:
parent
0af7dfeae1
commit
623c6cab85
3 changed files with 129 additions and 47 deletions
|
@ -143,6 +143,21 @@ class Embydb_Functions():
|
||||||
return item
|
return item
|
||||||
except: return None
|
except: return None
|
||||||
|
|
||||||
|
def getItem_byWildId(self, embyid):
|
||||||
|
|
||||||
|
embycursor = self.embycursor
|
||||||
|
|
||||||
|
query = ' '.join((
|
||||||
|
|
||||||
|
"SELECT kodi_id, media_type",
|
||||||
|
"FROM emby",
|
||||||
|
"WHERE emby_id LIKE ?"
|
||||||
|
))
|
||||||
|
embycursor.execute(query, (embyid+"%",))
|
||||||
|
items = embycursor.fetchall()
|
||||||
|
|
||||||
|
return items
|
||||||
|
|
||||||
def getItem_byView(self, mediafolderid):
|
def getItem_byView(self, mediafolderid):
|
||||||
|
|
||||||
embycursor = self.embycursor
|
embycursor = self.embycursor
|
||||||
|
@ -303,3 +318,8 @@ class Embydb_Functions():
|
||||||
query = "DELETE FROM emby WHERE emby_id = ?"
|
query = "DELETE FROM emby WHERE emby_id = ?"
|
||||||
self.embycursor.execute(query, (embyid,))
|
self.embycursor.execute(query, (embyid,))
|
||||||
|
|
||||||
|
def removeWildItem(self, embyid):
|
||||||
|
|
||||||
|
query = "DELETE FROM emby WHERE emby_id LIKE ?"
|
||||||
|
self.embycursor.execute(query, (embyid+"%",))
|
||||||
|
|
|
@ -2010,6 +2010,7 @@ class Music(Items):
|
||||||
# Process single song
|
# Process single song
|
||||||
kodiversion = self.kodiversion
|
kodiversion = self.kodiversion
|
||||||
kodicursor = self.kodicursor
|
kodicursor = self.kodicursor
|
||||||
|
emby = self.emby
|
||||||
emby_db = self.emby_db
|
emby_db = self.emby_db
|
||||||
kodi_db = self.kodi_db
|
kodi_db = self.kodi_db
|
||||||
artwork = self.artwork
|
artwork = self.artwork
|
||||||
|
@ -2124,14 +2125,22 @@ class Music(Items):
|
||||||
emby_dbalbum = emby_db.getItem_byId(item['AlbumId'])
|
emby_dbalbum = emby_db.getItem_byId(item['AlbumId'])
|
||||||
albumid = emby_dbalbum[0]
|
albumid = emby_dbalbum[0]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# No album Id associated to the song.
|
# Verify if there's an album associated.
|
||||||
self.logMsg("Song itemid: %s has no albumId." % itemid, 1)
|
self.logMsg("Song itemid: %s has no albumId associated." % itemid, 1)
|
||||||
return
|
album_name = item.get('Album')
|
||||||
|
if album_name:
|
||||||
|
albumid = kodi_db.addAlbum(album_name, API.getProvider('MusicBrainzAlbum'))
|
||||||
|
emby_db.addReference("%salbum%s" % (itemid, albumid), albumid, "MusicAlbum_", "album")
|
||||||
|
else:
|
||||||
|
# No album Id associated to the song.
|
||||||
|
self.logMsg("Song itemid: %s has no albumId associated." % itemid, 1)
|
||||||
|
return False
|
||||||
|
|
||||||
except TypeError:
|
except TypeError:
|
||||||
# No album found. Let's create it
|
# No album found. Let's create it
|
||||||
self.logMsg("Album database entry missing.", 1)
|
self.logMsg("Album database entry missing.", 1)
|
||||||
emby_albumId = item['AlbumId']
|
emby_albumId = item['AlbumId']
|
||||||
album = self.emby.getItem(emby_albumId)
|
album = emby.getItem(emby_albumId)
|
||||||
self.add_updateAlbum(album)
|
self.add_updateAlbum(album)
|
||||||
emby_dbalbum = emby_db.getItem_byId(emby_albumId)
|
emby_dbalbum = emby_db.getItem_byId(emby_albumId)
|
||||||
try:
|
try:
|
||||||
|
@ -2205,76 +2214,103 @@ class Music(Items):
|
||||||
)
|
)
|
||||||
kodicursor.execute(query, (songid, albumid, track, title, duration))
|
kodicursor.execute(query, (songid, albumid, track, title, duration))
|
||||||
|
|
||||||
# Verify if album has artists
|
# Link song to artists
|
||||||
addArtist = False
|
for index, artist in enumerate(item['ArtistItems']):
|
||||||
query = ' '.join((
|
|
||||||
|
|
||||||
"SELECT strArtists",
|
|
||||||
"FROM album",
|
|
||||||
"WHERE idAlbum = ?"
|
|
||||||
))
|
|
||||||
kodicursor.execute(query, (albumid,))
|
|
||||||
result = kodicursor.fetchone()
|
|
||||||
if result and result[0] == "":
|
|
||||||
addArtist = True
|
|
||||||
|
|
||||||
if item['AlbumArtists']:
|
|
||||||
album_artists = item['AlbumArtists']
|
|
||||||
else:
|
|
||||||
album_artists = item['ArtistItems']
|
|
||||||
|
|
||||||
# Link song to artist
|
|
||||||
artists_name = []
|
|
||||||
for artist in album_artists:
|
|
||||||
artist_name = artist['Name']
|
artist_name = artist['Name']
|
||||||
artists_name.append(artist_name)
|
artist_eid = artist['Id']
|
||||||
emby_dbartist = emby_db.getItem_byId(artist['Id'])
|
artist_edb = emby_db.getItem_byId(artist_eid)
|
||||||
try:
|
try:
|
||||||
artistid = emby_dbartist[0]
|
artistid = artist_edb[0]
|
||||||
except: pass
|
except TypeError:
|
||||||
else:
|
# Artist is missing from emby database, add it.
|
||||||
|
artist_full = emby.getItem(artist_eid)
|
||||||
|
self.add_updateArtist(artist_full)
|
||||||
|
artist_edb = emby_db.getItem_byId(artist_eid)
|
||||||
|
artistid = artist_edb[0]
|
||||||
|
finally:
|
||||||
query = (
|
query = (
|
||||||
'''
|
'''
|
||||||
INSERT OR REPLACE INTO song_artist(idArtist, idSong, strArtist)
|
INSERT OR REPLACE INTO song_artist(idArtist, idSong, iOrder, strArtist)
|
||||||
|
|
||||||
|
VALUES (?, ?, ?, ?)
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
kodicursor.execute(query, (artistid, songid, index, artist_name))
|
||||||
|
|
||||||
|
# Verify if album artist exists
|
||||||
|
album_artists = []
|
||||||
|
for artist in item['AlbumArtists']:
|
||||||
|
|
||||||
|
artist_name = artist['Name']
|
||||||
|
album_artists.append(artist_name)
|
||||||
|
artist_eid = artist['Id']
|
||||||
|
artist_edb = emby_db.getItem_byId(artist_eid)
|
||||||
|
try:
|
||||||
|
artistid = artist_edb[0]
|
||||||
|
except TypeError:
|
||||||
|
# Artist is missing from emby database, add it.
|
||||||
|
artist_full = emby.getItem(artist_eid)
|
||||||
|
self.add_updateArtist(artist_full)
|
||||||
|
artist_edb = emby_db.getItem_byId(artist_eid)
|
||||||
|
artistid = artist_edb[0]
|
||||||
|
finally:
|
||||||
|
query = (
|
||||||
|
'''
|
||||||
|
INSERT OR REPLACE INTO album_artist(idArtist, idAlbum, strArtist)
|
||||||
|
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
kodicursor.execute(query, (artistid, songid, artist_name))
|
kodicursor.execute(query, (artistid, albumid, artist_name))
|
||||||
|
# Update discography
|
||||||
if addArtist:
|
if item.get('Album'):
|
||||||
query = (
|
query = (
|
||||||
'''
|
'''
|
||||||
INSERT OR REPLACE INTO album_artist(idArtist, idAlbum, strArtist)
|
INSERT OR REPLACE INTO discography(idArtist, strAlbum, strYear)
|
||||||
|
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
kodicursor.execute(query, (artistid, albumid, artist_name))
|
kodicursor.execute(query, (artistid, item['Album'], 0))
|
||||||
else:
|
else:
|
||||||
if addArtist:
|
album_artists = " / ".join(album_artists)
|
||||||
artists_onalbum = " / ".join(artists_name)
|
query = ' '.join((
|
||||||
|
|
||||||
|
"SELECT strArtists",
|
||||||
|
"FROM album",
|
||||||
|
"WHERE idAlbum = ?"
|
||||||
|
))
|
||||||
|
kodicursor.execute(query, (albumid,))
|
||||||
|
result = kodicursor.fetchone()
|
||||||
|
if result and result[0] != album_artists:
|
||||||
|
# Field is empty
|
||||||
if kodiversion in (16, 17):
|
if kodiversion in (16, 17):
|
||||||
# Kodi Jarvis, Krypton
|
# Kodi Jarvis, Krypton
|
||||||
query = "UPDATE album SET strArtists = ? WHERE idAlbum = ?"
|
query = "UPDATE album SET strArtists = ? WHERE idAlbum = ?"
|
||||||
kodicursor.execute(query, (artists_onalbum, albumid))
|
kodicursor.execute(query, (album_artists, albumid))
|
||||||
elif kodiversion == 15:
|
elif kodiversion == 15:
|
||||||
# Kodi Isengard
|
# Kodi Isengard
|
||||||
query = "UPDATE album SET strArtists = ? WHERE idAlbum = ?"
|
query = "UPDATE album SET strArtists = ? WHERE idAlbum = ?"
|
||||||
kodicursor.execute(query, (artists_onalbum, albumid))
|
kodicursor.execute(query, (album_artists, albumid))
|
||||||
else:
|
else:
|
||||||
# Kodi Helix
|
# Kodi Helix
|
||||||
query = "UPDATE album SET strArtists = ? WHERE idAlbum = ?"
|
query = "UPDATE album SET strArtists = ? WHERE idAlbum = ?"
|
||||||
kodicursor.execute(query, (artists_onalbum, albumid))
|
kodicursor.execute(query, (album_artists, albumid))
|
||||||
|
|
||||||
# Add genres
|
# Add genres
|
||||||
kodi_db.addMusicGenres(songid, genres, "song")
|
kodi_db.addMusicGenres(songid, genres, "song")
|
||||||
|
|
||||||
# Update artwork
|
# Update artwork
|
||||||
allart = artwork.getAllArtwork(item, parentInfo=True)
|
allart = artwork.getAllArtwork(item, parentInfo=True)
|
||||||
if hasEmbeddedCover:
|
if hasEmbeddedCover:
|
||||||
allart["Primary"] = "image://music@" + artwork.single_urlencode( playurl )
|
allart["Primary"] = "image://music@" + artwork.single_urlencode( playurl )
|
||||||
artwork.addArtwork(allart, songid, "song", kodicursor)
|
artwork.addArtwork(allart, songid, "song", kodicursor)
|
||||||
|
|
||||||
|
if item.get('AlbumId') is None:
|
||||||
|
# Update album artwork
|
||||||
|
artwork.addArtwork(allart, albumid, "album", kodicursor)
|
||||||
|
|
||||||
def updateUserdata(self, item):
|
def updateUserdata(self, item):
|
||||||
# This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
# This updates: Favorite, LastPlayedDate, Playcount, PlaybackPositionTicks
|
||||||
# Poster with progress bar
|
# Poster with progress bar
|
||||||
|
@ -2349,6 +2385,21 @@ class Music(Items):
|
||||||
if mediatype == "song":
|
if mediatype == "song":
|
||||||
# Delete song
|
# Delete song
|
||||||
self.removeSong(kodiid)
|
self.removeSong(kodiid)
|
||||||
|
# This should only address single song scenario, where server doesn't actually
|
||||||
|
# create an album for the song.
|
||||||
|
customitems = emby_db.getItem_byWildId(itemid)
|
||||||
|
emby_db.removeWildItem(itemid)
|
||||||
|
|
||||||
|
for item in customitems:
|
||||||
|
|
||||||
|
item_kid = item[0]
|
||||||
|
item_mediatype = item[1]
|
||||||
|
|
||||||
|
if item_mediatype == "album":
|
||||||
|
childs = emby_db.getItem_byParentId(item_kid, "song")
|
||||||
|
if not childs:
|
||||||
|
# Delete album
|
||||||
|
self.removeAlbum(item_kid)
|
||||||
|
|
||||||
##### IF ALBUM #####
|
##### IF ALBUM #####
|
||||||
|
|
||||||
|
|
|
@ -1086,6 +1086,7 @@ class Kodidb_Functions():
|
||||||
|
|
||||||
def addAlbum(self, name, musicbrainz):
|
def addAlbum(self, name, musicbrainz):
|
||||||
|
|
||||||
|
kodiversion = self.kodiversion
|
||||||
cursor = self.cursor
|
cursor = self.cursor
|
||||||
|
|
||||||
query = ' '.join((
|
query = ' '.join((
|
||||||
|
@ -1101,14 +1102,24 @@ class Kodidb_Functions():
|
||||||
# Create the album
|
# Create the album
|
||||||
cursor.execute("select coalesce(max(idAlbum),0) from album")
|
cursor.execute("select coalesce(max(idAlbum),0) from album")
|
||||||
albumid = cursor.fetchone()[0] + 1
|
albumid = cursor.fetchone()[0] + 1
|
||||||
query = (
|
if kodiversion in (15, 16, 17):
|
||||||
'''
|
query = (
|
||||||
INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID)
|
'''
|
||||||
|
INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID, strReleaseType)
|
||||||
|
|
||||||
VALUES (?, ?, ?)
|
VALUES (?, ?, ?, ?)
|
||||||
'''
|
'''
|
||||||
)
|
)
|
||||||
cursor.execute(query, (albumid, name, musicbrainz))
|
cursor.execute(query, (albumid, name, musicbrainz, "album"))
|
||||||
|
else: # Helix
|
||||||
|
query = (
|
||||||
|
'''
|
||||||
|
INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID)
|
||||||
|
|
||||||
|
VALUES (?, ?, ?)
|
||||||
|
'''
|
||||||
|
)
|
||||||
|
cursor.execute(query, (albumid, name, musicbrainz))
|
||||||
|
|
||||||
return albumid
|
return albumid
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue