Skip to content

Commit

Permalink
Changed the way album covers are associated, fixes #503
Browse files Browse the repository at this point in the history
  • Loading branch information
epoupon committed Sep 29, 2024
1 parent 4e1b422 commit 3f6177c
Show file tree
Hide file tree
Showing 31 changed files with 501 additions and 230 deletions.
1 change: 1 addition & 0 deletions approot/messages.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<message id="Lms.Admin.ScannerController.status-scheduled">Scheduled on {1}</message>
<message id="Lms.Admin.ScannerController.status-in-progress">Scanning: step {1}/{2}</message>
<message id="Lms.Admin.ScannerController.step-associating-artist-images">Associating artist images: {1}%...</message>
<message id="Lms.Admin.ScannerController.step-associating-release-images">Associating release images: {1}%...</message>
<message id="Lms.Admin.ScannerController.step-checking-for-duplicate-files">Checking for duplicate files... {1} files</message>
<message id="Lms.Admin.ScannerController.step-checking-for-removed-files">Checking for removed files... {1}%</message>
<message id="Lms.Admin.ScannerController.step-compact">Compacting database...</message>
Expand Down
1 change: 1 addition & 0 deletions approot/messages_fr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<message id="Lms.Admin.ScannerController.status-scheduled">Planifié le {1}</message>
<message id="Lms.Admin.ScannerController.status-in-progress">En cours de scan : étape {1}/{2}</message>
<message id="Lms.Admin.ScannerController.step-associating-artist-images">Association des images des artistes: {1}%...</message>
<message id="Lms.Admin.ScannerController.step-associating-release-images">Association des images des albums: {1}%...</message>
<message id="Lms.Admin.ScannerController.step-checking-for-duplicate-files">Vérification des fichiers dupliqués... {1} fichiers</message>
<message id="Lms.Admin.ScannerController.step-checking-for-removed-files">Vérification des fichiers supprimés... {1}%</message>
<message id="Lms.Admin.ScannerController.step-compact">Compactage de la base de données...</message>
Expand Down
1 change: 1 addition & 0 deletions approot/messages_it.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
<message id="Lms.Admin.ScannerController.status-scheduled">Pianificato il {1}</message>
<message id="Lms.Admin.ScannerController.status-in-progress">Scansione: passo {1}/{2}</message>
<message id="Lms.Admin.ScannerController.step-associating-artist-images">Associando immagini degli artisti: {1}%...</message>
<message id="Lms.Admin.ScannerController.step-associating-release-images">Associando immagini degli album: {1}%...</message>
<message id="Lms.Admin.ScannerController.step-checking-for-duplicate-files">Controllo duplicati... {1} files</message>
<message id="Lms.Admin.ScannerController.step-checking-for-removed-files">Controllo file... {1}%</message>
<message id="Lms.Admin.ScannerController.step-compact">Compattazione del database...</message>
Expand Down
1 change: 1 addition & 0 deletions approot/messages_pl.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@
<message id="Lms.Admin.ScannerController.status-scheduled">Zaplanowano na {1}</message>
<message id="Lms.Admin.ScannerController.status-in-progress">Skanowanie: krok {1}/{2}</message>
<message id="Lms.Admin.ScannerController.step-associating-artist-images">Kojarzenie obrazów artystów: {1}%...</message>
<message id="Lms.Admin.ScannerController.step-associating-release-images">Kojarzenie obrazów albumów: {1}%...</message>
<message id="Lms.Admin.ScannerController.step-checking-for-duplicate-files">
<plural case="0">Sprawdzanie duplikatów... {1} plik</plural>
<plural case="1">Sprawdzanie duplikatów... {1} pliki</plural>
Expand Down
1 change: 1 addition & 0 deletions approot/messages_zh.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@




<message id="Lms.Admin.ScannerController.step-discovering-files">检索文件中: {1} 文件</message>
<message id="Lms.Admin.ScannerController.step-fetching-track-features">从 AcousticBrainz 获取音轨特征: {1}/{2} 音轨 ({3}%)...</message>

