Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for multiple artist album without album artist tag showing up as an album per artist (issue #254) #258

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
19 changes: 14 additions & 5 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

self.__stats.added.albums += 1
return Album.create(name=album, artist=ar)
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, 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