Libraries can tell wheter they support renaming multiple files

This commit is contained in:
zv0n 2022-02-27 19:24:35 +01:00
parent 2bbaac3157
commit f2e87add67
7 changed files with 35 additions and 19 deletions

View File

@ -41,6 +41,7 @@ std::vector< RenameLibrary > getLibraries(const std::vector<std::pair<std::strin
goto dlsymerror;
}
rl.getName = ( const std::string(*)() ) dlsym( libhndl, "getName" );
rl.canRenameMultipleFiles = ( const bool(*)() ) dlsym( libhndl, "canRenameMultipleFiles" );
rl.config = library.second;
result.push_back( rl );
}

View File

@ -21,6 +21,7 @@ std::vector< RenameObject > getOptions( const RenameObject &search );
bool renamePath( const string &path, const RenameObject &renamer );
std::vector< string > getCustomKeys();
const string getName();
const bool canRenameMultipleFiles();
}
#endif // TV_RENAME_HPP

View File

@ -53,22 +53,23 @@ bool verifyLogin( const std::shared_ptr< restbed::Session > &session, rapidjson:
return res;
}
std::vector<std::pair<std::string, size_t>> getTypes() {
std::vector<std::pair<std::string, size_t>> result{};
std::vector<std::pair<RenameLibrary*, size_t>> getLibraries() {
std::vector<std::pair<RenameLibrary*, size_t>> result{};
for(size_t i = 0; i < libraries.size(); i++) {
result.emplace_back(libraries[i].getName(), i);
result.emplace_back(&libraries[i], i);
}
return result;
}
std::string getTypesJson() {
auto types = getTypes();
std::string getLibrariesJson() {
auto libraries = getLibraries();
std::ostringstream result;
result << "{\n \"types\": [\n";
if(!types.empty()) {
for(const auto &type : types) {
result << " {\n \"id\": " << type.second << ",\n";
result << " \"name\": \"" << safeJson(type.first) << "\"\n },\n";
result << "{\n \"libraries\": [\n";
if(!libraries.empty()) {
for(const auto &library : libraries) {
result << " {\n \"id\": " << library.second << ",\n";
result << " \"name\": \"" << safeJson(library.first->getName()) << "\"\n,";
result << " \"multiple_files\": " << (library.first->canRenameMultipleFiles() ? "true" : "false") << "\n },\n";
}
result.seekp(-2, std::ios_base::end);
result << "\n";
@ -78,8 +79,8 @@ std::string getTypesJson() {
return res;
}
void getTypesRest( const std::shared_ptr< restbed::Session > &session ) {
sendResponse(getTypesJson(), restbed::OK, session);
void getLibrariesRest( const std::shared_ptr< restbed::Session > &session ) {
sendResponse(getLibrariesJson(), restbed::OK, session);
}
std::vector< RenameObject > getOptions(const RenameObject &search) {
@ -512,10 +513,10 @@ int main(int argc, char **argv) {
restbed::Service service;
auto get_types = std::make_shared< restbed::Resource >();
get_types->set_path("/get_types");
get_types->set_method_handler( "GET", getTypesRest );
service.publish(get_types);
auto get_libraries = std::make_shared< restbed::Resource >();
get_libraries->set_path("/get_libraries");
get_libraries->set_method_handler( "GET", getLibrariesRest );
service.publish(get_libraries);
auto search = std::make_shared< restbed::Resource >();
search->set_path("/search");

View File

@ -10,6 +10,7 @@ struct RenameLibrary {
bool ( *renamePath )( const std::string &, const RenameObject & );
std::vector< std::string > ( *getCustomKeys )();
const std::string ( *getName )();
const bool ( *canRenameMultipleFiles )();
void *libhndl;
std::string name;
std::string config;

View File

@ -51,5 +51,9 @@ std::vector< string > getCustomKeys() {
}
const string getName() {
return "simple rename";
return "Simple Rename";
}
const bool canRenameMultipleFiles() {
return false;
}

View File

@ -282,5 +282,9 @@ std::vector< string > getCustomKeys() {
}
const string getName() {
return "themoviedb";
return "TheMovieDB";
}
const bool canRenameMultipleFiles() {
return false;
}

View File

@ -406,5 +406,9 @@ std::vector< string > getCustomKeys() {
}
const string getName() {
return "thetvdb";
return "TheTVDB";
}
const bool canRenameMultipleFiles() {
return true;
}