Added cover resizing

This commit is contained in:
Nedko 2024-07-01 15:17:40 +03:00
parent 21058e5ac4
commit 42ab8dbcb1
3 changed files with 37 additions and 1 deletions

View File

@ -3,6 +3,7 @@
#include <fstream>
#include <set>
#include <stdlib.h>
#include <sys/stat.h>
using std::endl;
@ -187,3 +188,16 @@ string clean_filename(const string& s)
return result;
}
bool exec_cmd(const string& cmd)
{
int error;
error = system(cmd.c_str());
if (0 != error)
{
return false;
}
return true;
}

View File

@ -19,5 +19,6 @@ void json_extract(const nlohmann::json& j, const std::string& key, bool& out);
bool ensure_folder(const std::string& main_path, const std::string& folder);
std::string trim_whitespace(const std::string& s);
std::string clean_filename(const std::string& s);
bool exec_cmd(const std::string& cmd);
#endif // COMMON_H_

View File

@ -15,6 +15,20 @@ void usage(const char *name)
cout << "Usage: " << name << " [catalog id] ..." << endl;
}
string gen_resize_command(const string& release_folder, const string& convert_exec)
{
string cmd;
cmd = convert_exec;
cmd += " \"";
cmd += build_fname(release_folder, "", "Cover.*");
cmd += "\" -resize 750x750 \"";
cmd += build_fname(release_folder, "", "Cover_small.jpg");
cmd += "\"";
return cmd;
}
int main(int argc, char **argv)
{
// Config stuff
@ -104,7 +118,14 @@ int main(int argc, char **argv)
continue;
}
// TODO: Resize cover
// Resize cover
ok = exec_cmd(gen_resize_command(release_folder, convert_exec));
if (!ok)
{
cout << "Could not resize cover for release - " << release.catalog_id << endl;
continue;
}
break;
// Download tracks (1 -- N)
for (Track& track : release.tracks)