Fixed album covers

This commit is contained in:
2026-08-21 12:42:06 -06:00
parent fe6dc020ca
commit aed13dc18f
5 changed files with 45 additions and 63 deletions
+22 -4
View File
@@ -39,9 +39,8 @@ auto metadata(const std::string& file, const std::string& artist, const std::str
"-metadata artist=\"{}\" "
"-metadata album=\"{}\" "
"-metadata track=\"{}\" "
"\"{}/{}_{}.mp3\"",
BIN_FFMPEG, file, TMP_DOWNLOAD_FOLDER, name, artist, album, index, TMP_DOWNLOAD_FOLDER, index,
name)
"\"{}/_{}.mp3\"",
BIN_FFMPEG, file, TMP_DOWNLOAD_FOLDER, name, artist, album, index, TMP_DOWNLOAD_FOLDER, name)
.c_str());
}
@@ -54,13 +53,16 @@ auto cleanTmpDownloadFolder() -> bool {
}
auto downloadImageToTmpFolder(std::string url) -> bool {
printf("Downloading image with url %s\n", url.c_str());
CURL* curl = curl_easy_init();
if (!curl) {
printf("ERROR: Failed to initialize curl.\n");
return false;
}
url = std::regex_replace(url, std::regex("https"), "http");
// TODO Breaks album covers but this is needed for windows
// 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) {
@@ -164,3 +166,19 @@ auto musicFolder() -> std::string {
return "";
}
auto writeMetadataToTmpFolder(const std::string& artist, const std::string& album, const std::string& coverUrl)
-> void {
downloadImageToTmpFolder(coverUrl);
size_t index = 1;
for (const auto& entry : std::filesystem::directory_iterator(TMP_DOWNLOAD_FOLDER)) {
if (std::filesystem::path(entry.path().string()).filename().string() == "cover.jpg") continue;
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());
// TODO rename without underscore
index++;
}
}