Skip to content

Commit

Permalink
there were still some filesname cases unhandled, so regex it is
Browse files Browse the repository at this point in the history
  • Loading branch information
SenpaiSimon committed Jan 6, 2025
1 parent c8803c3 commit a5095f1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#define DEFAULT_VIDEO_FILE_NAME "/%(title)s [%(id)s].%(ext)s"

#define DEFAULT_VIDEO_PLAYLIST_PATH_PATTERN "/%(uploader)s/%(playlist_title)s [youtube-%(playlist_id)s]"
#define JELLY_VIDEO_PLAYLIST_PATH_PATTERN(folder) "/" + folder
#define JELLY_VIDEO_PLAYLIST_PATH_PATTERN(folder) folder
#define DEFAULT_VIDEO_PLAYLIST_FILE_NAME(id) "/%(title)s - S" + id + "E%(playlist_index)s [%(id)s].%(ext)s"
#define JELLY_VIDEO_PLAYLIST_FILE_NAME "/E%(playlist_index)s - %(title)s [%(id)s].%(ext)s"

Expand Down
1 change: 1 addition & 0 deletions include/downloader/postProcess.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class postProcess {
nfoInfo_t scrapePath(fs::path path, bool episode);
void createNfo(fs::path path, nfoInfo_t nfo, bool episode);
std::string reformatDate(const std::string& date);
bool isPlaylistMeta(fs::path path);

public:
postProcess(settings setting);
Expand Down
2 changes: 1 addition & 1 deletion src/downloader/downloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void downloader::start() {
outputPath = conf["videoPath"];
if(setting.jellyfin) {
fs::path jellyPath = setting.playlistPath;
tempPath = string(conf["tempPath"]) + JELLY_VIDEO_PLAYLIST_PATH_PATTERN(jellyPath.filename().string());
tempPath = string(conf["tempPath"]) + "/" + JELLY_VIDEO_PLAYLIST_PATH_PATTERN(jellyPath.filename().string());
tempOutFile = tempPath + JELLY_VIDEO_PLAYLIST_FILE_NAME;
} else {
tempPath = string(conf["tempPath"]) + DEFAULT_VIDEO_PLAYLIST_PATH_PATTERN;
Expand Down
11 changes: 9 additions & 2 deletions src/downloader/postProcess.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ postProcess::postProcess(settings setting) {
this->setting = setting;
}

bool postProcess::isPlaylistMeta(fs::path path) {
string filename = path.filename().string();
return filename.rfind("E0 - ", 0) == 0 ||
filename.rfind("E00 - ", 0) == 0 ||
filename.rfind("E000 - ", 0) == 0;
}

void postProcess::convert() {
vector<fs::path> images;
vector<fs::path> infoJson;
Expand All @@ -14,7 +21,7 @@ void postProcess::convert() {
for (const auto& entry : std::filesystem::directory_iterator(setting.playlistPath)) {
// episode info json
if(entry.path().extension() == ".json") {
if(entry.path().filename().string().find("E0 - ") != std::string::npos) {
if(this->isPlaylistMeta(entry.path())) {
playlistInfo = entry.path();
} else {
infoJson.push_back(entry.path());
Expand All @@ -26,7 +33,7 @@ void postProcess::convert() {
entry.path().extension() == ".webp" || \
entry.path().extension() == ".png") {
// we dont want E0 image since it has bad quality
if(entry.path().filename().string().find("E0 - ") == std::string::npos) {
if(!this->isPlaylistMeta(entry.path())) {
images.push_back(entry.path());
}
}
Expand Down
8 changes: 6 additions & 2 deletions src/idExtractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,12 @@ void idExtractor::extractData() {
if(setting->mediaType == "videoPlaylist") {
// this path is without a ending slash /
if(setting->jellyfin) {
playlistPath = string(conf["videoPath"]) + \
tools::executeCommand(YT_DLP_PARSE_PATH(JELLY_VIDEO_PLAYLIST_PATH_PATTERN("%(playlist_title)s"), setting->dlUrl));
string tempScraperPath = tools::executeCommand(YT_DLP_PARSE_PATH(JELLY_VIDEO_PLAYLIST_PATH_PATTERN("%(playlist_title)s"), setting->dlUrl));
// replace all the stupid characters peopple type in their names
std::regex rgx("[^a-zA-Z0-9]");
tempScraperPath = std::regex_replace(tempScraperPath, rgx, "_");

playlistPath = string(conf["videoPath"]) + "/" + tempScraperPath;
channelPath = playlistPath;
} else {
playlistPath = string(conf["videoPath"]) + \
Expand Down

0 comments on commit a5095f1

Please sign in to comment.