Expand Down
5 changes: 1 addition & 4 deletions conf/lms.conf
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,14 @@ api-open-subsonic-disabled-clients = ("DSub");
# Turn on this option to allow the demo account creation/use
demo = false;

# Max external cover file size in MBytes
cover-max-file-size = 10;

# Max cover cache size in MBytes
cover-max-cache-size = 30;

# JPEG quality for covers (range is 1-100)
cover-jpeg-quality = 75;

# Preferred file names for covers (order is important)
cover-preferred-file-names = ("cover", "front");
cover-preferred-file-names = ("cover", "front", "folder", "default");

# File names for artist images (order is important)
# Note: files whose name is the artist's MBID are always searched before the names in this list. You can place the MBID files anywhere in your libraries.
Expand Down
1 change: 0 additions & 1 deletion src/libs/database/impl/Artist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -379,5 +379,4 @@ namespace lms::db
{
_image = getDboPtr(image);
}

} // namespace lms::db
3 changes: 2 additions & 1 deletion src/libs/database/impl/Image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include "database/Artist.hpp"
#include "database/Directory.hpp"
#include "database/Release.hpp"
#include "database/Session.hpp"

#include "IdTypeTraits.hpp"
Expand All @@ -40,7 +41,7 @@ namespace lms::db
if (params.directory.isValid())
query.where("i.directory_id = ?").bind(params.directory);
if (!params.fileStem.empty())
query.where("i.stem = ?").bind(params.fileStem);
query.where("i.stem = ? COLLATE NOCASE").bind(params.fileStem);

return query;
}
Expand Down
51 changes: 50 additions & 1 deletion src/libs/database/impl/Migration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace lms::db
{
namespace
{
static constexpr Version LMS_DATABASE_VERSION{ 67 };
static constexpr Version LMS_DATABASE_VERSION{ 68 };
}

VersionInfo::VersionInfo()
Expand Down Expand Up @@ -761,6 +761,54 @@ SELECT
session.getDboSession()->execute("ALTER TABLE user DROP COLUMN cur_playing_track_pos");
}

void migrateFromV67(Session& session)
{
// Add a ref to release in image
session.getDboSession()->execute(R"(CREATE TABLE "image_backup" (
"id" integer primary key autoincrement,
"version" integer not null,
"absolute_file_path" text not null,
"stem" text not null,
"file_last_write" text,
"file_size" integer not null,
"width" integer not null,
"height" integer not null,
"artist_id" bigint,
"release_id" bigint,
"directory_id" bigint,
constraint "fk_image_artist" foreign key ("artist_id") references "artist" ("id") on delete cascade deferrable initially deferred,
constraint "fk_image_release" foreign key ("release_id") references "release" ("id") on delete cascade deferrable initially deferred,
constraint "fk_image_directory" foreign key ("directory_id") references "directory" ("id") on delete cascade deferrable initially deferred
))");

// Migrate data, with the new release_id field set to null
session.getDboSession()->execute(R"(INSERT INTO image_backup
SELECT
id,
version,
absolute_file_path,
stem,
file_last_write,
file_size,
width,
height,
artist_id,
NULL,
directory_id
FROM image
)");
session.getDboSession()->execute("DROP TABLE image");
session.getDboSession()->execute("ALTER TABLE image_backup RENAME TO image");

// Changed some indexes for the image table -> remove all the previoulsy created index, the createIndexesIfNeeded will recreate them all
std::vector<std::string> indexeNames{ utils::fetchQueryResults(session.getDboSession()->query<std::string>(R"(SELECT name FROM sqlite_master WHERE type = 'index' AND name LIKE '%_idx')")) };
for (const auto& indexName : indexeNames)
session.getDboSession()->execute("DROP INDEX " + indexName);

// Just increment the scan version of the settings to make the next scheduled scan rescan everything
session.getDboSession()->execute("UPDATE scan_settings SET scan_version = scan_version + 1");
}

