diff --git a/readme.md b/readme.md index 8b749e1..fc00ef2 100644 --- a/readme.md +++ b/readme.md @@ -51,7 +51,7 @@ By default, dropout-dl will download the episode in the format `/S= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9') || c == '.' || c == '/' || c == '-' || c == '_') { + out += c; + }2 + else if (c == ',' && str[i + 1] == ' ') { + out+= '-'; + i++; + } + else if (c == ',' || c == '\'' || c == ' ') { + out += '-'; + } + } + + return out; + } + #if defined(__WIN32__) #include msec_t time_ms(void) @@ -463,10 +484,7 @@ namespace dropout_dl { filename = "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(), ',', '_'); - + filename = format_filename(filename); } if (quality == "all") { @@ -504,8 +522,6 @@ namespace dropout_dl { void cookie::get_value_from_db(sqlite3 *db, const std::string &sql_query_base, const std::string& value, bool verbose, int (*callback)(void*,int,char**,char**)) { std::string sql_mod_base = sql_query_base; - verbose = true; - if (sql_mod_base.find("WHERE") == std::string::npos) { sql_mod_base += " WHERE "; } diff --git a/src/episode.h b/src/episode.h index be7b6e8..d6f3820 100644 --- a/src/episode.h +++ b/src/episode.h @@ -189,6 +189,15 @@ namespace dropout_dl { */ std::string format_name_string(const std::string& str); + /** + * + * @param str - A string + * @return str properly formatted to be a filename + * + * Removes non-alphanumeric characters and spaces + */ + std::string format_filename(const std::string& str); + #if defined(__WIN32__) #include msec_t time_ms(void); @@ -245,6 +254,8 @@ namespace dropout_dl { public: /// The name of the series that the episode belongs to std::string series; + /// The directory for the series + std::string series_directory; /// The name of the episode std::string name; /// The number of the episode in the season. This can be a number or a string @@ -405,9 +416,11 @@ namespace dropout_dl { std::cout << "Got series: " << this->series << '\n'; } - std::replace(this->series.begin(), this->series.end(), ' ', '_'); + this->series_directory = format_filename(this->series); - std::replace(this->series.begin(), this->series.end(), ',', '_'); + if (verbose) { + std::cout << "Got series directory: " << this->series_directory << '\n'; + } this->embedded_url = get_embed_url(episode_data); diff --git a/src/main.cpp b/src/main.cpp index bf1b548..1a2b17b 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -335,11 +335,9 @@ int main(int argc, char** argv) { else if (options.season) { dropout_dl::season season = dropout_dl::series::get_season(options.url, options.cookies); - std::string series_directory = season.series_name; + std::string series_directory = dropout_dl::format_filename(season.series_name); - std::replace(series_directory.begin(), series_directory.end(), ' ', '_'); - - std::replace(series_directory.begin(), series_directory.end(), ',', '_'); + std::cout << "ser: " << season.series_name << "\ndir: " << series_directory << '\n'; season.download(options.quality, options.output_directory + "/" + series_directory); } @@ -350,14 +348,18 @@ int main(int argc, char** argv) { std::cout << "filename: " << options.filename << '\n'; } - if (!std::filesystem::is_directory(ep.series)) { - std::filesystem::create_directories(ep.series); + if (!std::filesystem::is_directory(options.output_directory)) { + std::filesystem::create_directories(options.output_directory); if (options.verbose) { std::cout << "Creating series directory" << '\n'; } } - ep.download(options.quality, options.output_directory + "/" + ep.series, options.filename); + if (options.filename.empty()) { + options.filename = dropout_dl::format_filename(ep.name + ".mp4"); + } + + ep.download(options.quality, options.output_directory, options.filename); } diff --git a/src/season.cpp b/src/season.cpp index 7c17aee..d868fe1 100644 --- a/src/season.cpp +++ b/src/season.cpp @@ -45,7 +45,7 @@ namespace dropout_dl { if (e.episode_url.empty()) { continue; } - std::cout << e.episode_number << ": " << e.name << ": " << e.episode_url << '\n'; + std::cout << '\t' << e.episode_number << ": " << e.name << '\n'; out.push_back(e); } } @@ -59,11 +59,7 @@ namespace dropout_dl { std::cout << "Creating series directory" << '\n'; } - std::string dir = series_directory + "/" + this->name; - - std::replace(dir.begin(), dir.end(), ' ', '_'); - - std::replace(dir.begin(), dir.end(), ',', '_'); + std::string dir = format_filename(series_directory + "/" + this->name); for (auto& ep : episodes) { ep.download(quality, dir); diff --git a/src/season.h b/src/season.h index 1e3044b..ae0c596 100644 --- a/src/season.h +++ b/src/season.h @@ -55,7 +55,7 @@ namespace dropout_dl { this->url = url; this->name = name; this->series_name = series_name; - std::cout << series_name << ": " << name << ": " << url << "\n"; + std::cout << series_name << ": " << name << ": " << "\n"; this->page_data = get_generic_page(url); this->episodes = get_episodes(page_data, cookies); } diff --git a/src/series.h b/src/series.h index 08fb94a..3e7156a 100644 --- a/src/series.h +++ b/src/series.h @@ -81,9 +81,7 @@ namespace dropout_dl { 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->series_directory = format_filename(name); this->seasons = get_seasons(page_data, cookies); }