Remove Music sync code for older Kodi version before Kodi Matrix

This commit is contained in:
croneter 2020-12-20 14:54:07 +01:00
parent bd8af8652e
commit 09b2c54675
2 changed files with 72 additions and 327 deletions

View file

@ -126,8 +126,6 @@ class MusicMixin(object):
# Check whether we have orphaned path entries # Check whether we have orphaned path entries
if not self.kodidb.path_id_from_song(kodi_id): if not self.kodidb.path_id_from_song(kodi_id):
self.kodidb.remove_path(path_id) self.kodidb.remove_path(path_id)
if v.KODIVERSION < 18:
self.kodidb.remove_albuminfosong(kodi_id)
self.kodidb.delete_artwork(kodi_id, v.KODI_TYPE_SONG) self.kodidb.delete_artwork(kodi_id, v.KODI_TYPE_SONG)
def remove_album(self, kodi_id): def remove_album(self, kodi_id):
@ -135,8 +133,6 @@ class MusicMixin(object):
Remove an album Remove an album
''' '''
self.kodidb.delete_album_from_discography(kodi_id) self.kodidb.delete_album_from_discography(kodi_id)
if v.KODIVERSION < 18:
self.kodidb.delete_album_from_album_genre(kodi_id)
self.kodidb.remove_album(kodi_id) self.kodidb.remove_album(kodi_id)
self.kodidb.delete_artwork(kodi_id, v.KODI_TYPE_ALBUM) self.kodidb.delete_artwork(kodi_id, v.KODI_TYPE_ALBUM)
@ -290,7 +286,6 @@ class Album(MusicMixin, ItemBase):
# UPDATE THE ALBUM ##### # UPDATE THE ALBUM #####
if update_item: if update_item:
LOG.info("UPDATE album plex_id: %s - Name: %s", plex_id, name) LOG.info("UPDATE album plex_id: %s - Name: %s", plex_id, name)
if v.KODIVERSION >= 18:
self.kodidb.update_album(name, self.kodidb.update_album(name,
musicBrainzId, musicBrainzId,
api.artist_name(), api.artist_name(),
@ -304,25 +299,10 @@ class Album(MusicMixin, ItemBase):
timing.unix_date_to_kodi(self.last_sync), timing.unix_date_to_kodi(self.last_sync),
'album', 'album',
kodi_id) kodi_id)
else:
self.kodidb.update_album_17(name,
musicBrainzId,
api.artist_name(),
genre,
api.year(),
compilation,
api.plot(),
thumb,
api.list_to_string(api.studios()),
api.userrating(),
timing.unix_date_to_kodi(self.last_sync),
'album',
kodi_id)
# OR ADD THE ALBUM ##### # OR ADD THE ALBUM #####
else: else:
LOG.info("ADD album plex_id: %s - Name: %s", plex_id, name) LOG.info("ADD album plex_id: %s - Name: %s", plex_id, name)
kodi_id = self.kodidb.new_album_id() kodi_id = self.kodidb.new_album_id()
if v.KODIVERSION >= 18:
self.kodidb.add_album(kodi_id, self.kodidb.add_album(kodi_id,
name, name,
musicBrainzId, musicBrainzId,
@ -336,26 +316,7 @@ class Album(MusicMixin, ItemBase):
api.userrating(), api.userrating(),
timing.unix_date_to_kodi(self.last_sync), timing.unix_date_to_kodi(self.last_sync),
'album') 'album')
else:
self.kodidb.add_album_17(kodi_id,
name,
musicBrainzId,
api.artist_name(),
genre,
api.year(),
compilation,
api.plot(),
thumb,
api.list_to_string(api.studios()),
api.userrating(),
timing.unix_date_to_kodi(self.last_sync),
'album')
self.kodidb.add_albumartist(artist_id, kodi_id, api.artist_name()) self.kodidb.add_albumartist(artist_id, kodi_id, api.artist_name())
if v.KODIVERSION < 18:
self.kodidb.add_discography(artist_id, name, api.year())
self.kodidb.add_music_genres(kodi_id,
api.genres(),
v.KODI_TYPE_ALBUM)
if app.SYNC.artwork: if app.SYNC.artwork:
self.kodidb.modify_artwork(artworks, self.kodidb.modify_artwork(artworks,
kodi_id, kodi_id,
@ -436,7 +397,6 @@ class Song(MusicMixin, ItemBase):
# No album found, create a single's album # No album found, create a single's album
LOG.info('Creating singles album') LOG.info('Creating singles album')
parent_id = self.kodidb.new_album_id() parent_id = self.kodidb.new_album_id()
if v.KODIVERSION >= 18:
self.kodidb.add_album(kodi_id, self.kodidb.add_album(kodi_id,
None, None,
None, None,
@ -450,20 +410,6 @@ class Song(MusicMixin, ItemBase):
None, None,
timing.unix_date_to_kodi(self.last_sync), timing.unix_date_to_kodi(self.last_sync),
'single') 'single')
else:
self.kodidb.add_album_17(kodi_id,
None,
None,
None,
genre,
api.year(),
None,
None,
None,
None,
None,
timing.unix_date_to_kodi(self.last_sync),
'single')
else: else:
album = self.plexdb.album(album_id) album = self.plexdb.album(album_id)
if not album: if not album:
@ -524,9 +470,6 @@ class Song(MusicMixin, ItemBase):
LOG.info("UPDATE song plex_id: %s - %s", plex_id, title) LOG.info("UPDATE song plex_id: %s - %s", plex_id, title)
# Use dummy strHash '123' for Kodi # Use dummy strHash '123' for Kodi
self.kodidb.update_path(path, kodi_pathid) self.kodidb.update_path(path, kodi_pathid)
# Update the song entry
if v.KODIVERSION >= 18:
# Kodi Leia
self.kodidb.update_song(parent_id, self.kodidb.update_song(parent_id,
artists, artists,
genre, genre,
@ -542,30 +485,11 @@ class Song(MusicMixin, ItemBase):
mood, mood,
api.date_created(), api.date_created(),
kodi_id) kodi_id)
else:
self.kodidb.update_song_17(parent_id,
artists,
genre,
title,
track,
api.runtime(),
year,
filename,
api.viewcount(),
api.lastplayed(),
api.userrating(),
comment,
mood,
api.date_created(),
kodi_id)
# OR ADD THE SONG ##### # OR ADD THE SONG #####
else: else:
LOG.info("ADD song plex_id: %s - %s", plex_id, title) LOG.info("ADD song plex_id: %s - %s", plex_id, title)
# Add path # Add path
kodi_pathid = self.kodidb.add_path(path) kodi_pathid = self.kodidb.add_path(path)
# Create the song entry
if v.KODIVERSION >= 18:
# Kodi Leia
self.kodidb.add_song(kodi_id, self.kodidb.add_song(kodi_id,
parent_id, parent_id,
kodi_pathid, kodi_pathid,
@ -584,32 +508,6 @@ class Song(MusicMixin, ItemBase):
0, 0,
mood, mood,
api.date_created()) api.date_created())
else:
self.kodidb.add_song_17(kodi_id,
parent_id,
kodi_pathid,
artists,
genre,
title,
track,
api.runtime(),
year,
filename,
musicBrainzId,
api.viewcount(),
api.lastplayed(),
api.userrating(),
0,
0,
mood,
api.date_created())
if v.KODIVERSION < 18:
# Link song to album
self.kodidb.add_albuminfosong(kodi_id,
parent_id,
track,
title,
api.runtime())
# Link song to artists # Link song to artists
artist_name = api.grandparent_title() artist_name = api.grandparent_title()
# Do the actual linking # Do the actual linking

View file

@ -179,87 +179,6 @@ class KodiMusicDB(common.KodiDBBase):
self.cursor.execute('SELECT COALESCE(MAX(idAlbum), 0) FROM album') self.cursor.execute('SELECT COALESCE(MAX(idAlbum), 0) FROM album')
return self.cursor.fetchone()[0] + 1 return self.cursor.fetchone()[0] + 1
@db.catch_operationalerrors
def add_album_17(self, *args):
"""
strReleaseType: 'album' or 'single'
"""
if app.SYNC.artwork:
self.cursor.execute('''
INSERT INTO album(
idAlbum,
strAlbum,
strMusicBrainzAlbumID,
strArtists,
strGenres,
iYear,
bCompilation,
strReview,
strImage,
strLabel,
iUserrating,
lastScraped,
strReleaseType)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (args))
else:
args = list(args)
del args[8]
self.cursor.execute('''
INSERT INTO album(
idAlbum,
strAlbum,
strMusicBrainzAlbumID,
strArtists,
strGenres,
iYear,
bCompilation,
strReview,
strLabel,
iUserrating,
lastScraped,
strReleaseType)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (args))
@db.catch_operationalerrors
def update_album_17(self, *args):
if app.SYNC.artwork:
self.cursor.execute('''
UPDATE album
SET strAlbum = ?,
strMusicBrainzAlbumID = ?,
strArtists = ?,
strGenres = ?,
iYear = ?,
bCompilation = ?,
strReview = ?,
strImage = ?,
strLabel = ?,
iUserrating = ?,
lastScraped = ?,
strReleaseType = ?
WHERE idAlbum = ?
''', (args))
else:
args = list(args)
del args[7]
self.cursor.execute('''
UPDATE album
SET strAlbum = ?,
strMusicBrainzAlbumID = ?,
strArtists = ?,
strGenres = ?,
iYear = ?,
bCompilation = ?,
strReview = ?,
strLabel = ?,
iUserrating = ?,
lastScraped = ?,
strReleaseType = ?
WHERE idAlbum = ?
''', (args))
@db.catch_operationalerrors @db.catch_operationalerrors
def add_album(self, *args): def add_album(self, *args):
""" """
@ -351,16 +270,6 @@ class KodiMusicDB(common.KodiDBBase):
VALUES (?, ?, ?) VALUES (?, ?, ?)
''', (artist_id, kodi_id, artistname)) ''', (artist_id, kodi_id, artistname))
@db.catch_operationalerrors
def add_discography(self, artist_id, albumname, year):
self.cursor.execute('''
INSERT OR REPLACE INTO discography(
idArtist,
strAlbum,
strYear)
VALUES (?, ?, ?)
''', (artist_id, albumname, year))
@db.catch_operationalerrors @db.catch_operationalerrors
def add_music_genres(self, kodiid, genres, mediatype): def add_music_genres(self, kodiid, genres, mediatype):
""" """
@ -437,31 +346,6 @@ class KodiMusicDB(common.KodiDBBase):
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (args)) ''', (args))
@db.catch_operationalerrors
def add_song_17(self, *args):
self.cursor.execute('''
INSERT INTO song(
idSong,
idAlbum,
idPath,
strArtists,
strGenres,
strTitle,
iTrack,
iDuration,
iYear,
strFileName,
strMusicBrainzTrackID,
iTimesPlayed,
lastplayed,
rating,
iStartOffset,
iEndOffset,
mood,
dateAdded)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
''', (args))
@db.catch_operationalerrors @db.catch_operationalerrors
def update_song(self, *args): def update_song(self, *args):
self.cursor.execute(''' self.cursor.execute('''
@ -492,27 +376,6 @@ class KodiMusicDB(common.KodiDBBase):
WHERE idSong = ? WHERE idSong = ?
''', (args)) ''', (args))
@db.catch_operationalerrors
def update_song_17(self, *args):
self.cursor.execute('''
UPDATE song
SET idAlbum = ?,
strArtists = ?,
strGenres = ?,
strTitle = ?,
iTrack = ?,
iDuration = ?,
iYear = ?,
strFilename = ?,
iTimesPlayed = ?,
lastplayed = ?,
rating = ?,
comment = ?,
mood = ?,
dateAdded = ?
WHERE idSong = ?
''', (args))
def path_id_from_song(self, kodi_id): def path_id_from_song(self, kodi_id):
self.cursor.execute('SELECT idPath FROM song WHERE idSong = ? LIMIT 1', self.cursor.execute('SELECT idPath FROM song WHERE idSong = ? LIMIT 1',
(kodi_id, )) (kodi_id, ))
@ -596,22 +459,6 @@ class KodiMusicDB(common.KodiDBBase):
VALUES (?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?)
''', (artist_id, song_id, 1, 0, artist_name)) ''', (artist_id, song_id, 1, 0, artist_name))
@db.catch_operationalerrors
def add_albuminfosong(self, song_id, album_id, track_no, track_title,
runtime):
"""
Kodi 17 only
"""
self.cursor.execute('''
INSERT OR REPLACE INTO albuminfosong(
idAlbumInfoSong,
idAlbumInfo,
iTrack,
strTitle,
iDuration)
VALUES (?, ?, ?, ?, ?)
''', (song_id, album_id, track_no, track_title, runtime))
@db.catch_operationalerrors @db.catch_operationalerrors
def update_userrating(self, kodi_id, kodi_type, userrating): def update_userrating(self, kodi_id, kodi_type, userrating):
""" """