Skip to content

Commit

Permalink
fix issue spl0k#254. albums now store their path, which is unique to …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
ianesten committed Jul 21, 2023
1 parent 0fa0d55 commit f891d8e
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions supysonic/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -268,6 +269,7 @@ def as_subsonic_album(self, user): # "AlbumID3" type in XSD
"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,
Expand Down
17 changes: 13 additions & 4 deletions supysonic/scanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ def scan_file(self, path_or_direntry):
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:
Expand Down Expand Up @@ -363,14 +363,23 @@ def add_cover(self, path):
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:
Expand Down
4 changes: 3 additions & 1 deletion supysonic/schema/mysql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion supysonic/schema/postgres.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion supysonic/schema/sqlite.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f891d8e

Please sign in to comment.