bool doDbMigration(Session& session)
{
static const std::string outdatedMsg{ "Outdated database, please rebuild it (delete the .db file and restart)" };
Expand Down Expand Up @@ -804,6 +852,7 @@ SELECT
{ 64, migrateFromV64 },
{ 65, migrateFromV65 },
{ 66, migrateFromV66 },
{ 67, migrateFromV67 },
};

bool migrationPerformed{};
Expand Down
13 changes: 12 additions & 1 deletion src/libs/database/impl/Release.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
#include "core/ILogger.hpp"
#include "database/Artist.hpp"
#include "database/Cluster.hpp"
#include "database/Directory.hpp"
#include "database/Image.hpp"
#include "database/Session.hpp"
#include "database/Track.hpp"
#include "database/User.hpp"
Expand Down Expand Up @@ -540,6 +542,11 @@ namespace lms::db
return utils::fetchQueryResults<Release::pointer>(query);
}

ObjectPtr<Image> Release::getImage() const
{
return ObjectPtr<Image>{ _image.lock() };
}

void Release::clearLabels()
{
_labels.clear();
Expand All @@ -560,6 +567,11 @@ namespace lms::db
_releaseTypes.insert(getDboPtr(releaseType));
}

void Release::setImage(ObjectPtr<Image> image)
{
_image = getDboPtr(image);
}

bool Release::hasVariousArtists() const
{
// TODO optimize
Expand Down Expand Up @@ -665,5 +677,4 @@ namespace lms::db

return res;
}

} // namespace lms::db
5 changes: 3 additions & 2 deletions src/libs/database/impl/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,11 @@ namespace lms::db
_session.execute("CREATE INDEX IF NOT EXISTS directory_media_library_idx ON directory(media_library_id)");

_session.execute("CREATE INDEX IF NOT EXISTS image_artist_idx ON image(artist_id)");
_session.execute("CREATE INDEX IF NOT EXISTS image_directory_idx ON image(directory_id)");
_session.execute("CREATE INDEX IF NOT EXISTS image_directory_stem_idx ON image(directory_id, stem COLLATE NOCASE)");
_session.execute("CREATE INDEX IF NOT EXISTS image_id_idx ON image(id)");
_session.execute("CREATE INDEX IF NOT EXISTS image_path_idx ON image(absolute_file_path)");
_session.execute("CREATE INDEX IF NOT EXISTS image_stem_idx ON image(stem)");
_session.execute("CREATE INDEX IF NOT EXISTS image_release_idx ON image(release_id)");
_session.execute("CREATE INDEX IF NOT EXISTS image_stem_idx ON image(stem COLLATE NOCASE)");

_session.execute("CREATE INDEX IF NOT EXISTS label_name_idx ON label(name)");

Expand Down
3 changes: 3 additions & 0 deletions src/libs/database/impl/Track.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,9 @@ namespace lms::db
if (params.directory.isValid())
query.where("t.directory_id = ?").bind(params.directory);

if (params.hasEmbeddedImage.has_value())
query.where("t.has_cover = ?").bind(params.hasEmbeddedImage.value());

