From eb39b102841c00905e83d21a73c6a0f5e6edf0f3 Mon Sep 17 00:00:00 2001 From: Moss Date: Thu, 29 Sep 2022 18:04:04 -0400 Subject: [PATCH] Options: Added '--output-directory' Option This changes where the show files are placed. --- src/main.cpp | 33 +++++++++++---------------------- src/season.cpp | 5 +++++ src/series.cpp | 9 +++++++-- src/series.h | 8 +++++++- 4 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 57778d9..30cafc2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -302,7 +302,7 @@ public: bool season = false; std::string quality; std::string filename; - std::string series_dir; + std::string output_directory; std::string episode; std::vector cookies; @@ -355,7 +355,7 @@ public: std::cerr << "ARGUMENT PARSE ERROR: --output-directory used with too few following arguments\n"; exit(8); } - series_dir = args[++i]; + output_directory = args[++i]; } else if (arg == "series") { series = true; @@ -382,6 +382,9 @@ public: } } + if (output_directory.empty()) { + output_directory = "."; + } if (season && series) { std::cerr << "ARGUMENT PARSE ERROR: Season and Series arguments used\n"; @@ -420,28 +423,18 @@ int main(int argc, char** argv) { if (options.series) { dropout_dl::series series(options.url, options.cookies); - if (options.series_dir.empty()) { - options.series_dir = series.name; - - std::replace(options.series_dir.begin(), options.series_dir.end(), ' ', '_'); - - std::replace(options.series_dir.begin(), options.series_dir.end(), ',', '_'); - } - - series.download(options.quality, options.series_dir); + series.download(options.quality, options.output_directory); } else if (options.season) { dropout_dl::season season = dropout_dl::series::get_season(options.url, options.cookies); - if (options.series_dir.empty()) { - options.series_dir = season.series_name; + std::string series_directory = season.series_name; - std::replace(options.series_dir.begin(), options.series_dir.end(), ' ', '_'); + std::replace(series_directory.begin(), series_directory.end(), ' ', '_'); - std::replace(options.series_dir.begin(), options.series_dir.end(), ',', '_'); - } + std::replace(series_directory.begin(), series_directory.end(), ',', '_'); - season.download(options.quality, options.series_dir); + season.download(options.quality, options.output_directory + "/" + series_directory); } else { dropout_dl::episode ep(options.url, options.cookies, options.verbose); @@ -460,10 +453,6 @@ int main(int argc, char** argv) { std::cout << "filename: " << options.filename << '\n'; } - if (options.series_dir.empty()) { - options.series_dir = ep.series; - } - if (!std::filesystem::is_directory(ep.series)) { std::filesystem::create_directories(ep.series); if (options.verbose) { @@ -471,7 +460,7 @@ int main(int argc, char** argv) { } } - ep.download(options.quality, options.series_dir, options.filename); + ep.download(options.quality, options.output_directory + "/" + ep.series, options.filename); } diff --git a/src/season.cpp b/src/season.cpp index b7177b5..ab8bcf1 100644 --- a/src/season.cpp +++ b/src/season.cpp @@ -54,6 +54,11 @@ namespace dropout_dl { } void season::download(const std::string &quality, const std::string &series_directory) { + if (!std::filesystem::is_directory(series_directory)) { + std::filesystem::create_directories(series_directory); + std::cout << "Creating series directory" << '\n'; + } + std::string dir = series_directory + "/" + this->name; std::replace(dir.begin(), dir.end(), ' ', '_'); diff --git a/src/series.cpp b/src/series.cpp index b567333..9531751 100644 --- a/src/series.cpp +++ b/src/series.cpp @@ -219,9 +219,14 @@ namespace dropout_dl { exit(9); } - void series::download(const std::string &quality, const std::string &series_directory) { + void series::download(const std::string &quality, const std::string& base) { + if (!std::filesystem::is_directory(base + "/" + series_directory)) { + std::filesystem::create_directories(base + "/" + series_directory); + std::cout << "Creating series directory" << '\n'; + } + for (auto& season : seasons) { - season.download(quality, series_directory); + season.download(quality, base + "/" + series_directory); } } diff --git a/src/series.h b/src/series.h index 0a8abf2..16b1619 100644 --- a/src/series.h +++ b/src/series.h @@ -15,6 +15,7 @@ namespace dropout_dl { std::string name; std::string url; std::string page_data; + std::string series_directory; std::vector seasons; static std::string get_series_name(const std::string& html_data); @@ -23,7 +24,7 @@ namespace dropout_dl { static season get_season(const std::string& url, const std::vector& cookies); - void download(const std::string& quality, const std::string& series_directory); + void download(const std::string& quality, const std::string& base); explicit series(const std::string& url, const std::vector& cookies) { this->url = url; @@ -33,6 +34,11 @@ namespace dropout_dl { std::cerr << "SERIES PARSE ERROR: Could not parse series name\n"; exit(10); } + + this->series_directory = name; + std::replace(this->series_directory.begin(), this->series_directory.end(), ' ', '_'); + std::replace(this->series_directory.begin(), this->series_directory.end(), ',', '_'); + this->seasons = get_seasons(page_data, cookies); } };