Fully working album download
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user