switch (params.sortMethod)
{
case TrackSortMethod::None:
Expand Down
15 changes: 13 additions & 2 deletions src/libs/database/include/database/Image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
#include <Wt/Dbo/Dbo.h>
#include <Wt/WDateTime.h>

#include "database/ArtistId.hpp"
#include "database/DirectoryId.hpp"
#include "database/ImageId.hpp"
#include "database/Object.hpp"
Expand All @@ -35,6 +34,7 @@ namespace lms::db
{
class Artist;
class Directory;
class Release;
class Session;

class Image final : public Object<Image, ImageId>
Expand Down Expand Up @@ -87,7 +87,16 @@ namespace lms::db
void setFileSize(std::size_t fileSize) { _fileSize = fileSize; }
void setWidth(std::size_t width) { _width = width; }
void setHeight(std::size_t height) { _height = height; }
void setArtist(const ObjectPtr<Artist>& artist) { _artist = getDboPtr(artist); }
void setArtist(const ObjectPtr<Artist>& artist)
{
_artist = getDboPtr(artist);
_release = nullptr;
}
void setRelease(const ObjectPtr<Release>& release)
{
_release = getDboPtr(release);
_artist = nullptr;
}
void setDirectory(const ObjectPtr<Directory>& directory) { _directory = getDboPtr(directory); }

template<class Action>
Expand All @@ -102,6 +111,7 @@ namespace lms::db
Wt::Dbo::field(a, _height, "height");

Wt::Dbo::belongsTo(a, _artist, "artist", Wt::Dbo::OnDeleteCascade);
Wt::Dbo::belongsTo(a, _release, "release", Wt::Dbo::OnDeleteCascade);
Wt::Dbo::belongsTo(a, _directory, "directory", Wt::Dbo::OnDeleteCascade);
}

Expand All @@ -118,6 +128,7 @@ namespace lms::db
int _height{};

Wt::Dbo::ptr<Artist> _artist;
Wt::Dbo::ptr<Release> _release;
Wt::Dbo::ptr<Directory> _directory;
};
} // namespace lms::db
5 changes: 5 additions & 0 deletions src/libs/database/include/database/Release.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ namespace lms::db
class Artist;
class Cluster;
class ClusterType;
class Image;
class Release;
class Session;
class Track;
Expand Down Expand Up @@ -245,6 +246,7 @@ namespace lms::db
std::vector<std::string> getLabelNames() const;
std::vector<std::string> getReleaseTypeNames() const;
void visitLabels(const std::function<void(const Label::pointer& label)>& _func) const;
ObjectPtr<Image> getImage() const;

// Setters
void setName(std::string_view name) { _name = name; }
Expand All @@ -258,6 +260,7 @@ namespace lms::db
void clearReleaseTypes();
void addLabel(ObjectPtr<Label> releaseType);
void addReleaseType(ObjectPtr<ReleaseType> releaseType);
void setImage(ObjectPtr<Image> image);

// Get the artists of this release
std::vector<ObjectPtr<Artist>> getArtists(TrackArtistLinkType type = TrackArtistLinkType::Artist) const;
Expand All @@ -278,6 +281,7 @@ namespace lms::db
Wt::Dbo::field(a, _isCompilation, "is_compilation");
Wt::Dbo::hasMany(a, _tracks, Wt::Dbo::ManyToOne, "release");

Wt::Dbo::hasOne(a, _image, "release");
Wt::Dbo::hasMany(a, _labels, Wt::Dbo::ManyToMany, "release_label", "", Wt::Dbo::OnDeleteCascade);
Wt::Dbo::hasMany(a, _releaseTypes, Wt::Dbo::ManyToMany, "release_release_type", "", Wt::Dbo::OnDeleteCascade);
}
Expand All @@ -300,6 +304,7 @@ namespace lms::db
std::string _artistDisplayName;
bool _isCompilation{}; // See https://picard-docs.musicbrainz.org/en/appendices/tag_mapping.html#compilation-itunes-5

Wt::Dbo::weak_ptr<Image> _image;
Wt::Dbo::collection<Wt::Dbo::ptr<Track>> _tracks;
Wt::Dbo::collection<Wt::Dbo::ptr<Label>> _labels;
Wt::Dbo::collection<Wt::Dbo::ptr<ReleaseType>> _releaseTypes;
Expand Down
6 changes: 6 additions & 0 deletions src/libs/database/include/database/Track.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ namespace lms::db
std::optional<int> discNumber; // matching this disc number
MediaLibraryId mediaLibrary; // If set, tracks in this library
DirectoryId directory; // if set, tracks in this directory
std::optional<bool> hasEmbeddedImage; // if set, tracks that have or not embedded images

FindParameters& setClusters(std::span<const ClusterId> _clusters)
{
Expand Down Expand Up @@ -172,6 +173,11 @@ namespace lms::db
directory = _directory;
return *this;
}
FindParameters& setHasEmbeddedImage(std::optional<bool> _hasEmbeddedImage)
{
hasEmbeddedImage = _hasEmbeddedImage;
return *this;
}
};

struct PathResult
Expand Down
Loading

0 comments on commit 3f6177c

Please sign in to comment.