diff --git a/functions.cpp b/functions.cpp index 2007dca..f7db7b8 100644 --- a/functions.cpp +++ b/functions.cpp @@ -34,7 +34,7 @@ std::vector< RenameLibrary > getLibraries(const std::vector( * )() )dlsym( + rl.getCustomKeys = ( std::vector< std::pair< std::string, std::string > >( * )() )dlsym( libhndl, "getCustomKeys" ); if ( !rl.getCustomKeys ) { result.push_back( rl ); diff --git a/library.hpp b/library.hpp index d9f2805..9774a2c 100644 --- a/library.hpp +++ b/library.hpp @@ -15,11 +15,17 @@ using string = std::string; #endif +#define STRING_TYPE "string" +#define NUM_TYPE "number" +#define YEAR_TYPE "year" +#define DATE_TYPE "date" +#define BOOL_TYPE "bool" + extern "C" { bool init(const string &configuration); std::vector< RenameObject > getOptions( const RenameObject &search ); bool renamePath( const string &path, const RenameObject &renamer ); -std::vector< string > getCustomKeys(); +std::vector< std::pair > getCustomKeys(); const string getName(); const bool canRenameMultipleFiles(); } diff --git a/main.cpp b/main.cpp index 86c5783..9b1a238 100644 --- a/main.cpp +++ b/main.cpp @@ -138,7 +138,7 @@ void getOptionsRest( const std::shared_ptr< restbed::Session > &session, rapidjs sendResponse(getOptionsJson(search), 200, session); } -std::vector< std::string > getCustomKeys(size_t library_id) { +std::vector< std::pair< std::string, std::string > > getCustomKeys(size_t library_id) { if(library_id >= libraries.size()) { return {}; } @@ -148,16 +148,16 @@ std::vector< std::string > getCustomKeys(size_t library_id) { std::string getCustomKeysJson(size_t library_id) { std::ostringstream res; - res << "{\n \"custom_keys\": [\n"; + res << "{\n \"custom_keys\": {\n"; auto custom_keys = getCustomKeys(library_id); if(!custom_keys.empty()) { for(auto &key : custom_keys) { - res << "\"" << safeJson(key) << "\",\n"; + res << "\"" << safeJson(key.first) << "\": \"" << safeJson(key.second) << "\",\n"; } res.seekp( -2, std::ios_base::end ); res << "\n"; } - res << " ]\n}"; + res << " }\n}"; return res.str(); } diff --git a/rename_library.hpp b/rename_library.hpp index 7cfc6c1..82b7fdc 100644 --- a/rename_library.hpp +++ b/rename_library.hpp @@ -8,7 +8,7 @@ struct RenameLibrary { bool ( *init )( const std::string & ); std::vector< RenameObject > ( *getOptions )( const RenameObject & ); bool ( *renamePath )( const std::string &, const RenameObject & ); - std::vector< std::string > ( *getCustomKeys )(); + std::vector< std::pair< std::string, std::string > > ( *getCustomKeys )(); const std::string ( *getName )(); const bool ( *canRenameMultipleFiles )(); void *libhndl; diff --git a/simple_rename/simple.cpp b/simple_rename/simple.cpp index a7a707b..261c484 100644 --- a/simple_rename/simple.cpp +++ b/simple_rename/simple.cpp @@ -22,11 +22,11 @@ constexpr const char_t *_tv_rename_dir_divider = "/"; #endif -bool init(const string &config_path) { +bool init( const string &config_path ) { return true; } -std::vector< RenameObject > getOptions( const RenameObject &/*UNUSED*/ ) { +std::vector< RenameObject > getOptions( const RenameObject & /*UNUSED*/ ) { return {}; } @@ -40,14 +40,17 @@ bool renamePath( const string &path, const RenameObject &renamer ) { return false; } - if ( new_name.find('/') != string::npos || new_name.find('\\') != string::npos ) { + if ( new_name.find( '/' ) != string::npos || + new_name.find( '\\' ) != string::npos ) { return false; } - return FSLib::rename( path, FSLib::canonical( FSLib::getContainingDirectory(path) ) + "/" + new_name ); + return FSLib::rename( + path, FSLib::canonical( FSLib::getContainingDirectory( path ) ) + "/" + + new_name ); } -std::vector< string > getCustomKeys() { - return { "new_name" }; +std::vector< std::pair< string, string > > getCustomKeys() { + return { { "new_name", STRING_TYPE } }; } const string getName() { diff --git a/themoviedb/moviedb.cpp b/themoviedb/moviedb.cpp index a7102ea..6683eca 100644 --- a/themoviedb/moviedb.cpp +++ b/themoviedb/moviedb.cpp @@ -277,8 +277,12 @@ bool renamePath( const string &path, const RenameObject &renamer ) { year ); } -std::vector< string > getCustomKeys() { - return { "id", "language", "year", "original_title", "use_original" }; +std::vector< std::pair< string, string > > getCustomKeys() { + return { { "id", NUM_TYPE }, + { "language", STRING_TYPE }, + { "year", YEAR_TYPE }, + { "original_title", STRING_TYPE }, + { "use_original", BOOL_TYPE } }; } const string getName() { diff --git a/thetvdb/tv_rename.cpp b/thetvdb/tv_rename.cpp index 86c9170..e6faa0d 100644 --- a/thetvdb/tv_rename.cpp +++ b/thetvdb/tv_rename.cpp @@ -401,8 +401,11 @@ bool renamePath( const string &path, const RenameObject &renamer ) { return true; } -std::vector< string > getCustomKeys() { - return { "id", "language", "pattern", "order" }; +std::vector< std::pair< string, string > > getCustomKeys() { + return { { "id", NUM_TYPE }, + { "language", STRING_TYPE }, + { "pattern", STRING_TYPE }, + { "order", STRING_TYPE } }; } const string getName() {