Episode: Added Check For Already Downloaded Episode
This commit is contained in:
parent
d7a3f53f03
commit
24adf6446b
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// Created by moss on 12/24/22.
|
||||
//
|
||||
|
||||
#pragma once
|
||||
|
||||
#define RESET "\033[0m"
|
||||
#define BLACK "\033[30m" /* Black */
|
||||
#define RED "\033[31m" /* Red */
|
||||
#define GREEN "\033[32m" /* Green */
|
||||
#define YELLOW "\033[33m" /* Yellow */
|
||||
#define BLUE "\033[34m" /* Blue */
|
||||
#define MAGENTA "\033[35m" /* Magenta */
|
||||
#define CYAN "\033[36m" /* Cyan */
|
||||
#define WHITE "\033[37m" /* White */
|
||||
#define BOLDBLACK "\033[1m\033[30m" /* Bold Black */
|
||||
#define BOLDRED "\033[1m\033[31m" /* Bold Red */
|
||||
#define FAIL "\033[31mFAIL: \033[0m" // Test Failure
|
||||
#define BOLDFAIL "\033[1m\033[31mFAIL: \033[0m" // Test Failure
|
||||
#define BOLDGREEN "\033[1m\033[32m" /* Bold Green */
|
||||
#define SUCCESS "\033[32mSUCCESS: \033[0m" /* Test Success */
|
||||
#define BOLDSUCCESS "\033[1m\033[32mSUCCESS: \033[0m" /* Test Success */
|
||||
#define BOLDYELLOW "\033[1m\033[33m" /* Bold Yellow */
|
||||
#define WARN "\033[1m\033[33mWARNING: \033[0m" /* Test Warning */
|
||||
#define BOLDBLUE "\033[1m\033[34m" /* Bold Blue */
|
||||
#define TESTNAME "\033[1m\033[34mTEST: \033[0m" /* Bold Blue */
|
||||
#define BOLDMAGENTA "\033[1m\033[35m" /* Bold Magenta */
|
||||
#define BOLDCYAN "\033[1m\033[36m" /* Bold Cyan */
|
||||
#define BOLDWHITE "\033[1m\033[37m" /* Bold White */
|
|
@ -265,7 +265,6 @@ namespace dropout_dl {
|
|||
// Skip "VIDEO_TITLE", the following colon, and the opening quotation mark.
|
||||
i += video_title_title.size() + 2;
|
||||
|
||||
|
||||
int j;
|
||||
for (j = 0; meta_data[i + j] != '"' && i + j < meta_data.size(); j++) {
|
||||
// skip checking for quotes if prefaced by a forward slash
|
||||
|
@ -518,6 +517,31 @@ namespace dropout_dl {
|
|||
}
|
||||
|
||||
|
||||
void episode::download_quality(const std::string& quality, const std::string& base_directory, const std::string& filename) {
|
||||
if (!std::filesystem::is_directory(base_directory)) {
|
||||
std::filesystem::create_directories(base_directory);
|
||||
if (this->verbose) {
|
||||
std::cout << "Creating quality directory" << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
std::string filepath = base_directory + "/" + filename;
|
||||
|
||||
if(std::filesystem::is_regular_file(filepath)) {
|
||||
std::cout << YELLOW << "File already exists: " << filepath << RESET << '\n';
|
||||
return;
|
||||
}
|
||||
std::fstream out(filepath,
|
||||
std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
|
||||
|
||||
out << this->get_video_data(quality, filepath) << std::endl;
|
||||
|
||||
std::cout << GREEN << filepath << RESET;
|
||||
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
|
||||
void episode::download(const std::string& quality, const std::string& series_directory, std::string filename) {
|
||||
if (filename.empty()) {
|
||||
if (this->episode_number != 0) {
|
||||
|
@ -537,32 +561,12 @@ namespace dropout_dl {
|
|||
|
||||
if (quality == "all") {
|
||||
for (const auto &possible_quality: this->qualities) {
|
||||
if (!std::filesystem::is_directory(series_directory + "/" + possible_quality)) {
|
||||
std::filesystem::create_directories(series_directory + "/" + possible_quality);
|
||||
if (this->verbose) {
|
||||
std::cout << "Creating quality directory" << '\n';
|
||||
}
|
||||
}
|
||||
std::fstream out(series_directory + "/" + possible_quality + "/" + filename,
|
||||
std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
|
||||
|
||||
out << this->get_video_data(possible_quality, series_directory + "/" + possible_quality + "/" + filename) << std::endl;
|
||||
this->download_quality(possible_quality, series_directory + possible_quality, filename);
|
||||
}
|
||||
} else {
|
||||
if (!std::filesystem::is_directory(series_directory)) {
|
||||
std::filesystem::create_directories(series_directory);
|
||||
if (this->verbose) {
|
||||
std::cout << "Creating quality directory" << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
std::fstream out(series_directory + "/" + filename,
|
||||
std::ios_base::in | std::ios_base::out | std::ios_base::trunc);
|
||||
|
||||
out << this->get_video_data(quality, series_directory + "/" + filename) << std::endl;
|
||||
this->download_quality(quality, series_directory, filename);
|
||||
}
|
||||
|
||||
std::cout << '\n';
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <filesystem>
|
||||
#include "color.h"
|
||||
#include <sqlite3.h>
|
||||
#ifdef DROPOUT_DL_GCRYPT
|
||||
#include <gcrypt.h>
|
||||
|
@ -259,13 +260,13 @@ namespace dropout_dl {
|
|||
/// The name of the season that the episode belongs to
|
||||
std::string season;
|
||||
/// The number of the season (only set when downloading a season or series)
|
||||
int season_number;
|
||||
int season_number = 0;
|
||||
/// The json metadata of the episode
|
||||
std::string metadata;
|
||||
/// The name of the episode
|
||||
std::string name;
|
||||
/// The number of the episode (only set when downloading a season or series)
|
||||
int episode_number;
|
||||
int episode_number = 0;
|
||||
/// The url for the main episode page
|
||||
std::string episode_url;
|
||||
/// The data of the main episode page
|
||||
|
@ -382,6 +383,18 @@ namespace dropout_dl {
|
|||
*/
|
||||
std::string get_video_data(const std::string& quality, const std::string& filename = "");
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param quality - The quality of the video
|
||||
* @param base_directory - The directory which the episode is downloaded into
|
||||
* @param filename - The name of the file (Will default if empty)
|
||||
*
|
||||
* Downloads the episode using the get_video_data function and places it into the <b>filename</b> file in the <b>base_directory</b> directory.
|
||||
* If the file already exists it will output the name in yellow and will not redownload.
|
||||
*/
|
||||
void download_quality(const std::string& quality, const std::string& base_directory, const std::string& filename);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param quality - The quality of the video
|
||||
|
|
Loading…
Reference in New Issue