Skip to content

Commit

Permalink
Episode: Added Redundancy Check for Episode Number
Browse files Browse the repository at this point in the history
This fixes an issue with ch-shorts where the second page's episode
numbers are reset to start with one. Not sure why the dropout.tv website
is so inconsistent but whatever. This fixes the second issue of issue #4.
  • Loading branch information
mosswg committed Jun 19, 2023
1 parent 12561e6 commit 6014531
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/episode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ namespace dropout_dl {
return "ERROR";
}

int episode::get_episode_number(const std::string& page_data, int season_number) {
std::string open_string = "Season " + std::to_string(season_number) + ", Episode ";
std::string close_string = "\n";

std::string episode_num_str = get_substring_in(page_data, open_string, close_string, 0);

int episode_number = -1;
if (!episode_num_str.empty()) {
episode_number = get_int_in_string(episode_num_str);
}

return episode_number;
}

std::string episode::get_season_name(const std::string& meta_data) {
std::string season_title_title("\"COLLECTION_TITLE\"");
for (int i = 0; i < meta_data.size(); i++) {
Expand Down
25 changes: 23 additions & 2 deletions src/episode.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,16 @@ namespace dropout_dl {
*/
static std::string get_season_name(const std::string& meta_data);


/**
*
* @param page_data - Episode page data
* @return The episode number
*
* Get the number of the season from the metadata
*/
static int get_episode_number(const std::string& page_data, int season_number);

/**
*
* @param meta_data - Episode metadata in json format
Expand Down Expand Up @@ -240,7 +250,18 @@ namespace dropout_dl {

this->season = season;

this->episode_number = episode_number;
int episode_number_from_page = get_episode_number(episode_data, season_number);
if (episode_number_from_page != -1) {
this->episode_number = episode_number_from_page;
}
else {
this->episode_number = episode_number;
}
if (episode_number_from_page != episode_number) {
if (verbose) {
std::cout << "WARNING: episode number from season page (" << episode_number << ") and episode page (" << episode_number_from_page << ") do not match. Using " << this->episode_number << " if this is correct please ignore this warning\n";
}
}

this->season_number = season_number;

Expand Down Expand Up @@ -281,7 +302,7 @@ namespace dropout_dl {
}

this->get_qualities();
}
}

/**
*
Expand Down

0 comments on commit 6014531

Please sign in to comment.