From 2ade05b1757ef098c93e7e67b04f2a5a2e32d086 Mon Sep 17 00:00:00 2001 From: Moss Date: Tue, 7 Feb 2023 21:31:40 -0800 Subject: [PATCH] Series: Fixed Passing Series Name to Season --- src/series.cpp | 32 ++++++++++++++++---------------- src/series.h | 14 +++++++++----- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/series.cpp b/src/series.cpp index 28ee2e8..2f51c85 100644 --- a/src/series.cpp +++ b/src/series.cpp @@ -28,7 +28,7 @@ namespace dropout_dl { return "ERROR"; } - std::vector series::get_seasons(const std::string &html_data, const std::vector& cookies) { + std::vector series::get_seasons(const std::vector& cookies) { std::vector out; std::string search_class("js-switch-season"); @@ -43,35 +43,35 @@ namespace dropout_dl { bool seasons_dropdown = false; std::string season_url; std::string season_name; - for (int i = 0; i < html_data.size(); i++) { - if (substr_is(html_data, i, open_select)) { - for (int j = i; j < html_data.size(); j++) { - if (substr_is(html_data, j, search_class)) { + for (int i = 0; i < this->page_data.size(); i++) { + if (substr_is(this->page_data, i, open_select)) { + for (int j = i; j < this->page_data.size(); j++) { + if (substr_is(this->page_data, j, search_class)) { i = j; seasons_dropdown = true; break; } - else if (substr_is(html_data, j, close_tag)) { + else if (substr_is(this->page_data, j, close_tag)) { break; } } } if (seasons_dropdown) { - if (substr_is(html_data, i, value)) { + if (substr_is(this->page_data, i, value)) { i += value.size() + 1; - for (int j = 0; j + i < html_data.size(); j++) { - if (html_data[i + j] == '"') { - season_url = html_data.substr(i, j); + for (int j = 0; j + i < this->page_data.size(); j++) { + if (this->page_data[i + j] == '"') { + season_url = this->page_data.substr(i, j); i += j; break; } } } - else if (!season_url.empty() && substr_is(html_data, i, close_tag)) { + else if (!season_url.empty() && substr_is(this->page_data, i, close_tag)) { i += close_tag.size() + 1; - for (int j = 0; i + j < html_data.size(); j++) { - if (html_data[i + j] == '\n') { - season_name = html_data.substr(i, j); + for (int j = 0; i + j < this->page_data.size(); j++) { + if (this->page_data[i + j] == '\n') { + season_name = this->page_data.substr(i, j); // Remove leading and trailing whitespace bool leading_whitespace = true; @@ -91,7 +91,7 @@ namespace dropout_dl { } season_name = season_name.substr(name_start, season_name.size() - name_start - name_end); - out.emplace_back(season_url, season_name, cookies); + out.emplace_back(season_url, season_name, cookies, this->name, this->download_captions); std::cout << out.back().name << ": " << out.back().url << '\n'; @@ -105,7 +105,7 @@ namespace dropout_dl { } } - if (substr_is(html_data, i, close_select)) { + if (substr_is(this->page_data, i, close_select)) { break; } } diff --git a/src/series.h b/src/series.h index ecdbc11..3495613 100644 --- a/src/series.h +++ b/src/series.h @@ -24,6 +24,10 @@ namespace dropout_dl { std::string series_directory; /// A vector containing all the season that this series include std::vector seasons; + /// A vector containing the cookies needed to download episodes + std::vector cookies; + /// Whether or not to download captions + bool download_captions; /** * @@ -36,15 +40,13 @@ namespace dropout_dl { /** * - * @param html_data - The series page data * @param cookies - The cookies from a browser - * @return A list of all seasons in the series * * Scrapes the series page for the names and link of all the season. Creates season objects for each of these. * These season object contain all the episodes of the season as episode objects. * The cookies this function takes are passed to the episode objects. */ - static std::vector get_seasons(const std::string& html_data, const std::vector& cookies); + std::vector get_seasons(const std::vector& cookies); /** * @@ -72,10 +74,12 @@ namespace dropout_dl { * * Creates a series object and populates the needed variables */ - explicit series(const std::string& url, const std::vector& cookies) { + series(const std::string& url, const std::vector& cookies, bool download_captions = false) { this->url = url; + this->download_captions = download_captions; this->page_data = get_generic_page(url); this->name = get_series_name(page_data); + this->cookies = cookies; if (name == "ERROR") { std::cerr << "SERIES PARSE ERROR: Could not parse series name\n"; exit(10); @@ -83,7 +87,7 @@ namespace dropout_dl { this->series_directory = format_filename(name); - this->seasons = get_seasons(page_data, cookies); + this->seasons = this->get_seasons(cookies); } };