Quality: Added Qualities to 'episode' Object

This is done with parallel arrays. The first time the 'get_qualities' function is called it gets the
qualities and urls and places them into the 'qualities' and
'quality_urls' arrays and returns the 'qualities' array. If the function
has already run it returns the 'qualities' array. It can be forced the
re-find the qualities by clearing the 'qualities' array.
This commit is contained in:
Moss 2022-09-28 21:59:42 -04:00
parent 53bd57cd17
commit a168a642fd
2 changed files with 59 additions and 21 deletions

View File

@ -48,7 +48,7 @@ namespace dropout_dl {
long last_progress_timestamp; long last_progress_timestamp;
int curl_progress_func(void* ptr, double total_to_download, double downloaded, double total_to_upload, double uploaded) { int curl_progress_func(void* ptr, double total_to_download, double downloaded, double total_to_upload, double uploaded) {
const double number_chars = 100; const double number_chars = 50;
const char* full_character = ""; const char* full_character = "";
const char* empty_character = ""; const char* empty_character = "";
@ -413,38 +413,67 @@ namespace dropout_dl {
return config_page; return config_page;
} }
std::vector<std::string> episode::get_qualities() {
if (!qualities.empty()) {
std::string episode::get_video_url(const std::string& quality) { return qualities;
}
int i = 0; int i = 0;
bool video_section = false; bool video_section = false;
for (; i < this->config_data.size(); i++ ) {
const std::string quality_marker = R"("quality":")";
for (; i < config_data.size(); i++ ) {
// std::cout << i << "/" << javascript_data.size() << ": " << javascript_data[i] << ": " << javascript_data.substr(i, 17) << ": " << video_section << "\n"; // std::cout << i << "/" << javascript_data.size() << ": " << javascript_data[i] << ": " << javascript_data.substr(i, 17) << ": " << video_section << "\n";
if (this->config_data.substr(i, 9) == "video/mp4") { if (config_data.substr(i, 9) == "video/mp4") {
video_section = true; video_section = true;
} }
if (video_section && this->config_data.substr(i, (R"("quality":")" + quality + '"').size()) == R"("quality":")" + quality + '"') { if (video_section && config_data.substr(i, quality_marker.size()) == quality_marker) {
i += quality_marker.size();
for (int j = 0; j + i < config_data.size(); j++) {
if (config_data[i + j] == '"') {
this->qualities.push_back(config_data.substr(i, j));
if (this->verbose) {
std::cout << "Found quality (" << i << " + " << j << "): " << qualities.back() << std::endl;
}
break; break;
} }
} }
if (i == this->config_data.size()) { for (int j = i; j > 0; j--) {
std::cerr << "ERROR: quality of " << quality << " not found" << std::endl;
exit(7);
}
std::string url;
for (; i > 0; i--) {
// std::cout << i << ": " << javascript_data[i] << ": " << javascript_data.substr(i-7, 7) << "\n"; // std::cout << i << ": " << javascript_data[i] << ": " << javascript_data.substr(i-7, 7) << "\n";
if (this->config_data.substr(i-7, 7) == R"("url":")") { if (this->config_data.substr(j-7, 7) == R"("url":")") {
for (int k = 0; k < i - j; k++) {
if (config_data[j + k] == '"') {
this->quality_urls.emplace_back(config_data.substr(j, k));
if (this->verbose) {
std::cout << "Found url (" << j << " + " << k << "): " << quality_urls.back()
<< std::endl;
}
break; break;
} }
} }
break;
while (this->config_data[i] != '"') {
url += this->config_data[i++];
} }
return url; }
}
}
return qualities;
}
std::string episode::get_video_url(const std::string& quality) {
for (int i = 0; i < qualities.size(); i++) {
if (qualities[i] == quality) {
return quality_urls[i];
}
}
std::cerr << "ERROR: quality of " << quality << " not found\nPossible qualities: ";
for (int i = 0; i < qualities.size(); i++) {
std::cerr << qualities[i];
if (i != qualities.size() - 1) {
std::cerr << ", ";
}
}
exit(6);
} }
std::string episode::get_video_data(const std::string &quality) { std::string episode::get_video_data(const std::string &quality) {

View File

@ -39,6 +39,10 @@ namespace dropout_dl {
std::string config_url; std::string config_url;
std::string config_data; std::string config_data;
std::string filename; std::string filename;
std::vector<std::string> qualities;
std::vector<std::string> quality_urls;
bool verbose;
// Curl // Curl
@ -68,6 +72,8 @@ namespace dropout_dl {
static std::string get_config_url(const std::string& html_data); static std::string get_config_url(const std::string& html_data);
std::vector<std::string> get_qualities();
std::string get_video_url(const std::string& quality); std::string get_video_url(const std::string& quality);
std::string get_video_data(const std::string& quality); std::string get_video_data(const std::string& quality);
@ -75,6 +81,7 @@ namespace dropout_dl {
explicit episode(const std::string& episode_url, std::vector<std::string> cookies, bool verbose = false) { explicit episode(const std::string& episode_url, std::vector<std::string> cookies, bool verbose = false) {
this->episode_url = episode_url; this->episode_url = episode_url;
this->verbose = verbose;
episode_data = get_episode_page(episode_url, cookies[0], cookies[1]); episode_data = get_episode_page(episode_url, cookies[0], cookies[1]);
@ -140,6 +147,8 @@ namespace dropout_dl {
} }
this->config_data = get_config_page(this->config_url); this->config_data = get_config_page(this->config_url);
this->get_qualities();
} }
}; };