More relaxed search for artist images, fixes #538

This commit is contained in:
emeric
2024-10-30 18:40:51 +01:00
parent ea49b0eeb8
commit 33f4cf47ea
2 changed files with 34 additions and 17 deletions
@@ -108,27 +108,44 @@ namespace lms::scanner
releasePaths.insert(directory->getAbsolutePath());
});
// Expect layout like this:
// ReleaseArtist/Release/Tracks'
// /artist.jpg
// /someOtherUserConfiguredArtistFile.jpg
if (!releasePaths.empty())
{
const std::filesystem::path artistPath{ releasePaths.size() == 1 ? releasePaths.begin()->parent_path() : core::pathUtils::getLongestCommonPath(std::cbegin(releasePaths), std::cend(releasePaths)) };
image = findImageInDirectory(searchContext, artistPath);
}
if (!image)
{
// Expect layout like this:
// ReleaseArtist/Release/Tracks'
// /artist.jpg
// /someOtherUserConfiguredArtistFile.jpg
for (const std::filesystem::path& releasePath : releasePaths)
// /artist.jpg
// /someOtherUserConfiguredArtistFile.jpg
//
// Or:
// ReleaseArtist/SomeGrouping/Release/Tracks'
// /artist.jpg
// /someOtherUserConfiguredArtistFile.jpg
//
std::filesystem::path directoryToInspect{ core::pathUtils::getLongestCommonPath(std::cbegin(releasePaths), std::cend(releasePaths)) };
while (true)
{
image = findImageInDirectory(searchContext, releasePath);
image = findImageInDirectory(searchContext, directoryToInspect);
if (image)
break;
std::filesystem::path parentPath{ directoryToInspect.parent_path() };
if (parentPath == directoryToInspect)
break;
directoryToInspect = parentPath;
}
if (!image)
{
// Expect layout like this:
// ReleaseArtist/Release/Tracks'
// /artist.jpg
// /someOtherUserConfiguredArtistFile.jpg
for (const std::filesystem::path& releasePath : releasePaths)
{
image = findImageInDirectory(searchContext, releasePath);
if (image)
break;
}
}
}
}
@@ -119,7 +119,7 @@ namespace lms::scanner
// and still belongs to a media directory
if (!std::filesystem::exists(p) || !std::filesystem::is_regular_file(p))
{
LMS_LOG(DBUPDATER, INFO, "Removing '" << p.string() << "': missing");
LMS_LOG(DBUPDATER, DEBUG, "Removing '" << p.string() << "': missing");
return false;
}
@@ -128,13 +128,13 @@ namespace lms::scanner
return core::pathUtils::isPathInRootPath(p, libraryInfo.rootDirectory, &excludeDirFileName);
}))
{
LMS_LOG(DBUPDATER, INFO, "Removing '" << p.string() << "': out of media directory");
LMS_LOG(DBUPDATER, DEBUG, "Removing '" << p.string() << "': out of media directory");
return false;
}
if (!core::pathUtils::hasFileAnyExtension(p, allowedExtensions))
{
LMS_LOG(DBUPDATER, INFO, "Removing '" << p.string() << "': file format no longer handled");
LMS_LOG(DBUPDATER, DEBUG, "Removing '" << p.string() << "': file format no longer handled");
return false;
}