Season: Changed How Episode Numbers Are Parsed For Seasons

Now episode numbers are scraped from the season page rather than counting.
This allow for specials (which dont have an episode number) to be saved
with a slightly different format.
This commit is contained in:
Moss 2023-02-07 22:21:21 -08:00
parent 3a8e904ebb
commit 286fbb969b
No known key found for this signature in database
GPG Key ID: F539D4A506C954F9
6 changed files with 50 additions and 10 deletions

View File

@ -338,7 +338,11 @@ namespace dropout_dl {
void episode::download(const std::string& quality, const std::string& series_directory, std::string filename) {
if (filename.empty()) {
if (this->episode_number != 0) {
if (this->season_number != 0) {
if (this->episode_number == -1) {
/// Episode file without season or episode number in case of special episode
filename = this->series + " - " + this->name;
}
else if (this->season_number != 0) {
filename = this->series + " - S" + ((this->season_number < 10) ? "0" : "") + std::to_string(this->season_number) + "E" + ((this->episode_number < 10) ? "0" : "") + std::to_string(this->episode_number) + " - " + this->name;
}
else {

View File

@ -36,7 +36,7 @@ namespace dropout_dl {
/// The name of the episode
std::string name;
/// The number of the episode (only set when downloading a season or series)
int episode_number = 0;
int episode_number = -1;
/// The url for the main episode page
std::string episode_url;
/// The data of the main episode page

View File

@ -5,7 +5,7 @@
#include "season.h"
namespace dropout_dl {
episode season::get_episode(const std::string& html_data, int& start_point, const std::vector<cookie>& cookies, int episode_number) {
episode season::get_episode(const std::string& html_data, int& start_point, const std::vector<cookie>& cookies) {
int link_start = 0;
for (int i = start_point; i > 0; i--) {
if (substr_is(html_data, i, "<a")) {
@ -24,6 +24,11 @@ namespace dropout_dl {
for (int j = 0; j + i < html_data.size(); j++) {
if (html_data[i + j] == '"') {
start_point += 15;
std::string episode_text = get_substring_in(html_data, R"(<span class='media-identifier media-episode'>)", "</span>", i);
int episode_number = -1;
if (!episode_text.empty()) {
episode_number = get_int_in_string(episode_text);
}
return episode(html_data.substr(i, j), cookies, this->series_name, this->name, episode_number, this->season_number, false, this->download_captions);
}
}
@ -38,14 +43,12 @@ namespace dropout_dl {
std::string site_video(R"(class="browse-item-link" data-track-event="site_video")");
int number_of_episodes = 0;
for (int i = 0; i < this->page_data.size(); i++) {
if (substr_is(this->page_data, i, site_video)) {
episode e = get_episode(this->page_data, i, cookies, number_of_episodes + 1);
episode e = get_episode(this->page_data, i, cookies);
if (e.episode_url.empty()) {
continue;
}
number_of_episodes++;
std::cout << '\t' << e.name << '\n';
out.push_back(e);
}

View File

@ -27,7 +27,7 @@ namespace dropout_dl {
/// Whether or not to download captions
bool download_captions;
episode get_episode(const std::string& html_data, int& start_point, const std::vector<cookie>& cookies, int episode_number = 0);
episode get_episode(const std::string& html_data, int& start_point, const std::vector<cookie>& cookies);
/**
*

View File

@ -281,8 +281,8 @@ namespace dropout_dl {
std::string get_substring_in(const std::string& string, const std::string& begin, const std::string& end) {
size_t substring_start = string.find(begin);
std::string get_substring_in(const std::string& string, const std::string& begin, const std::string& end, int starting_index) {
size_t substring_start = string.find(begin, starting_index);
if (substring_start == std::string::npos) {
std::cerr << "ERROR: Could not find start of substring\n";
@ -333,4 +333,26 @@ namespace dropout_dl {
return result;
}
int get_int_in_string(const std::string& string, uint32_t starting_index) {
int out = 0;
int negative = 1;
bool found_number = false;
for (uint32_t i = starting_index; i < string.length(); i++) {
if (string[i] == '-' && (string[i] <= '9' && string[i] >= '0')) {
negative = -1;
}
if (string[i] <= '9' && string[i] >= '0') {
found_number = true;
out *= 10;
out += string[i] - '0';
}
else if (found_number) {
return out * negative;
}
}
return out * negative;
}
}

View File

@ -140,7 +140,18 @@ namespace dropout_dl {
* @param end - the ending string
* @return the substring of 'string' between 'start' and 'end'
*/
std::string get_substring_in(const std::string& string, const std::string& begin, const std::string& end);
std::string get_substring_in(const std::string& string, const std::string& begin, const std::string& end, int staring_index = 0);
/**
*
* @param string - the string that contains an integer.
* @param starting_index - the index within the string to start at.
* @return the int within <b>string</b>
*
* Gets the first int in <b>string</b> after <b>starting_index</b>. The first non number character will cause the function to stop parsing the int
*/
int get_int_in_string(const std::string& string, uint32_t starting_index = 0);
/**