mirror of
https://github.com/jellyfin/jellyfin-kodi.git
synced 2024-11-10 04:06:11 +00:00
Allow music to be repaired
This commit is contained in:
parent
c66ca3b99c
commit
49e673a873
2 changed files with 60 additions and 12 deletions
|
@ -61,7 +61,7 @@ class KodiMusic(KodiItems):
|
|||
)
|
||||
self.cursor.execute(query, (1, 'Composer'))
|
||||
|
||||
def get_artist(self, name, musicbrainz):
|
||||
def get_artist(self, name, musicbrainz, artist_id=None):
|
||||
|
||||
query = ' '.join((
|
||||
|
||||
|
@ -75,14 +75,14 @@ class KodiMusic(KodiItems):
|
|||
artist_id = result[0]
|
||||
artist_name = result[1]
|
||||
except TypeError:
|
||||
artist_id = self._add_artist(name, musicbrainz)
|
||||
artist_id = self._add_artist(name, musicbrainz, artist_id)
|
||||
else:
|
||||
if artist_name != name:
|
||||
self.update_artist_name(artist_id, name)
|
||||
|
||||
return artist_id
|
||||
|
||||
def _add_artist(self, name, musicbrainz):
|
||||
def _add_artist(self, name, musicbrainz, artist_id=None):
|
||||
|
||||
query = ' '.join((
|
||||
# Safety check, when musicbrainz does not exist
|
||||
|
@ -95,7 +95,7 @@ class KodiMusic(KodiItems):
|
|||
try:
|
||||
artist_id = self.cursor.fetchone()[0]
|
||||
except TypeError:
|
||||
artist_id = self.create_entry()
|
||||
artist_id = artist_id or self.create_entry()
|
||||
query = (
|
||||
'''
|
||||
INSERT INTO artist(idArtist, strArtist, strMusicBrainzArtistID)
|
||||
|
@ -159,7 +159,40 @@ class KodiMusic(KodiItems):
|
|||
)
|
||||
self.cursor.execute(query, (kodi_id, album, year))
|
||||
|
||||
def get_album(self, name, musicbrainz=None):
|
||||
def validate_artist(self, kodi_id):
|
||||
|
||||
query = "SELECT * FROM artist WHERE idArtist = ?"
|
||||
self.cursor.execute(query, (kodi_id,))
|
||||
try:
|
||||
kodi_id = self.cursor.fetchone()[0]
|
||||
except TypeError:
|
||||
kodi_id = None
|
||||
|
||||
return kodi_id
|
||||
|
||||
def validate_album(self, kodi_id):
|
||||
|
||||
query = "SELECT * FROM album WHERE idAlbum = ?"
|
||||
self.cursor.execute(query, (kodi_id,))
|
||||
try:
|
||||
kodi_id = self.cursor.fetchone()[0]
|
||||
except TypeError:
|
||||
kodi_id = None
|
||||
|
||||
return kodi_id
|
||||
|
||||
def validate_song(self, kodi_id):
|
||||
|
||||
query = "SELECT * FROM song WHERE idSong = ?"
|
||||
self.cursor.execute(query, (kodi_id,))
|
||||
try:
|
||||
kodi_id = self.cursor.fetchone()[0]
|
||||
except TypeError:
|
||||
kodi_id = None
|
||||
|
||||
return kodi_id
|
||||
|
||||
def get_album(self, name, musicbrainz=None, album_id=None):
|
||||
|
||||
if musicbrainz is not None:
|
||||
query = ' '.join((
|
||||
|
@ -174,20 +207,20 @@ class KodiMusic(KodiItems):
|
|||
|
||||
"SELECT idAlbum",
|
||||
"FROM album",
|
||||
"WHERE strMusicBrainzAlbumID = ?"
|
||||
"WHERE strAlbum = ?"
|
||||
))
|
||||
self.cursor.execute(query, (name,))
|
||||
|
||||
try:
|
||||
album_id = self.cursor.fetchone()[0]
|
||||
except TypeError:
|
||||
album_id = self._add_album(name, musicbrainz)
|
||||
album_id = self._add_album(name, musicbrainz, album_id)
|
||||
|
||||
return album_id
|
||||
|
||||
def _add_album(self, name, musicbrainz):
|
||||
def _add_album(self, name, musicbrainz, album_id=None):
|
||||
|
||||
album_id = self.create_entry_album()
|
||||
album_id = album_id or self.create_entry_album()
|
||||
query = (
|
||||
'''
|
||||
INSERT INTO album(idAlbum, strAlbum, strMusicBrainzAlbumID, strReleaseType)
|
||||
|
|
|
@ -193,8 +193,12 @@ class Music(Items):
|
|||
except TypeError:
|
||||
update_item = False
|
||||
log.debug("artistid: %s not found", itemid)
|
||||
artistid = None
|
||||
else:
|
||||
pass
|
||||
if self.kodi_db.validate_artist(artistid) is None:
|
||||
# item is not found, let's recreate it.
|
||||
update_item = False
|
||||
log.info("artistid: %s missing from Kodi, repairing the entry", artistid)
|
||||
|
||||
##### The artist details #####
|
||||
lastScraped = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
@ -230,7 +234,7 @@ class Music(Items):
|
|||
log.info("ADD artist itemid: %s - Name: %s", itemid, name)
|
||||
# safety checks: It looks like Emby supports the same artist multiple times.
|
||||
# Kodi doesn't allow that. In case that happens we just merge the artist entries.
|
||||
artistid = self.kodi_db.get_artist(name, musicBrainzId)
|
||||
artistid = self.kodi_db.get_artist(name, musicBrainzId, artistid)
|
||||
# Create the reference in emby table
|
||||
emby_db.addReference(itemid, artistid, artisttype, "artist", checksum=checksum)
|
||||
|
||||
|
@ -262,6 +266,12 @@ class Music(Items):
|
|||
except TypeError:
|
||||
update_item = False
|
||||
log.debug("albumid: %s not found", itemid)
|
||||
albumid = None
|
||||
else:
|
||||
if self.kodi_db.validate_album(albumid) is None:
|
||||
# item is not found, let's recreate it.
|
||||
update_item = False
|
||||
log.info("albumid: %s missing from Kodi, repairing the entry", albumid)
|
||||
|
||||
##### The album details #####
|
||||
lastScraped = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
|
||||
|
@ -299,7 +309,7 @@ class Music(Items):
|
|||
log.info("ADD album itemid: %s - Name: %s", itemid, name)
|
||||
# safety checks: It looks like Emby supports the same artist multiple times.
|
||||
# Kodi doesn't allow that. In case that happens we just merge the artist entries.
|
||||
albumid = self.kodi_db.get_album(name, musicBrainzId)
|
||||
albumid = self.kodi_db.get_album(name, musicBrainzId, albumid)
|
||||
# Create the reference in emby table
|
||||
emby_db.addReference(itemid, albumid, "MusicAlbum", "album", checksum=checksum)
|
||||
|
||||
|
@ -372,6 +382,11 @@ class Music(Items):
|
|||
update_item = False
|
||||
log.debug("songid: %s not found", itemid)
|
||||
songid = self.kodi_db.create_entry_song()
|
||||
else:
|
||||
if self.kodi_db.validate_song(songid) is None:
|
||||
# item is not found, let's recreate it.
|
||||
update_item = False
|
||||
log.info("songid: %s missing from Kodi, repairing the entry", songid)
|
||||
|
||||
##### The song details #####
|
||||
checksum = API.get_checksum()
|
||||
|
|
Loading…
Reference in a new issue