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
+2
View File
@@ -19,6 +19,8 @@ target_include_directories(YTMusicDL26 PUBLIC
include(cmake/CPM.cmake)
set(CURL_USE_LIBPSL OFF CACHE BOOL "" FORCE)
CPMAddPackage("gh:nlohmann/json#v3.12.0")
CPMAddPackage("gh:curl/curl#curl-8_21_0")
Binary file not shown.
BIN
View File
Binary file not shown.
+6
View File
@@ -5,6 +5,12 @@
#ifdef _WIN32
#define BIN_FOLDER "bin/windows"
#define BIN_YT_DLP "bin/windows/yt-dlp.exe"
#define BIN_FFMPEG "bin/windows/ffmpeg.exe"
#define BIN_DENO "bin/windows/deno.exe"
#else
#define BIN_FOLDER "bin/linux"
#define BIN_YT_DLP "bin/linux/yt-dlp"
#define BIN_FFMPEG "bin/linux/ffmpeg"
#define BIN_DENO "bin/linux/deno"
#endif
+6 -6
View File
@@ -100,11 +100,11 @@ auto Playlist::writeMetadata(const json& data) -> bool {
size_t index = 1;
for (const auto& entry : std::filesystem::directory_iterator(TMP_DOWNLOAD_FOLDER)) {
if (std::filesystem::path(entry.path()).filename().string() == "cover.jpg") continue;
if (std::filesystem::path(entry.path().string()).filename().string() == "cover.jpg") continue;
metadata(entry.path(), artist, album, index);
printf("Finished writting metadata for %s.\n", entry.path().c_str());
std::filesystem::remove(entry.path());
metadata(entry.path().string(), artist, album, index);
printf("Finished writting metadata for %s.\n", entry.path().string().c_str());
std::filesystem::remove(entry.path().string());
index++;
}
@@ -130,12 +130,12 @@ auto Playlist::urlsFromPlaylist(const std::string& url) -> std::vector<std::stri
std::filesystem::remove(urlsFileLocation);
ytdlp(
std::format("--js-runtimes \"deno:{}/deno\" "
std::format("--js-runtimes \"deno:{}\" "
"--quiet "
"--flat-playlist "
"--print-to-file \"%(webpage_url)s\" "
"{} \"{}\"",
BIN_FOLDER, urlsFileLocation, url));
BIN_DENO, urlsFileLocation, url));
std::ifstream f(urlsFileLocation);
if (!f.is_open()) {
+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";
+1 -1
View File
@@ -8,7 +8,7 @@ auto metadata(const std::string& file, const std::string& artist, const std::str
auto cleanTmpDownloadFolder() -> bool;
auto downloadImageToTmpFolder(const std::string& url) -> bool;
auto downloadImageToTmpFolder(std::string url) -> bool;
auto downloadVideo(const std::string& url) -> bool;
+4 -4
View File
@@ -82,11 +82,11 @@ auto Video::writeMetadata(const nlohmann::json& data) -> bool {
size_t index = 1;
for (const auto& entry : std::filesystem::directory_iterator(TMP_DOWNLOAD_FOLDER)) {
if (std::filesystem::path(entry.path()).filename().string() == "cover.jpg") continue;
if (std::filesystem::path(entry.path().string()).filename().string() == "cover.jpg") continue;
metadata(entry.path(), artist, album, index);
printf("Finished writting metadata for %s.\n", entry.path().c_str());
std::filesystem::remove(entry.path());
metadata(entry.path().string(), artist, album, index);
printf("Finished writting metadata for %s.\n", entry.path().string().c_str());
std::filesystem::remove(entry.path().string());
index++;
}
+6
View File
@@ -0,0 +1,6 @@
mkdir build
cd build
cmake -DCMAKE_TOOLCHAIN_FILE=~/TC-mingw.cmake -GNinja ..
ninja
wine YTMusicDL26.exe
cd ..