Working on windows

This commit is contained in:
2026-08-20 12:39:26 -06:00
parent 4fc7457052
commit 8001311b52
9 changed files with 39 additions and 23 deletions
+14 -12
View File
@@ -19,7 +19,7 @@ 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("{}/yt-dlp {}", BIN_FOLDER, args).c_str());
system(std::format("{} {}", BIN_YT_DLP, args).c_str());
return true;
}
@@ -27,7 +27,7 @@ auto metadata(const std::string& file, const std::string& artist, const std::str
std::string name = std::filesystem::path(file).filename().string();
name = std::regex_replace(name, std::regex(".mp3"), "");
system(std::format("{}/ffmpeg "
system(std::format("{} "
"-hide_banner -loglevel error "
"-i \"{}\" "
"-i \"{}/cover.jpg\" "
@@ -40,27 +40,29 @@ auto metadata(const std::string& file, const std::string& artist, const std::str
"-metadata album=\"{}\" "
"-metadata track=\"{}\" "
"\"{}/{}_{}.mp3\"",
BIN_FOLDER, file, TMP_DOWNLOAD_FOLDER, name, artist, album, index, TMP_DOWNLOAD_FOLDER, index,
BIN_FFMPEG, file, TMP_DOWNLOAD_FOLDER, name, artist, album, index, TMP_DOWNLOAD_FOLDER, index,
name)
.c_str());
}
auto cleanTmpDownloadFolder() -> bool {
for (const auto& entry : std::filesystem::directory_iterator(TMP_DOWNLOAD_FOLDER)) {
std::filesystem::remove_all(entry.path());
std::filesystem::remove_all(entry.path().string());
}
return true;
}
auto downloadImageToTmpFolder(const std::string& url) -> bool {
auto downloadImageToTmpFolder(std::string url) -> bool {
CURL* curl = curl_easy_init();
if (!curl) {
printf("ERROR: Failed to initialize curl.\n");
return false;
}
FILE* file = std::fopen(std::format("{}/cover.jpg", TMP_DOWNLOAD_FOLDER).c_str(), "wb");
url = std::regex_replace(url, std::regex("https"), "http");
auto outputPath = std::filesystem::path(TMP_DOWNLOAD_FOLDER) / "cover.jpg";
FILE* file = std::fopen(outputPath.string().c_str(), "wb");
if (!file) {
curl_easy_cleanup(curl);
printf("ERROR: Failed to create cover file.\n");
@@ -92,13 +94,13 @@ auto downloadVideo(const std::string& url) -> bool {
}
ytdlp(
std::format("--js-runtimes \"deno:{}/deno\" "
std::format("--js-runtimes \"deno:{}\" "
"--quiet "
"-f \"bestaudio/best\" "
"-x --audio-format mp3 "
"-o \"{}/%(title)s.%(ext)s\" "
"{}",
BIN_FOLDER, TMP_DOWNLOAD_FOLDER, url));
BIN_DENO, TMP_DOWNLOAD_FOLDER, url));
printf("Finished downloading video %s.\n", url.c_str());
return true;
@@ -107,11 +109,11 @@ auto downloadVideo(const std::string& url) -> bool {
auto writeAndReturnDataJson(const std::string& url) -> json {
std::filesystem::remove("tmp/data.json");
ytdlp(
std::format("--js-runtimes \"deno:{}/deno\" "
std::format("--js-runtimes \"deno:{}\" "
"--dump-single-json "
"\"{}\" "
"> tmp/data.json",
BIN_FOLDER, url));
BIN_DENO, url));
std::ifstream f("tmp/data.json");
if (!f) {
@@ -129,7 +131,7 @@ auto moveAndSortTmpFilesToFolder(const std::string& folder, const std::string& a
std::filesystem::create_directories(path);
for (const auto& entry : std::filesystem::directory_iterator(path)) {
std::filesystem::remove_all(entry.path());
std::filesystem::remove_all(entry.path().string());
}
for (const auto& entry : std::filesystem::directory_iterator(TMP_DOWNLOAD_FOLDER)) {
@@ -154,7 +156,7 @@ auto autoDetermineRip(const std::string& musicFolder, const std::string& url) ->
auto musicFolder() -> std::string {
#ifdef _WIN32
const char* userProfile = std::getenv("USERPROFILE");
if (userProfile) return std::filesystem::path(userProfile) / "Music";
if (userProfile) return std::format("{}/Music", userProfile);
#else
const char* home = std::getenv("HOME");
if (home) return std::filesystem::path(home) / "Music";