mirror of
https://github.com/spl0k/supysonic.git
synced 2024-11-13 21:52:18 +00:00
fix issue #254. albums now store their path, which is unique to an album. this means that the album artist does not have to be set for a compilation to be correctly grouped as one album instead of one album per artist.
This commit is contained in:
parent
0fa0d55290
commit
f891d8e7f6
@ -258,6 +258,7 @@ class Album(_Model):
|
||||
id = PrimaryKeyField()
|
||||
name = CharField()
|
||||
artist = ForeignKeyField(Artist, backref="albums")
|
||||
folder = ForeignKeyField(Folder, backref="albums")
|
||||
|
||||
def as_subsonic_album(self, user): # "AlbumID3" type in XSD
|
||||
duration, created, year = self.tracks.select(
|
||||
@ -268,6 +269,7 @@ class Album(_Model):
|
||||
"id": str(self.id),
|
||||
"name": self.name,
|
||||
"artist": self.artist.name,
|
||||
"folderId": str(self.folder_id),
|
||||
"artistId": str(self.artist.id),
|
||||
"songCount": self.tracks.count(),
|
||||
"duration": duration,
|
||||
|
@ -247,7 +247,7 @@ class Scanner(Thread):
|
||||
trdict["bitrate"] = tag.bitrate // 1000
|
||||
trdict["last_modification"] = mtime
|
||||
|
||||
tralbum = self.__find_album(albumartist, album)
|
||||
tralbum = self.__find_album(albumartist, album, path)
|
||||
trartist = self.__find_artist(artist)
|
||||
|
||||
if tr is None:
|
||||
@ -363,14 +363,23 @@ class Scanner(Thread):
|
||||
folder.cover_art = cover_name
|
||||
folder.save()
|
||||
|
||||
def __find_album(self, artist, album):
|
||||
def __find_album(self, artist, album, track_path):
|
||||
ar = self.__find_artist(artist)
|
||||
al = ar.albums.where(Album.name == album).first()
|
||||
if al:
|
||||
return al
|
||||
|
||||
try:
|
||||
folder=self.__find_folder(track_path)
|
||||
folder_id=folder.id
|
||||
al = folder.albums.first()
|
||||
if al:
|
||||
if(al.folder.path == folder.path and al.folder.name == folder.name):
|
||||
return al
|
||||
self.__stats.added.albums += 1
|
||||
return Album.create(name=album, artist=ar, folder_id=folder_id)
|
||||
except Album.DoesNotExist:
|
||||
self.__stats.added.albums += 1
|
||||
return Album.create(name=album, artist=ar)
|
||||
return Album.create(name=album, artist=ar, folder_id=folder_id)
|
||||
|
||||
def __find_artist(self, artist):
|
||||
try:
|
||||
|
@ -19,9 +19,11 @@ CREATE TABLE IF NOT EXISTS artist (
|
||||
CREATE TABLE IF NOT EXISTS album (
|
||||
id CHAR(32) PRIMARY KEY,
|
||||
name VARCHAR(256) NOT NULL,
|
||||
artist_id CHAR(32) NOT NULL REFERENCES artist(id)
|
||||
artist_id CHAR(32) NOT NULL REFERENCES artist(id),
|
||||
folder_id INTEGER NOT NULL REFERENCES folder
|
||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||
CREATE INDEX index_album_artist_id_fk ON album(artist_id);
|
||||
CREATE INDEX index_album_folder_id_fk ON album(folder_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS track (
|
||||
id CHAR(32) PRIMARY KEY,
|
||||
|
@ -19,9 +19,11 @@ CREATE TABLE IF NOT EXISTS artist (
|
||||
CREATE TABLE IF NOT EXISTS album (
|
||||
id UUID PRIMARY KEY,
|
||||
name CITEXT NOT NULL,
|
||||
artist_id UUID NOT NULL REFERENCES artist
|
||||
artist_id UUID NOT NULL REFERENCES artist,
|
||||
folder_id INTEGER NOT NULL REFERENCES folder
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS index_album_artist_id_fk ON album(artist_id);
|
||||
CREATE INDEX IF NOT EXISTS index_album_folder_id_fk ON album(folder_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS track (
|
||||
id UUID PRIMARY KEY,
|
||||
|
@ -20,9 +20,11 @@ CREATE TABLE IF NOT EXISTS artist (
|
||||
CREATE TABLE IF NOT EXISTS album (
|
||||
id CHAR(36) PRIMARY KEY,
|
||||
name VARCHAR(256) NOT NULL COLLATE NOCASE,
|
||||
artist_id CHAR(36) NOT NULL REFERENCES artist
|
||||
artist_id CHAR(36) NOT NULL REFERENCES artist,
|
||||
folder_id INTEGER NOT NULL REFERENCES folder
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS index_album_artist_id_fk ON album(artist_id);
|
||||
CREATE INDEX IF NOT EXISTS index_album_folder_id_fk ON album(folder_id);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS track (
|
||||
id CHAR(36) PRIMARY KEY,
|
||||
|
Loading…
Reference in New Issue
Block a user