Mage GM work again
This commit is contained in:
@@ -19,11 +19,11 @@
|
||||
|
||||
#include "JPEGImage.hpp"
|
||||
|
||||
#include "Exception.hpp"
|
||||
#include "RawImage.hpp"
|
||||
#include "image/Exception.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
|
||||
namespace CoverArt::GraphicsMagick
|
||||
namespace Image::GraphicsMagick
|
||||
{
|
||||
JPEGImage::JPEGImage(const RawImage& rawImage, unsigned quality)
|
||||
{
|
||||
|
||||
@@ -25,9 +25,9 @@
|
||||
|
||||
#include <Magick++.h>
|
||||
|
||||
#include "cover/IEncodedImage.hpp"
|
||||
#include "image/IEncodedImage.hpp"
|
||||
|
||||
namespace CoverArt::GraphicsMagick
|
||||
namespace Image::GraphicsMagick
|
||||
{
|
||||
class RawImage;
|
||||
class JPEGImage : public IEncodedImage
|
||||
|
||||
@@ -21,41 +21,43 @@
|
||||
|
||||
#include <magick/resource.h>
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
#include "JPEGImage.hpp"
|
||||
#include "Exception.hpp"
|
||||
#include "image/Exception.hpp"
|
||||
#include "utils/Logger.hpp"
|
||||
|
||||
namespace Image::GraphicsMagick
|
||||
namespace Image
|
||||
{
|
||||
|
||||
std::unique_ptr<IRawImage> decodeImage(const std::byte* encodedData, std::size_t encodedDataSize)
|
||||
{
|
||||
return std::make_unique<RawImage>(encodedData, encodedDataSize);
|
||||
return std::make_unique<GraphicsMagick::RawImage>(encodedData, encodedDataSize);
|
||||
}
|
||||
|
||||
std::unique_ptr<IRawImage> decodeImage(const std::filesystem::path& path)
|
||||
{
|
||||
return std::make_unique<RawImage>(path)
|
||||
return std::make_unique<GraphicsMagick::RawImage>(path);
|
||||
}
|
||||
|
||||
void
|
||||
init(const std::filesystem::path& path)
|
||||
{
|
||||
Magick::InitializeMagick(path.string().c_str());
|
||||
|
||||
if (auto nbThreads {MagickLib::GetMagickResourceLimit(MagickLib::ThreadsResource)}; nbThreads != 1)
|
||||
LMS_LOG(COVER, WARNING) << "Consider setting env var OMP_NUM_THREADS=1 to save resources";
|
||||
|
||||
if (!MagickLib::SetMagickResourceLimit(MagickLib::ThreadsResource, 1))
|
||||
LMS_LOG(COVER, ERROR) << "Cannot set Magick thread resource limit to 1!";
|
||||
|
||||
if (!MagickLib::SetMagickResourceLimit(MagickLib::DiskResource, 0))
|
||||
LMS_LOG(COVER, ERROR) << "Cannot set Magick disk resource limit to 0!";
|
||||
|
||||
LMS_LOG(COVER, INFO) << "Magick threads resource limit = " << GetMagickResourceLimit(MagickLib::ThreadsResource);
|
||||
LMS_LOG(COVER, INFO) << "Magick Disk resource limit = " << GetMagickResourceLimit(MagickLib::DiskResource);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
init(const std::filesystem::path& path)
|
||||
namespace Image::GraphicsMagick
|
||||
{
|
||||
Magick::InitializeMagick(path.string().c_str());
|
||||
|
||||
if (auto nbThreads {MagickLib::GetMagickResourceLimit(MagickLib::ThreadsResource)}; nbThreads != 1)
|
||||
LMS_LOG(COVER, WARNING) << "Consider setting env var OMP_NUM_THREADS=1 to save resources";
|
||||
|
||||
if (!MagickLib::SetMagickResourceLimit(MagickLib::ThreadsResource, 1))
|
||||
LMS_LOG(COVER, ERROR) << "Cannot set Magick thread resource limit to 1!";
|
||||
|
||||
if (!MagickLib::SetMagickResourceLimit(MagickLib::DiskResource, 0))
|
||||
LMS_LOG(COVER, ERROR) << "Cannot set Magick disk resource limit to 0!";
|
||||
|
||||
LMS_LOG(COVER, INFO) << "Magick threads resource limit = " << GetMagickResourceLimit(MagickLib::ThreadsResource);
|
||||
LMS_LOG(COVER, INFO) << "Magick Disk resource limit = " << GetMagickResourceLimit(MagickLib::DiskResource);
|
||||
}
|
||||
|
||||
RawImage::RawImage(const std::byte* encodedData, std::size_t encodedDataSize)
|
||||
{
|
||||
|
||||
@@ -28,14 +28,12 @@
|
||||
#include <cstddef>
|
||||
#include <filesystem>
|
||||
|
||||
#include "cover/IEncodedImage.hpp"
|
||||
#include "IRawImage.hpp"
|
||||
#include "image/IEncodedImage.hpp"
|
||||
#include "image/IRawImage.hpp"
|
||||
|
||||
namespace CoverArt::GraphicsMagick
|
||||
namespace Image::GraphicsMagick
|
||||
{
|
||||
void init(const std::filesystem::path& path);
|
||||
|
||||
class RawImage : IRawImage
|
||||
class RawImage : public IRawImage
|
||||
{
|
||||
public:
|
||||
RawImage(const std::byte* encodedData, std::size_t encodedDataSize);
|
||||
|
||||
@@ -43,6 +43,12 @@ namespace Image
|
||||
{
|
||||
return std::make_unique<STB::RawImage>(path);
|
||||
}
|
||||
|
||||
void
|
||||
init(const std::filesystem::path& path)
|
||||
{
|
||||
}
|
||||
{
|
||||
}
|
||||
|
||||
namespace Image::STB
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <filesystem>
|
||||
#include <memory>
|
||||
|
||||
#include "image/IEncodedImage.hpp"
|
||||
@@ -33,6 +34,7 @@ namespace Image
|
||||
virtual std::unique_ptr<IEncodedImage> encodeToJPEG(unsigned quality) const = 0;
|
||||
};
|
||||
|
||||
void init(const std::filesystem::path& path);
|
||||
std::unique_ptr<IRawImage> decodeImage(const std::byte* encodedData, std::size_t encodedDataSize);
|
||||
std::unique_ptr<IRawImage> decodeImage(const std::filesystem::path& path);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,6 @@ class WhereClause
|
||||
private:
|
||||
std::string _clause; // WHERE clause
|
||||
std::list<std::string> _bindArgs;
|
||||
|
||||
};
|
||||
|
||||
class InnerJoinClause
|
||||
|
||||
@@ -184,7 +184,6 @@ class Track : public Object<Track, TrackId>
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
static const std::size_t _maxNameLength = 128;
|
||||
static const std::size_t _maxCopyrightLength = 128;
|
||||
static const std::size_t _maxCopyrightURLLength = 128;
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2021 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <string_view>
|
||||
#include "services/scrobbling/Listen.hpp"
|
||||
|
||||
namespace Scrobbling
|
||||
{
|
||||
ScrobblerBase::ScrobblerBase(Database::Db& db)
|
||||
: _db {db}
|
||||
{
|
||||
}
|
||||
|
||||
Database::TrackListId
|
||||
ScrobberBase::getListensTrackList(Database::UserId userId, std::string_view trackListName)
|
||||
{
|
||||
std::string_view listensTrackListName {getListensTrackListName()};
|
||||
Database::Session& session {_db.getTLSSession()};
|
||||
|
||||
{
|
||||
auto transaction {session.createSharedTransaction()};
|
||||
|
||||
if (auto trackList {Database::TrackList::get(session, listensTrackListName, Database::TrackList::Type::Internal, userId)})
|
||||
return trackList->getId();
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction {session.createUniqueTransaction()};
|
||||
if (auto trackList {Database::TrackList::get(session, listensTrackListName, Database::TrackList::Type::Internal, userId)})
|
||||
return trackList->getId();
|
||||
|
||||
const Database::User::pointer user {Database::User::getById(session, userId)};
|
||||
if (!user)
|
||||
return {};
|
||||
|
||||
Database::TrackList::pointer trackList {Database::TrackList::create(session, listensTrackListName, Database::TrackList::Type::Internal, false, user)};
|
||||
return trackList->getId();
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ScrobberBase::saveTimedListen(const TimedListen& listen, std::string_view trackListName)
|
||||
{
|
||||
const Database::TrackListId trackListId {getListensTrackList(listen.userId)};
|
||||
if (!trackListId)
|
||||
return false;
|
||||
|
||||
{
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} // ns Scrobbling
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
#include <Wt/WServer.h>
|
||||
#include <Wt/WApplication.h>
|
||||
|
||||
#include "image/IRawImage.hpp"
|
||||
#include "services/auth/IAuthTokenService.hpp"
|
||||
#include "services/auth/IPasswordService.hpp"
|
||||
#include "services/auth/IEnvService.hpp"
|
||||
@@ -254,6 +255,7 @@ int main(int argc, char* argv[])
|
||||
else
|
||||
throw LmsException {"Bad value '" + authenticationBackend + "' for 'authentication-backend'"};
|
||||
|
||||
Image::init(argv[0]);
|
||||
Service<Cover::ICoverService> coverService {Cover::createCoverService(database, argv[0], server.appRoot() + "/images/unknown-cover.jpg")};
|
||||
Service<Recommendation::IRecommendationService> recommendationService {Recommendation::createRecommendationService(database)};
|
||||
Service<Scanner::IScannerService> scannerService {Scanner::createScannerService(database, *recommendationService)};
|
||||
|
||||
Reference in New Issue
Block a user