diff --git a/CMakeLists.txt b/CMakeLists.txt index 345117c..7e20147 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") diff --git a/bin/windows/deno.exe b/bin/windows/deno.exe new file mode 100644 index 0000000..bcd73db Binary files /dev/null and b/bin/windows/deno.exe differ diff --git a/bin/windows/ffmpeg.exe b/bin/windows/ffmpeg.exe new file mode 100755 index 0000000..1c2f2d5 Binary files /dev/null and b/bin/windows/ffmpeg.exe differ diff --git a/src/config.hpp b/src/config.hpp index 995f774..27fda22 100644 --- a/src/config.hpp +++ b/src/config.hpp @@ -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 diff --git a/src/playlist.cpp b/src/playlist.cpp index c10d8e0..6ed07f4 100644 --- a/src/playlist.cpp +++ b/src/playlist.cpp @@ -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 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"; diff --git a/src/utils.hpp b/src/utils.hpp index 86ada8c..34743fb 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -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; diff --git a/src/video.cpp b/src/video.cpp index dddcebd..62eab37 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -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++; } diff --git a/winrun.sh b/winrun.sh new file mode 100644 index 0000000..8f54b1c --- /dev/null +++ b/winrun.sh @@ -0,0 +1,6 @@ +mkdir build +cd build +cmake -DCMAKE_TOOLCHAIN_FILE=~/TC-mingw.cmake -GNinja .. +ninja +wine YTMusicDL26.exe +cd ..