/*
* Copyright (C) 2015 Emeric Poupon
*
* This file is part of LMS.
*
* LMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* LMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see .
*/
#pragma once
#include
#include
#include "services/artwork/IArtworkService.hpp"
#include "ImageCache.hpp"
namespace lms::db
{
class Session;
}
namespace lms::metadata
{
class IAudioFileParser;
}
namespace lms::cover
{
class ArtworkService : public IArtworkService
{
public:
ArtworkService(db::Db& db, const std::filesystem::path& defaultReleaseCoverSvgPath, const std::filesystem::path& defaultArtistImageSvgPath);
~ArtworkService() override;
ArtworkService(const ArtworkService&) = delete;
ArtworkService& operator=(const ArtworkService&) = delete;
private:
ImageFindResult findArtistImage(db::ArtistId artistId) override;
ImageFindResult findTrackImage(db::TrackId trackId) override;
ImageFindResult findTrackMediaImage(db::TrackId trackId) override;
ImageFindResult findReleaseImage(db::ReleaseId releaseId) override;
ImageFindResult findTrackListImage(db::TrackListId trackListId) override;
std::shared_ptr getImage(db::ImageId imageId, std::optional width) override;
std::shared_ptr getTrackEmbeddedImage(db::TrackEmbeddedImageId trackEmbeddedImageId, std::optional width) override;
std::shared_ptr getDefaultReleaseCover() override;
std::shared_ptr getDefaultArtistImage() override;
void flushCache() override;
void setJpegQuality(unsigned quality) override;
std::unique_ptr getFromImageFile(const std::filesystem::path& p, std::optional width) const;
std::unique_ptr getTrackImage(const std::filesystem::path& path, std::size_t index, std::optional width) const;
db::Db& _db;
std::unique_ptr _audioFileParser;
ImageCache _cache;
std::shared_ptr _defaultReleaseCover;
std::shared_ptr _defaultArtistImage;
static inline const std::vector _fileExtensions{ ".jpg", ".jpeg", ".png", ".bmp" }; // TODO parametrize
unsigned _jpegQuality;
};
} // namespace lms::cover