Auto reformatted the base, ref #470
This commit is contained in:
@@ -22,21 +22,19 @@
|
||||
#include <set>
|
||||
|
||||
#include "av/IAudioFile.hpp"
|
||||
|
||||
#include "database/Db.hpp"
|
||||
#include "database/Artist.hpp"
|
||||
#include "database/Release.hpp"
|
||||
#include "database/Session.hpp"
|
||||
#include "database/Track.hpp"
|
||||
|
||||
#include "image/Exception.hpp"
|
||||
#include "image/Image.hpp"
|
||||
#include "core/IConfig.hpp"
|
||||
#include "core/ILogger.hpp"
|
||||
#include "core/Path.hpp"
|
||||
#include "core/Random.hpp"
|
||||
#include "core/String.hpp"
|
||||
#include "core/Utils.hpp"
|
||||
#include "database/Artist.hpp"
|
||||
#include "database/Db.hpp"
|
||||
#include "database/Release.hpp"
|
||||
#include "database/Session.hpp"
|
||||
#include "database/Track.hpp"
|
||||
#include "image/Exception.hpp"
|
||||
#include "image/Image.hpp"
|
||||
|
||||
namespace lms::cover
|
||||
{
|
||||
@@ -80,10 +78,10 @@ namespace lms::cover
|
||||
std::vector<std::string> res;
|
||||
|
||||
core::Service<core::IConfig>::get()->visitStrings("cover-preferred-file-names",
|
||||
[&res](std::string_view fileName)
|
||||
{
|
||||
[&res](std::string_view fileName) {
|
||||
res.emplace_back(fileName);
|
||||
}, { "cover", "front" });
|
||||
},
|
||||
{ "cover", "front" });
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -93,10 +91,10 @@ namespace lms::cover
|
||||
std::vector<std::string> res;
|
||||
|
||||
core::Service<core::IConfig>::get()->visitStrings("artist-image-file-names",
|
||||
[&res](std::string_view fileName)
|
||||
{
|
||||
[&res](std::string_view fileName) {
|
||||
res.emplace_back(fileName);
|
||||
}, { "artist" });
|
||||
},
|
||||
{ "artist" });
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -105,7 +103,7 @@ namespace lms::cover
|
||||
{
|
||||
return (std::find(std::cbegin(extensions), std::cend(extensions), file.extension()) != std::cend(extensions));
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
std::unique_ptr<ICoverService> createCoverService(db::Db& db, const std::filesystem::path& defaultSvgCoverPath)
|
||||
{
|
||||
@@ -136,22 +134,21 @@ namespace lms::cover
|
||||
{
|
||||
std::unique_ptr<IEncodedImage> image;
|
||||
|
||||
input.visitAttachedPictures([&](const av::Picture& picture)
|
||||
{
|
||||
if (image)
|
||||
return;
|
||||
input.visitAttachedPictures([&](const av::Picture& picture) {
|
||||
if (image)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
std::unique_ptr<IRawImage> rawImage{ decodeImage(picture.data, picture.dataSize) };
|
||||
rawImage->resize(width);
|
||||
image = rawImage->encodeToJPEG(_jpegQuality);
|
||||
}
|
||||
catch (const image::Exception& e)
|
||||
{
|
||||
LMS_LOG(COVER, ERROR, "Cannot read embedded cover: " << e.what());
|
||||
}
|
||||
});
|
||||
try
|
||||
{
|
||||
std::unique_ptr<IRawImage> rawImage{ decodeImage(picture.data, picture.dataSize) };
|
||||
rawImage->resize(width);
|
||||
image = rawImage->encodeToJPEG(_jpegQuality);
|
||||
}
|
||||
catch (const image::Exception& e)
|
||||
{
|
||||
LMS_LOG(COVER, ERROR, "Cannot read embedded cover: " << e.what());
|
||||
}
|
||||
});
|
||||
|
||||
return image;
|
||||
}
|
||||
@@ -183,19 +180,18 @@ namespace lms::cover
|
||||
{
|
||||
const std::multimap<std::string, std::filesystem::path> coverPaths{ getCoverPaths(directory) };
|
||||
|
||||
auto tryLoadImageFromFilename = [&](std::string_view fileName)
|
||||
{
|
||||
std::unique_ptr<IEncodedImage> image;
|
||||
auto tryLoadImageFromFilename = [&](std::string_view fileName) {
|
||||
std::unique_ptr<IEncodedImage> image;
|
||||
|
||||
auto range{ coverPaths.equal_range(std::string {fileName}) };
|
||||
for (auto it{ range.first }; it != range.second; ++it)
|
||||
{
|
||||
image = getFromCoverFile(it->second, width);
|
||||
if (image)
|
||||
break;
|
||||
}
|
||||
return image;
|
||||
};
|
||||
auto range{ coverPaths.equal_range(std::string{ fileName }) };
|
||||
for (auto it{ range.first }; it != range.second; ++it)
|
||||
{
|
||||
image = getFromCoverFile(it->second, width);
|
||||
if (image)
|
||||
break;
|
||||
}
|
||||
return image;
|
||||
};
|
||||
|
||||
std::unique_ptr<IEncodedImage> image;
|
||||
|
||||
@@ -353,14 +349,13 @@ namespace lms::cover
|
||||
|
||||
Session& session{ _db.getTLSSession() };
|
||||
|
||||
auto getReleaseInfo{ [&]
|
||||
{
|
||||
auto getReleaseInfo{ [&] {
|
||||
std::optional<ReleaseInfo> res;
|
||||
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
|
||||
// get a track in this release, consider the release is in a single directory
|
||||
const auto tracks{ Track::find(session, Track::FindParameters {}.setRelease(releaseId).setRange(Range{ 0, 1 }).setSortMethod(TrackSortMethod::Release)) };
|
||||
const auto tracks{ Track::find(session, Track::FindParameters{}.setRelease(releaseId).setRange(Range{ 0, 1 }).setSortMethod(TrackSortMethod::Release)) };
|
||||
if (!tracks.results.empty())
|
||||
{
|
||||
const Track::pointer& track{ tracks.results.front() };
|
||||
@@ -416,18 +411,17 @@ namespace lms::cover
|
||||
Track::FindParameters params;
|
||||
params.setArtist(artistId, { TrackArtistLinkType::ReleaseArtist });
|
||||
|
||||
Track::find(session, params, [&](const Track::pointer& track)
|
||||
{
|
||||
Artist::FindParameters artistFindParams;
|
||||
artistFindParams.setTrack(track->getId());
|
||||
artistFindParams.setLinkType(TrackArtistLinkType::ReleaseArtist);
|
||||
Track::find(session, params, [&](const Track::pointer& track) {
|
||||
Artist::FindParameters artistFindParams;
|
||||
artistFindParams.setTrack(track->getId());
|
||||
artistFindParams.setLinkType(TrackArtistLinkType::ReleaseArtist);
|
||||
|
||||
const auto releaseArtists{ Artist::findIds(session, artistFindParams) };
|
||||
if (releaseArtists.results.size() == 1)
|
||||
releasePaths.insert(track->getAbsoluteFilePath().parent_path());
|
||||
else
|
||||
multiArtistReleasePaths.insert(track->getAbsoluteFilePath().parent_path());
|
||||
});
|
||||
const auto releaseArtists{ Artist::findIds(session, artistFindParams) };
|
||||
if (releaseArtists.results.size() == 1)
|
||||
releasePaths.insert(track->getAbsoluteFilePath().parent_path());
|
||||
else
|
||||
multiArtistReleasePaths.insert(track->getAbsoluteFilePath().parent_path());
|
||||
});
|
||||
}
|
||||
|
||||
std::vector<std::string> artistFileNames;
|
||||
@@ -497,4 +491,3 @@ namespace lms::cover
|
||||
}
|
||||
|
||||
} // namespace lms::cover
|
||||
|
||||
|
||||
@@ -23,9 +23,10 @@
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
#include "services/cover/ICoverService.hpp"
|
||||
#include "image/IEncodedImage.hpp"
|
||||
#include "database/Types.hpp"
|
||||
#include "image/IEncodedImage.hpp"
|
||||
#include "services/cover/ICoverService.hpp"
|
||||
|
||||
#include "ImageCache.hpp"
|
||||
|
||||
namespace lms::db
|
||||
@@ -49,23 +50,23 @@ namespace lms::cover
|
||||
CoverService(const CoverService&) = delete;
|
||||
CoverService& operator=(const CoverService&) = delete;
|
||||
|
||||
std::shared_ptr<image::IEncodedImage> getFromTrack(db::TrackId trackId, image::ImageSize width) override;
|
||||
std::shared_ptr<image::IEncodedImage> getFromRelease(db::ReleaseId releaseId, image::ImageSize width) override;
|
||||
std::shared_ptr<image::IEncodedImage> getFromArtist(db::ArtistId artistId, image::ImageSize width) override;
|
||||
std::shared_ptr<image::IEncodedImage> getDefaultSvgCover() override;
|
||||
void flushCache() override;
|
||||
void setJpegQuality(unsigned quality) override;
|
||||
std::shared_ptr<image::IEncodedImage> getFromTrack(db::TrackId trackId, image::ImageSize width) override;
|
||||
std::shared_ptr<image::IEncodedImage> getFromRelease(db::ReleaseId releaseId, image::ImageSize width) override;
|
||||
std::shared_ptr<image::IEncodedImage> getFromArtist(db::ArtistId artistId, image::ImageSize width) override;
|
||||
std::shared_ptr<image::IEncodedImage> getDefaultSvgCover() override;
|
||||
void flushCache() override;
|
||||
void setJpegQuality(unsigned quality) override;
|
||||
|
||||
std::shared_ptr<image::IEncodedImage> getFromTrack(db::Session& dbSession, db::TrackId trackId, image::ImageSize width, bool allowReleaseFallback);
|
||||
std::unique_ptr<image::IEncodedImage> getFromAvMediaFile(const av::IAudioFile& input, image::ImageSize width) const;
|
||||
std::unique_ptr<image::IEncodedImage> getFromCoverFile(const std::filesystem::path& p, image::ImageSize width) const;
|
||||
std::shared_ptr<image::IEncodedImage> getFromTrack(db::Session& dbSession, db::TrackId trackId, image::ImageSize width, bool allowReleaseFallback);
|
||||
std::unique_ptr<image::IEncodedImage> getFromAvMediaFile(const av::IAudioFile& input, image::ImageSize width) const;
|
||||
std::unique_ptr<image::IEncodedImage> getFromCoverFile(const std::filesystem::path& p, image::ImageSize width) const;
|
||||
|
||||
std::unique_ptr<image::IEncodedImage> getFromTrack(const std::filesystem::path& path, image::ImageSize width) const;
|
||||
std::multimap<std::string, std::filesystem::path> getCoverPaths(const std::filesystem::path& directoryPath) const;
|
||||
std::unique_ptr<image::IEncodedImage> getFromDirectory(const std::filesystem::path& directory, image::ImageSize width, const std::vector<std::string>& preferredFileNames, bool allowPickRandom) const;
|
||||
std::unique_ptr<image::IEncodedImage> getFromSameNamedFile(const std::filesystem::path& filePath, image::ImageSize width) const;
|
||||
std::unique_ptr<image::IEncodedImage> getFromTrack(const std::filesystem::path& path, image::ImageSize width) const;
|
||||
std::multimap<std::string, std::filesystem::path> getCoverPaths(const std::filesystem::path& directoryPath) const;
|
||||
std::unique_ptr<image::IEncodedImage> getFromDirectory(const std::filesystem::path& directory, image::ImageSize width, const std::vector<std::string>& preferredFileNames, bool allowPickRandom) const;
|
||||
std::unique_ptr<image::IEncodedImage> getFromSameNamedFile(const std::filesystem::path& filePath, image::ImageSize width) const;
|
||||
|
||||
bool checkCoverFile(const std::filesystem::path& filePath) const;
|
||||
bool checkCoverFile(const std::filesystem::path& filePath) const;
|
||||
|
||||
db::Db& _db;
|
||||
|
||||
@@ -80,4 +81,3 @@ namespace lms::cover
|
||||
};
|
||||
|
||||
} // namespace lms::cover
|
||||
|
||||
|
||||
@@ -21,14 +21,15 @@
|
||||
|
||||
#include <mutex>
|
||||
|
||||
#include "core/Random.hpp"
|
||||
#include "core/ILogger.hpp"
|
||||
#include "core/Random.hpp"
|
||||
|
||||
namespace lms::cover
|
||||
{
|
||||
ImageCache::ImageCache(std::size_t maxCacheSize)
|
||||
: _maxCacheSize{ maxCacheSize }
|
||||
{}
|
||||
{
|
||||
}
|
||||
|
||||
void ImageCache::addImage(const EntryDesc& entryDesc, std::shared_ptr<image::IEncodedImage> image)
|
||||
{
|
||||
@@ -70,4 +71,4 @@ namespace lms::cover
|
||||
_cacheSize = 0;
|
||||
_cache.clear();
|
||||
}
|
||||
}
|
||||
} // namespace lms::cover
|
||||
@@ -65,8 +65,8 @@ namespace lms::cover
|
||||
};
|
||||
|
||||
std::unordered_map<EntryDesc, std::shared_ptr<image::IEncodedImage>, EntryHasher> _cache;
|
||||
std::size_t _cacheSize{};
|
||||
mutable std::atomic<std::size_t> _cacheMisses{};
|
||||
mutable std::atomic<std::size_t> _cacheHits{};
|
||||
std::size_t _cacheSize{};
|
||||
mutable std::atomic<std::size_t> _cacheMisses{};
|
||||
mutable std::atomic<std::size_t> _cacheHits{};
|
||||
};
|
||||
}
|
||||
} // namespace lms::cover
|
||||
@@ -52,5 +52,4 @@ namespace lms::cover
|
||||
|
||||
std::unique_ptr<ICoverService> createCoverService(db::Db& db, const std::filesystem::path& defaultSvgCoverPath);
|
||||
|
||||
} // namespace lms::coverArt
|
||||
|
||||
} // namespace lms::cover
|
||||
|
||||
Reference in New Issue
Block a user