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; goto dlsymerror;
} }
rl.getName = ( const std::string(*)() ) dlsym( libhndl, "getName" ); rl.getName = ( const std::string(*)() ) dlsym( libhndl, "getName" );
rl.canRenameMultipleFiles = ( const bool(*)() ) dlsym( libhndl, "canRenameMultipleFiles" );
rl.config = library.second; rl.config = library.second;
result.push_back( rl ); 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 ); bool renamePath( const string &path, const RenameObject &renamer );
std::vector< string > getCustomKeys(); std::vector< string > getCustomKeys();
const string getName(); const string getName();
const bool canRenameMultipleFiles();
} }
#endif // TV_RENAME_HPP #endif // TV_RENAME_HPP

View File

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

View File

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

View File

@ -51,5 +51,9 @@ std::vector< string > getCustomKeys() {
} }
const string getName() { 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() { 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() { const string getName() {
return "thetvdb"; return "TheTVDB";
}
const bool canRenameMultipleFiles() {
return true;
} }