Skip to content

Commit

Permalink
MetadataHandler: Refactor static methods
Browse files Browse the repository at this point in the history
  • Loading branch information
KarlStraussberger committed Mar 13, 2024
1 parent 8792d06 commit e5f2992
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 14 deletions.
3 changes: 2 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,9 @@ add_library(libgerbera STATIC
src/metadata/metacontent_handler.h
src/metadata/metadata_enums.cc
src/metadata/metadata_enums.h
src/metadata/metadata_handler.cc
src/metadata/metadata_handler.h
src/metadata/metadata_service.cc
src/metadata/metadata_service.h
src/metadata/resolution.cc
src/metadata/resolution.h
src/metadata/taglib_handler.cc
Expand Down
20 changes: 10 additions & 10 deletions src/metadata/exiv2_handler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ Exiv2Handler::Exiv2Handler(const std::shared_ptr<Context>& context)
{
// silence exiv2 messages without debug
Exiv2::LogMsg::setHandler([](auto, auto s) { log_debug("Exiv2: {}", s); });
metaTags = config->getDictionaryOption(CFG_IMPORT_LIBOPTS_EXIV2_METADATA_TAGS_LIST);
auxTags = config->getArrayOption(CFG_IMPORT_LIBOPTS_EXIV2_AUXDATA_TAGS_LIST);
}

void Exiv2Handler::fillMetadata(const std::shared_ptr<CdsObject>& item)
Expand Down Expand Up @@ -153,9 +155,8 @@ void Exiv2Handler::fillMetadata(const std::shared_ptr<CdsObject>& item)
}

// if there are any metadata tags that the user wants - add them
const auto meta = config->getDictionaryOption(CFG_IMPORT_LIBOPTS_EXIV2_METADATA_TAGS_LIST);
if (!meta.empty()) {
for (auto&& [metatag, metakey] : meta) {
if (!metaTags.empty()) {
for (auto&& [metatag, metakey] : metaTags) {
std::string metaval;
log_debug("metatag: {} ", metatag.c_str());
if (startswith(metatag, "Exif")) {
Expand All @@ -167,8 +168,8 @@ void Exiv2Handler::fillMetadata(const std::shared_ptr<CdsObject>& item)
if (xmpMd != xmpData.end())
metaval = trimString(xmpMd->toString());
} else {
log_debug("Invalid meta Tag {}", metatag.c_str());
break;
log_warning("Invalid meta Tag {}", metatag.c_str());
continue;
}
if (!metaval.empty()) {
metaval = sc->convert(metaval);
Expand All @@ -181,9 +182,8 @@ void Exiv2Handler::fillMetadata(const std::shared_ptr<CdsObject>& item)
}

// if there are any auxilary tags that the user wants - add them
const auto aux = config->getArrayOption(CFG_IMPORT_LIBOPTS_EXIV2_AUXDATA_TAGS_LIST);
if (!aux.empty()) {
for (auto&& auxtag : aux) {
if (!auxTags.empty()) {
for (auto&& auxtag : auxTags) {
std::string auxval;
log_debug("auxtag: {} ", auxtag.c_str());
if (startswith(auxtag, "Exif")) {
Expand All @@ -195,8 +195,8 @@ void Exiv2Handler::fillMetadata(const std::shared_ptr<CdsObject>& item)
if (xmpMd != xmpData.end())
auxval = trimString(xmpMd->toString());
} else {
log_debug("Invalid Aux Tag {}", auxtag.c_str());
break;
log_warning("Invalid Aux Tag {}", auxtag.c_str());
continue;
}
if (!auxval.empty()) {
auxval = sc->convert(auxval);
Expand Down
4 changes: 4 additions & 0 deletions src/metadata/exiv2_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ class Exiv2Handler : public MetadataHandler {
explicit Exiv2Handler(const std::shared_ptr<Context>& context);
void fillMetadata(const std::shared_ptr<CdsObject>& item) override;
std::unique_ptr<IOHandler> serveContent(const std::shared_ptr<CdsObject>& obj, const std::shared_ptr<CdsResource>& resource) override;

private:
std::vector<std::string> auxTags;
std::map<std::string, std::string> metaTags;
};

#endif // __METADATA_EXIV2_H__
Expand Down
5 changes: 2 additions & 3 deletions src/metadata/metadata_handler.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
class CdsItem;
class CdsObject;
class CdsResource;
class ContentManager;
class IOHandler;
enum class ContentHandler;
enum class MetadataFields;
Expand All @@ -56,8 +55,8 @@ class MetadataHandler {

public:
explicit MetadataHandler(const std::shared_ptr<Context>& context)
: config(context->getConfig())
, mime(context->getMime())
: config(context->getConfig())
, mime(context->getMime())
{
}

Expand Down
73 changes: 73 additions & 0 deletions src/metadata/metadata_service.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*GRB*
Gerbera - https://gerbera.io/
metadata_service.h - this file is part of Gerbera.
Copyright (C) 2024 Gerbera Contributors
Gerbera is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
Gerbera 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 Gerbera. If not, see <http://www.gnu.org/licenses/>.
*/

/// \file metadata_service.h
/// \brief Definition of the MetadataService class.
#ifndef __METADATA_SERVICE_H__
#define __METADATA_SERVICE_H__

#include <map>

#include "common.h"
#include "util/grb_fs.h"

// forward declaration
class CdsItem;
class Config;
class ContentManager;
class Context;
enum class ContentHandler;
class MetadataHandler;

enum class MetadataType {
TagLib,
Exiv2,
LibExif,
Matroska,
WavPack,
Ffmpeg,
Thumbnailer,
VideoThumbnailer,
ImageThumbnailer,
FanArt,
ContainerArt,
Subtitle,
Metafile,
ResourceFile,
};

class MetadataService {
private:
std::shared_ptr<Context> context;
std::shared_ptr<Config> config;
std::shared_ptr<ContentManager> content;
std::map<std::string, std::string> mappings;
std::map<MetadataType, std::shared_ptr<MetadataHandler>> handlers;

public:
explicit MetadataService(const std::shared_ptr<Context>& context, const std::shared_ptr<ContentManager>& content);

void extractMetaData(const std::shared_ptr<CdsItem>& item, const fs::directory_entry& dirEnt);
std::shared_ptr<MetadataHandler> getHandler(ContentHandler handlerType);

};

#endif // __METADATA_HANDLER_H__

0 comments on commit e5f2992

Please sign in to comment.