Fully working album download

This commit is contained in:
2026-08-20 11:02:06 -06:00
parent a33cab8326
commit ee378b19a3
5 changed files with 97 additions and 66 deletions
+38
View File
@@ -6,12 +6,15 @@
#include <cstdlib>
#include <filesystem>
#include <format>
#include <fstream>
#include <nlohmann/json.hpp>
#include <regex>
#include <string>
#include "config.hpp"
using json = nlohmann::json;
// This runs in shell, if put through a website interface it would allow for injection
auto ytdlp(const std::string& args) -> bool {
system(std::format("bin/linux/yt-dlp {}", args).c_str());
@@ -97,3 +100,38 @@ auto downloadVideo(const std::string& url) -> bool {
printf("Finished downloading video %s.\n", url.c_str());
return true;
}
auto writeAndReturnDataJson(const std::string& url) -> json {
std::filesystem::remove("tmp/data.json");
ytdlp(
std::format("--js-runtimes \"deno:bin/linux/deno\" "
"--dump-single-json "
"\"{}\" "
"> tmp/data.json",
url));
std::ifstream f("tmp/data.json");
if (!f) {
printf("ERROR: Couldn't open data.json\n");
return false;
}
return json::parse(f);
}
auto moveAndSortTmpFilesToFolder(const std::string& folder, const std::string& artist, const std::string& album)
-> bool {
std::filesystem::path folderPath(folder);
std::filesystem::path path = folderPath / artist / album;
std::filesystem::create_directories(path);
for (const auto& entry : std::filesystem::directory_iterator(path)) {
std::filesystem::remove_all(entry.path());
}
for (const auto& entry : std::filesystem::directory_iterator(TMP_DOWNLOAD_FOLDER)) {
std::filesystem::rename(entry, path / entry.path().filename());
}
return true;
}