Added getCustomKeyOptions and getCustomKeyDefault functions

This commit is contained in:
zv0n 2022-03-06 16:40:15 +01:00
parent 2b47f2c825
commit 49d32f9023
7 changed files with 530 additions and 38 deletions

View File

@ -34,12 +34,24 @@ std::vector< RenameLibrary > getLibraries(const std::vector<std::pair<std::strin
result.push_back( rl ); result.push_back( rl );
goto dlsymerror; goto dlsymerror;
} }
rl.getCustomKeys = ( std::vector< std::pair< std::string, std::string > >( * )() )dlsym( rl.getCustomKeys = ( std::vector< std::unordered_map< std::string, std::string > >( * )() )dlsym(
libhndl, "getCustomKeys" ); libhndl, "getCustomKeys" );
if ( !rl.getCustomKeys ) { if ( !rl.getCustomKeys ) {
result.push_back( rl ); result.push_back( rl );
goto dlsymerror; goto dlsymerror;
} }
rl.getCustomKeyOptions = ( std::vector< std::pair< std::string, std::string > >( * )(const std::string &) )dlsym(
libhndl, "getCustomKeyOptions" );
if ( !rl.getCustomKeyOptions ) {
result.push_back( rl );
goto dlsymerror;
}
rl.getCustomKeyDefault = ( const std::string( * )(const std::string &) )dlsym(
libhndl, "getCustomKeyDefault" );
if ( !rl.getCustomKeyDefault ) {
result.push_back( rl );
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.canRenameMultipleFiles = ( const bool(*)() ) dlsym( libhndl, "canRenameMultipleFiles" );
rl.config = library.second; rl.config = library.second;

View File

@ -20,12 +20,17 @@ using string = std::string;
#define YEAR_TYPE "year" #define YEAR_TYPE "year"
#define DATE_TYPE "date" #define DATE_TYPE "date"
#define BOOL_TYPE "bool" #define BOOL_TYPE "bool"
#define MULTICHOICE_TYPE "multichoice"
extern "C" { extern "C" {
bool init(const string &configuration); bool init(const string &configuration);
std::vector< RenameObject > getOptions( const RenameObject &search ); 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< std::pair<string, string> > getCustomKeys(); // key name, key type
std::vector< std::unordered_map<string, string> > getCustomKeys();
// option internal representation, option display value
std::vector< std::pair<string, string> > getCustomKeyOptions(const string &key);
const string getCustomKeyDefault(const string &key);
const string getName(); const string getName();
const bool canRenameMultipleFiles(); const bool canRenameMultipleFiles();
} }

View File

@ -16,6 +16,8 @@
#include "config/config.hpp" #include "config/config.hpp"
#include "fileobject.hpp" #include "fileobject.hpp"
// TODO add customKeyOptions and customKeyDefault endpoints
std::vector<RenameLibrary> libraries{}; std::vector<RenameLibrary> libraries{};
Configuration cfg; Configuration cfg;
@ -138,7 +140,7 @@ void getOptionsRest( const std::shared_ptr< restbed::Session > &session, rapidjs
sendResponse(getOptionsJson(search), 200, session); sendResponse(getOptionsJson(search), 200, session);
} }
std::vector< std::pair< std::string, std::string > > getCustomKeys(size_t library_id) { std::vector< std::unordered_map< std::string, std::string > > getCustomKeys(size_t library_id) {
if(library_id >= libraries.size()) { if(library_id >= libraries.size()) {
return {}; return {};
} }
@ -148,16 +150,20 @@ std::vector< std::pair< std::string, std::string > > getCustomKeys(size_t librar
std::string getCustomKeysJson(size_t library_id) { std::string getCustomKeysJson(size_t library_id) {
std::ostringstream res; std::ostringstream res;
res << "{\n \"custom_keys\": {\n"; res << "{\n \"custom_keys\": [\n";
auto custom_keys = getCustomKeys(library_id); auto custom_keys = getCustomKeys(library_id);
if(!custom_keys.empty()) { if(!custom_keys.empty()) {
for(auto &key : custom_keys) { for(auto &key : custom_keys) {
res << "\"" << safeJson(key.first) << "\": \"" << safeJson(key.second) << "\",\n"; res << " {\n";
res << " \"name\": \"" << safeJson(key["name"]) << "\",\n";
res << " \"type\": \"" << safeJson(key["type"]) << "\",\n";
res << " \"input\": \"" << safeJson(key["input"]) << "\"\n";
res << " },\n";
} }
res.seekp( -2, std::ios_base::end ); res.seekp( -2, std::ios_base::end );
res << "\n"; res << "\n";
} }
res << " }\n}"; res << " ]\n}";
return res.str(); return res.str();
} }

View File

@ -2,13 +2,16 @@
#define RENAME_LIBRARY_H #define RENAME_LIBRARY_H
#include <vector> #include <vector>
#include <unordered_map>
#include "rename_object.hpp" #include "rename_object.hpp"
struct RenameLibrary { struct RenameLibrary {
bool ( *init )( const std::string & ); bool ( *init )( const std::string & );
std::vector< RenameObject > ( *getOptions )( const RenameObject & ); std::vector< RenameObject > ( *getOptions )( const RenameObject & );
bool ( *renamePath )( const std::string &, const RenameObject & ); bool ( *renamePath )( const std::string &, const RenameObject & );
std::vector< std::pair< std::string, std::string > > ( *getCustomKeys )(); std::vector< std::unordered_map< std::string, std::string > > ( *getCustomKeys )();
std::vector< std::pair< std::string, std::string > > ( *getCustomKeyOptions )(const std::string &);
const std::string ( *getCustomKeyDefault )(const std::string &);
const std::string ( *getName )(); const std::string ( *getName )();
const bool ( *canRenameMultipleFiles )(); const bool ( *canRenameMultipleFiles )();
void *libhndl; void *libhndl;

View File

@ -31,12 +31,8 @@ std::vector< RenameObject > getOptions( const RenameObject & /*UNUSED*/ ) {
} }
bool renamePath( const string &path, const RenameObject &renamer ) { bool renamePath( const string &path, const RenameObject &renamer ) {
string new_name = ""; string new_name = renamer.getPresentedName();
if(new_name.empty()) {
if ( renamer.getCustomFields().find( "new_name" ) !=
renamer.getCustomFields().end() ) {
new_name = renamer.getCustomFields().at( "new_name" );
} else {
return false; return false;
} }
@ -49,8 +45,20 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
new_name ); new_name );
} }
std::vector< std::pair< string, string > > getCustomKeys() { std::vector< std::unordered_map< string, string > > getCustomKeys() {
return { { "new_name", STRING_TYPE } }; return {};
}
std::vector< std::pair< string, string > > getCustomKeyOptions(const string &key) {
return {};
}
const string getCustomKeyDefault(const string &key) {
return "";
}
const string choiceDisplay() {
return "\%name";
} }
const string getName() { const string getName() {

View File

@ -43,6 +43,196 @@ constexpr const char_t *_tv_rename_dir_divider = "/";
#endif #endif
const std::vector< std::pair< std::string, std::string > > languages = {
{ "aa", "Afar" },
{ "ab", "Abkhazian" },
{ "ae", "Avestan" },
{ "af", "Afrikaans" },
{ "ak", "Akan" },
{ "am", "Amharic" },
{ "an", "Aragonese" },
{ "ar", "العربية" },
{ "as", "Assamese" },
{ "av", "Avaric" },
{ "ay", "Aymara" },
{ "az", "Azərbaycan" },
{ "ba", "Bashkir" },
{ "be", "беларуская мова" },
{ "bg", "български език" },
{ "bi", "Bislama" },
{ "bm", "Bamanankan" },
{ "bn", "বাংলা" },
{ "bo", "Tibetan" },
{ "br", "Breton" },
{ "bs", "Bosanski" },
{ "ca", "Català" },
{ "ce", "Chechen" },
{ "ch", "Finu' Chamorro" },
{ "cn", "广州话 / 廣州話" },
{ "co", "Corsican" },
{ "cr", "Cree" },
{ "cs", "Český" },
{ "cu", "Slavic" },
{ "cv", "Chuvash" },
{ "cy", "Cymraeg" },
{ "da", "Dansk" },
{ "de", "Deutsch" },
{ "dv", "Divehi" },
{ "dz", "Dzongkha" },
{ "ee", "Èʋegbe" },
{ "el", "ελληνικά" },
{ "en", "English" },
{ "eo", "Esperanto" },
{ "es", "Español" },
{ "et", "Eesti" },
{ "eu", "euskera" },
{ "fa", "فارسی" },
{ "ff", "Fulfulde" },
{ "fi", "suomi" },
{ "fj", "Fijian" },
{ "fo", "Faroese" },
{ "fr", "Français" },
{ "fy", "Frisian" },
{ "ga", "Gaeilge" },
{ "gd", "Gaelic" },
{ "gl", "Galego" },
{ "gn", "Guarani" },
{ "gu", "Gujarati" },
{ "gv", "Manx" },
{ "ha", "Hausa" },
{ "he", "עִבְרִית" },
{ "hi", "हिन्दी" },
{ "ho", "Hiri Motu" },
{ "hr", "Hrvatski" },
{ "ht", "Haitian; Haitian Creole" },
{ "hu", "Magyar" },
{ "hy", "Armenian" },
{ "hz", "Herero" },
{ "ia", "Interlingua" },
{ "id", "Bahasa indonesia" },
{ "ie", "Interlingue" },
{ "ig", "Igbo" },
{ "ii", "Yi" },
{ "ik", "Inupiaq" },
{ "io", "Ido" },
{ "is", "Íslenska" },
{ "it", "Italiano" },
{ "iu", "Inuktitut" },
{ "ja", "日本語" },
{ "jv", "Javanese" },
{ "ka", "ქართული" },
{ "kg", "Kongo" },
{ "ki", "Kikuyu" },
{ "kj", "Kuanyama" },
{ "kk", "қазақ" },
{ "kl", "Kalaallisut" },
{ "km", "Khmer" },
{ "kn", "Kannada" },
{ "ko", "한국어/조선말" },
{ "kr", "Kanuri" },
{ "ks", "Kashmiri" },
{ "ku", "Kurdish" },
{ "kv", "Komi" },
{ "kw", "Cornish" },
{ "ky", "Kirghiz" },
{ "la", "Latin" },
{ "lb", "Letzeburgesch" },
{ "lg", "Ganda" },
{ "li", "Limburgish" },
{ "ln", "Lingala" },
{ "lo", "Lao" },
{ "lt", "Lietuvių" },
{ "lu", "Luba-Katanga" },
{ "lv", "Latviešu" },
{ "mg", "Malagasy" },
{ "mh", "Marshall" },
{ "mi", "Maori" },
{ "mk", "Macedonian" },
{ "ml", "Malayalam" },
{ "mn", "Mongolian" },
{ "mo", "Moldavian" },
{ "mr", "Marathi" },
{ "ms", "Bahasa melayu" },
{ "mt", "Malti" },
{ "my", "Burmese" },
{ "na", "Nauru" },
{ "nb", "Bokmål" },
{ "nd", "Ndebele" },
{ "ne", "Nepali" },
{ "ng", "Ndonga" },
{ "nl", "Nederlands" },
{ "nn", "Norwegian Nynorsk" },
{ "no", "Norsk" },
{ "nr", "Ndebele" },
{ "nv", "Navajo" },
{ "ny", "Chichewa; Nyanja" },
{ "oc", "Occitan" },
{ "oj", "Ojibwa" },
{ "om", "Oromo" },
{ "or", "Oriya" },
{ "os", "Ossetian; Ossetic" },
{ "pa", "ਪੰਜਾਬੀ" },
{ "pi", "Pali" },
{ "pl", "Polski" },
{ "ps", "پښتو" },
{ "pt", "Português" },
{ "qu", "Quechua" },
{ "rm", "Raeto-Romance" },
{ "rn", "Kirundi" },
{ "ro", "Română" },
{ "ru", "Pусский" },
{ "rw", "Kinyarwanda" },
{ "sa", "Sanskrit" },
{ "sc", "Sardinian" },
{ "sd", "Sindhi" },
{ "se", "Northern Sami" },
{ "sg", "Sango" },
{ "sh", "Serbo-Croatian" },
{ "si", "සිංහල" },
{ "sk", "Slovenčina" },
{ "sl", "Slovenščina" },
{ "sm", "Samoan" },
{ "sn", "Shona" },
{ "so", "Somali" },
{ "sq", "shqip" },
{ "sr", "Srpski" },
{ "ss", "Swati" },
{ "st", "Sotho" },
{ "su", "Sundanese" },
{ "sv", "svenska" },
{ "sw", "Kiswahili" },
{ "ta", "தமிழ்" },
{ "te", "తెలుగు" },
{ "tg", "Tajik" },
{ "th", "ภาษาไทย" },
{ "ti", "Tigrinya" },
{ "tk", "Turkmen" },
{ "tl", "Tagalog" },
{ "tn", "Tswana" },
{ "to", "Tonga" },
{ "tr", "Türkçe" },
{ "ts", "Tsonga" },
{ "tt", "Tatar" },
{ "tw", "Twi" },
{ "ty", "Tahitian" },
{ "ug", "Uighur" },
{ "uk", "Український" },
{ "ur", "اردو" },
{ "uz", "ozbek" },
{ "ve", "Venda" },
{ "vi", "Tiếng Việt" },
{ "vo", "Volapük" },
{ "wa", "Walloon" },
{ "wo", "Wolof" },
{ "xh", "Xhosa" },
{ "xx", "No Language" },
{ "yi", "Yiddish" },
{ "yo", "Èdè Yorùbá" },
{ "za", "Zhuang" },
{ "zh", "普通话" },
{ "zu", "Zulu" }
};
string _moviedb_api_token{}; string _moviedb_api_token{};
Request _moviedb_request; Request _moviedb_request;
@ -277,12 +467,52 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
year ); year );
} }
std::vector< std::pair< string, string > > getCustomKeys() { std::vector< std::unordered_map< string, string > > getCustomKeys() {
return { { "id", NUM_TYPE }, return { {
{ "language", STRING_TYPE }, { "name", "id"},
{ "year", YEAR_TYPE }, {"type", NUM_TYPE},
{ "original_title", STRING_TYPE }, {"input", "true"}
{ "use_original", BOOL_TYPE } }; },
{
{ "name", "language" },
{ "type", MULTICHOICE_TYPE },
{ "input", "true" },
},
{
{ "name", "year" },
{ "type", YEAR_TYPE },
{ "input", "true" },
},
{
{ "name", "original_title" },
{ "type", STRING_TYPE },
{ "input", "false" },
},
{
{ "name", "use_original" },
{ "type", BOOL_TYPE },
{ "input", "true" },
},
};
}
std::vector< std::pair< string, string > >
getCustomKeyOptions( const string &key ) {
if ( key == "language" ) {
return languages;
}
return {};
}
const string getCustomKeyDefault( const string &key ) {
if ( key == "language" ) {
return "en";
}
return "";
}
const string choiceDisplay() {
return "\%name (\%original_title) (\%year)";
} }
const string getName() { const string getName() {

View File

@ -46,6 +46,191 @@ constexpr const char_t *_tv_rename_dir_divider = "/";
#define TV_LINUX 0x0400 #define TV_LINUX 0x0400
#define TV_DVD 0x0800 #define TV_DVD 0x0800
const std::vector< std::pair< std::string, std::string > > languages = {
{ "aa", "Afaraf" },
{ "ab", "аҧсуабызшәа" },
{ "ae", "avesta" },
{ "af", "Afrikaans" },
{ "ak", "Akan" },
{ "am", "አማርኛ" },
{ "an", "aragonés" },
{ "ar", "العربية" },
{ "as", "অসমীয়া" },
{ "av", "авармацӀ" },
{ "ay", "aymararu" },
{ "az", "azərbaycandili" },
{ "ba", "башҡорттеле" },
{ "be", "беларускаямова" },
{ "bg", "българскиезик" },
{ "bh", "भोजपुरी" },
{ "bi", "Bislama" },
{ "bm", "bamanankan" },
{ "bn", "বাংলা" },
{ "bo", "བོད་ཡིག" },
{ "br", "brezhoneg" },
{ "bs", "bosanskijezik" },
{ "ca", "català" },
{ "ce", "нохчийнмотт" },
{ "ch", "Chamoru" },
{ "co", "corsu" },
{ "cr", "ᓀᐦᐃᔭᐍᐏᐣ" },
{ "cs", "čeština" },
{ "cu", "ѩзыкъсловѣньскъ" },
{ "cv", "чӑвашчӗлхи" },
{ "cy", "Cymraeg" },
{ "da", "dansk" },
{ "de", "Deutsch" },
{ "dv", "ދިވެހި" },
{ "dz", "རྫོང་ཁ" },
{ "ee", "Eʋegbe" },
{ "el", "ελληνικήγλώσσα" },
{ "en", "English" },
{ "eo", "Esperanto" },
{ "es", "español" },
{ "et", "eesti" },
{ "eu", "euskara" },
{ "fa", "فارسی" },
{ "ff", "Fulfulde" },
{ "fi", "suomi" },
{ "fj", "vosaVakaviti" },
{ "fo", "føroyskt" },
{ "fr", "français" },
{ "fy", "Frysk" },
{ "ga", "Gaeilge" },
{ "gd", "Gàidhlig" },
{ "gl", "galego" },
{ "gn", "Avañe'ẽ" },
{ "gu", "ગુજરાતી" },
{ "gv", "Gaelg" },
{ "ha", "هَوُسَ" },
{ "he", "עברית" },
{ "hi", "हिन्दी" },
{ "ho", "HiriMotu" },
{ "hr", "hrvatskijezik" },
{ "ht", "Kreyòlayisyen" },
{ "hu", "Magyar" },
{ "hy", "Հայերեն" },
{ "hz", "Otjiherero" },
{ "ia", "Interlingua" },
{ "id", "BahasaIndonesia" },
{ "ie", "Interlingue" },
{ "ig", "AsụsụIgbo" },
{ "ii", "Nuosuhxop" },
{ "ik", "Iñupiaq" },
{ "io", "Ido" },
{ "is", "Íslenska" },
{ "it", "italiano" },
{ "iu", "ᐃᓄᒃᑎᑐᑦ" },
{ "ja", "日本語" },
{ "jv", "basaJawa" },
{ "ka", "ქართული" },
{ "kg", "KiKongo" },
{ "ki", "Gĩkũyũ" },
{ "kj", "Kuanyama" },
{ "kk", "қазақтілі" },
{ "kl", "kalaallisut" },
{ "km", "ខ្មែរ" },
{ "kn", "ಕನ್ನಡ" },
{ "ko", "한국어" },
{ "kr", "Kanuri" },
{ "ks", "कश्मीरी" },
{ "ku", "Kurdî" },
{ "kv", "комикыв" },
{ "kw", "Kernewek" },
{ "ky", "кыргызтили" },
{ "la", "latine" },
{ "lb", "Lëtzebuergesch" },
{ "lg", "Luganda" },
{ "li", "Limburgs" },
{ "ln", "Lingála" },
{ "lo", "ພາສາລາວ" },
{ "lt", "lietuviųkalba" },
{ "lu", "Luba-Katanga" },
{ "lv", "latviešuvaloda" },
{ "mg", "Malagasyfiteny" },
{ "mh", "KajinM̧ajeļ" },
{ "mi", "tereoMāori" },
{ "mk", "македонскијазик" },
{ "ml", "മലയാളം" },
{ "mn", "монгол" },
{ "mr", "मराठी" },
{ "ms", "bahasaMelayu" },
{ "mt", "Malti" },
{ "my", "Burmese" },
{ "na", "EkakairũNaoero" },
{ "nd", "isiNdebele" },
{ "ne", "नेपाली" },
{ "ng", "Owambo" },
{ "nl", "Nederlands" },
{ "no", "Norskbokmål" },
{ "nr", "isiNdebele" },
{ "nv", "Dinébizaad" },
{ "ny", "chiCheŵa" },
{ "oc", "occitan" },
{ "oj", "ᐊᓂᔑᓈᐯᒧᐎᓐ" },
{ "om", "AfaanOromoo" },
{ "or", "ଓଡ଼ିଆ" },
{ "os", "иронæвзаг" },
{ "pa", "ਪੰਜਾਬੀ" },
{ "pi", "पाऴि" },
{ "pl", "językpolski" },
{ "ps", "پښتو" },
{ "pt", "Português-Brasil" },
{ "qu", "RunaSimi" },
{ "rm", "rumantschgrischun" },
{ "rn", "Ikirundi" },
{ "ro", "limbaromână" },
{ "ru", "русскийязык" },
{ "rw", "Ikinyarwanda" },
{ "sa", "संस्कृतम्" },
{ "sc", "sardu" },
{ "sd", "सिन्धी" },
{ "se", "Davvisámegiella" },
{ "sg", "yângâtîsängö" },
{ "si", "සිංහල" },
{ "sk", "slovenčina" },
{ "sl", "slovenskijezik" },
{ "sm", "gaganafa'aSamoa" },
{ "sn", "chiShona" },
{ "so", "Soomaaliga" },
{ "sq", "gjuhashqipe" },
{ "sr", "српскијезик" },
{ "ss", "SiSwati" },
{ "st", "Sesotho" },
{ "su", "BasaSunda" },
{ "sv", "svenska" },
{ "sw", "Kiswahili" },
{ "ta", "தமிழ்" },
{ "te", "తెలుగు" },
{ "tg", "тоҷикӣ" },
{ "th", "ไทย" },
{ "ti", "ትግርኛ" },
{ "tk", "Türkmen" },
{ "tl", "WikangTagalog" },
{ "tn", "Setswana" },
{ "to", "fakaTonga" },
{ "tr", "Türkçe" },
{ "ts", "Xitsonga" },
{ "tt", "татартеле" },
{ "tw", "Twi" },
{ "ty", "ReoTahiti" },
{ "ug", "Uyƣurqə" },
{ "uk", "українськамова" },
{ "ur", "اردو" },
{ "uz", "Ozbek" },
{ "ve", "Tshivenḓa" },
{ "vi", "TiếngViệt" },
{ "vo", "Volapük" },
{ "wa", "walon" },
{ "wo", "Wollof" },
{ "xh", "isiXhosa" },
{ "yi", "ייִדיש" },
{ "yo", "Yorùbá" },
{ "za", "Saɯcueŋƅ" },
{ "zh", "大陆简体" },
{ "zu", "isiZulu" }
};
string _tv_rename_api_token{}; string _tv_rename_api_token{};
Request _tv_rename_request; Request _tv_rename_request;
@ -71,11 +256,11 @@ bool authenticate( const std::string &api_key ) {
return true; return true;
} }
bool init(const string &config_path) { bool init( const string &config_path ) {
return authenticate( "42B66F5E-C6BF-423F-ADF9-CC97163472F6" ); return authenticate( "42B66F5E-C6BF-423F-ADF9-CC97163472F6" );
} }
std::vector< std::pair< string, string > > std::vector< std::tuple< string, string, string > >
searchShow( const string &show, const string &language ) { searchShow( const string &show, const string &language ) {
Request &request = _tv_rename_request; Request &request = _tv_rename_request;
request.addHeader( TEXT( "Accept: application/json" ) ); request.addHeader( TEXT( "Accept: application/json" ) );
@ -86,8 +271,7 @@ searchShow( const string &show, const string &language ) {
auto encoded_show = encodeUrl( show ); auto encoded_show = encodeUrl( show );
rapidjson::Document json; rapidjson::Document json;
json.Parse( json.Parse( request.get( TEXT( "/search/series?name=" ) + encoded_show ).c_str() );
request.get( TEXT( "/search/series?name=" ) + encoded_show ).c_str() );
if ( json.HasParseError() ) if ( json.HasParseError() )
return {}; return {};
@ -96,13 +280,15 @@ searchShow( const string &show, const string &language ) {
return {}; return {};
} }
std::vector< std::pair< string, string > > ret; std::vector< std::tuple< string, string, string > > ret;
// find all possible shows // find all possible shows
for ( size_t i = 0; i < results.Size(); i++ ) { for ( size_t i = 0; i < results.Size(); i++ ) {
auto show = toString( results[i]["seriesName"].GetString() ); auto show = toString( results[i]["seriesName"].GetString() );
auto id = toString( std::to_string( results[i]["id"].GetInt() ) ); auto id = toString( std::to_string( results[i]["id"].GetInt() ) );
ret.emplace_back( show, id ); std::string date = toString( results[i]["firstAired"].GetString() );
auto year = date.substr(0, date.find('-'));
ret.emplace_back( show, id, year );
} }
request.clearHeader(); request.clearHeader();
return ret; return ret;
@ -335,14 +521,15 @@ void allSeasons( const string &id, const string &path, const string &show,
} }
} }
RenameObject showToRenameObject( const std::pair< string, string > &show, RenameObject showToRenameObject( const std::tuple< string, string, string > &show,
const std::string &language ) { const std::string &language ) {
RenameObject result; RenameObject result;
result.setPresentedName( show.first ); result.setPresentedName( std::get<0>(show) );
result.addCustomField( "id", show.second ); result.addCustomField( "id", std::get<1>(show) );
result.addCustomField( "language", language ); result.addCustomField( "language", language );
result.addCustomField( "order", "aired" ); result.addCustomField( "order", "aired" );
result.addCustomField( "pattern", getDefaultPattern() ); result.addCustomField( "pattern", getDefaultPattern() );
result.addCustomField( "year", std::get<2>(show) );
return result; return result;
} }
@ -379,9 +566,10 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
auto results = searchShow( renamer.getPresentedName(), lang ); auto results = searchShow( renamer.getPresentedName(), lang );
if ( results.empty() ) if ( results.empty() )
return false; return false;
id = results[0].second; id = std::get<1>(results[0]);
show = results[0].first; show = std::get<0>(results[0]);
} else if( renamer.getCustomFields().find("id") != renamer.getCustomFields().end()) { } else if ( renamer.getCustomFields().find( "id" ) !=
renamer.getCustomFields().end() ) {
id = renamer.getCustomFields().at( "id" ); id = renamer.getCustomFields().at( "id" );
show = showFromId( id ); show = showFromId( id );
} }
@ -401,11 +589,51 @@ bool renamePath( const string &path, const RenameObject &renamer ) {
return true; return true;
} }
std::vector< std::pair< string, string > > getCustomKeys() { std::vector< std::unordered_map< string, string > > getCustomKeys() {
return { { "id", NUM_TYPE }, return { {
{ "language", STRING_TYPE }, { "name", "id"},
{ "pattern", STRING_TYPE }, {"type", NUM_TYPE},
{ "order", STRING_TYPE } }; {"input", "true"}
},
{
{ "name", "language" },
{ "type", STRING_TYPE },
{ "input", "true" },
},
{
{ "name", "pattern" },
{ "type", STRING_TYPE },
{ "input", "true" },
},
{
{ "name", "order" },
{ "type", MULTICHOICE_TYPE },
{ "input", "true" },
},
{
{ "name", "year" },
{ "type", YEAR_TYPE },
{ "input", "false" },
}
};
}
std::vector< std::pair< string, string > > getCustomKeyOptions(const string &key) {
if(key == "language") {
return languages;
}
return {};
}
const string choiceDisplay() {
return "\%name (\%year)";
}
const string getCustomKeyDefault(const string &key) {
if(key == "language") {
return "en";
}
return "";
} }
const string getName() { const string getName() {