Options: Added 'output' and 'output-directory' Options

This commit is contained in:
Moss 2022-09-28 23:27:48 -04:00
parent facb363608
commit 144353558c
3 changed files with 67 additions and 43 deletions

View File

@ -58,11 +58,13 @@ this needs to be redone every time the cookies expire (~30 minutes)
### Options ### Options
``` ```
--help Display this message --help Display this message
--quality Set the quality of the downloaded video. Quality can be set to 'all' which --quality Set the quality of the downloaded video. Quality can be set to 'all' which
will download all qualities and place them into separate folders will download all qualities and place them into separate folders
--verbose Display debug information while running --output Set the output filename
--force-cookies Interpret the next to arguments as authentication cookie and session cookie --output-directory Set the directory where files are output
--verbose Display debug information while running
--force-cookies Interpret the next to arguments as authentication cookie and session cookie
``` ```
dropout-dl will download the episode into a folder with the name of the series in the format dropout-dl will download the episode into a folder with the name of the series in the format
`S<season-num>E<episode-num><name>.mp4` `S<season-num>E<episode-num><name>.mp4`

View File

@ -39,7 +39,6 @@ namespace dropout_dl {
std::string embedded_page_data; std::string embedded_page_data;
std::string config_url; std::string config_url;
std::string config_data; std::string config_data;
std::string filename;
std::vector<std::string> qualities; std::vector<std::string> qualities;
std::vector<std::string> quality_urls; std::vector<std::string> quality_urls;
@ -114,16 +113,6 @@ namespace dropout_dl {
std::replace(this->series.begin(), this->series.end(), ',', '_'); std::replace(this->series.begin(), this->series.end(), ',', '_');
this->filename = "S" + (this->season_number.size() < 2 ? "0" + this->season_number : this->season_number) + "E" + (this->episode_number.size() < 2 ? "0" + this->episode_number : this->episode_number) + this->name + ".mp4";
std::replace(filename.begin(), filename.end(), ' ', '_');
std::replace(filename.begin(), filename.end(), ',', '_');
if (verbose) {
std::cout << "filename: " << filename << '\n';
}
this->embedded_url = get_embed_url(episode_data); this->embedded_url = get_embed_url(episode_data);
replace_all(this->embedded_url, "&amp;", "&"); replace_all(this->embedded_url, "&amp;", "&");

View File

@ -321,6 +321,8 @@ public:
bool verbose = false; bool verbose = false;
bool cookies_forced = false; bool cookies_forced = false;
std::string quality; std::string quality;
std::string filename;
std::string series_dir;
std::vector<std::string> cookies; std::vector<std::string> cookies;
static std::vector<std::string> convert_program_args(int argc, char** argv) { static std::vector<std::string> convert_program_args(int argc, char** argv) {
@ -334,43 +336,56 @@ public:
options(int argc, char** argv) { options(int argc, char** argv) {
std::vector<std::string> args = convert_program_args(argc, argv); std::vector<std::string> args = convert_program_args(argc, argv);
bool next_is_quality = false; for (int i = 0; i < args.size(); i++) {
bool next_is_cookie = false; const auto& arg = args[i];
for (const auto& arg : args) {
if (next_is_quality) { if (arg.substr(0, 2) != "--") {
quality = arg;
next_is_quality = false;
continue;
}
if (next_is_cookie) {
cookies.emplace_back(arg);
if (cookies.size() == 2) {
next_is_quality = false;
}
continue;
}
else if (arg.substr(0, 2) != "--") {
url = arg; url = arg;
} }
else { else {
if (arg == "--verbose") { if (arg == "--verbose") {
verbose = true; verbose = true;
} else if (arg == "--quality") { } else if (arg == "--quality") {
next_is_quality = true; if (i + 1 >= args.size()) {
std::cerr << "ARGUMENT PARSE ERROR: --quality used with too few following arguments\n";
exit(8);
}
quality = args[++i];
} }
else if (arg == "--force-cookies") { else if (arg == "--force-cookies") {
next_is_cookie = true; if (i + 2 >= args.size()) {
std::cerr << "ARGUMENT PARSE ERROR: --force-cookies used with too few following arguments\n";
exit(8);
}
cookies.emplace_back(args[++i]);
cookies.emplace_back(args[++i]);
cookies_forced = true; cookies_forced = true;
} }
else if (arg == "--output") {
if (i + 1 >= args.size()) {
std::cerr << "ARGUMENT PARSE ERROR: --output used with too few following arguments\n";
exit(8);
}
filename = args[++i];
}
else if (arg == "--output-directory") {
if (i + 1 >= args.size()) {
std::cerr << "ARGUMENT PARSE ERROR: --output-directory used with too few following arguments\n";
exit(8);
}
series_dir = args[++i];
}
else if (arg == "--help") { else if (arg == "--help") {
std::cout << "Usage: dropout-dl [OPTIONS] <url> [OPTIONS]\n" std::cout << "Usage: dropout-dl [OPTIONS] <url> [OPTIONS]\n"
"\n" "\n"
"Options:\n" "Options:\n"
"\t--help Display this message\n" "\t--help Display this message\n"
"\t--quality Set the quality of the downloaded video. Quality can be set to 'all' which\n" "\t--quality Set the quality of the downloaded video. Quality can be set to 'all' which\n"
"\t will download all qualities and place them into separate folders\n" "\t will download all qualities and place them into separate folders\n"
"\t--verbose Display debug information while running\n" "\t--output Set the output filename\n"
"\t--force-cookies Interpret the next to arguments as authentication cookie and session cookie\n" "\t--output-directory Set the directory where files are output\n"
"\t--verbose Display debug information while running\n"
"\t--force-cookies Interpret the next to arguments as authentication cookie and session cookie\n"
<< std::endl; << std::endl;
exit(0); exit(0);
@ -412,6 +427,24 @@ int main(int argc, char** argv) {
dropout_dl::episode ep(options.url, options.cookies, options.verbose); dropout_dl::episode ep(options.url, options.cookies, options.verbose);
if (options.filename.empty()) {
options.filename = "S" + (ep.season_number.size() < 2 ? "0" + ep.season_number : ep.season_number) + "E" +
(ep.episode_number.size() < 2 ? "0" + ep.episode_number : ep.episode_number) + ep.name +
".mp4";
std::replace(options.filename.begin(), options.filename.end(), ' ', '_');
std::replace(options.filename.begin(), options.filename.end(), ',', '_');
}
if (options.verbose) {
std::cout << "filename: " << options.filename << '\n';
}
if (options.series_dir.empty()) {
options.series_dir = ep.series;
}
if (!std::filesystem::is_directory(ep.series)) { if (!std::filesystem::is_directory(ep.series)) {
std::filesystem::create_directories(ep.series); std::filesystem::create_directories(ep.series);
if (options.verbose) { if (options.verbose) {
@ -421,20 +454,20 @@ int main(int argc, char** argv) {
if (options.quality == "all") { if (options.quality == "all") {
for (const auto& possible_quality : ep.qualities) { for (const auto& possible_quality : ep.qualities) {
if (!std::filesystem::is_directory(ep.series + "/" + possible_quality)) { if (!std::filesystem::is_directory(options.series_dir + "/" + possible_quality)) {
std::filesystem::create_directories(ep.series + "/" + possible_quality); std::filesystem::create_directories(options.series_dir + "/" + possible_quality);
if (options.verbose) { if (options.verbose) {
std::cout << "Creating series directory" << '\n'; std::cout << "Creating series directory" << '\n';
} }
} }
std::fstream out(ep.series + "/" + possible_quality + "/" + ep.filename, std::fstream out(options.series_dir + "/" + possible_quality + "/" + options.filename,
std::ios_base::in | std::ios_base::out | std::ios_base::trunc); std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
out << ep.get_video_data(possible_quality) << std::endl; out << ep.get_video_data(possible_quality) << std::endl;
} }
} }
else { else {
std::fstream out(ep.series + "/" + ep.filename, std::ios_base::in | std::ios_base::out | std::ios_base::trunc); std::fstream out(options.series_dir + "/" + options.filename, std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
out << ep.get_video_data(options.quality) << std::endl; out << ep.get_video_data(options.quality) << std::endl;
} }