mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-04-10 19:15:13 +00:00
Fixed an issue where the scraper would sometimes consider very small images to be invalid.
This commit is contained in:
parent
4132553c55
commit
8b91905e9e
|
@ -259,15 +259,27 @@ MDResolveHandle::MDResolveHandle(const ScraperSearchResult& result,
|
||||||
// This is just a temporary workaround to avoid saving media files to disk that
|
// This is just a temporary workaround to avoid saving media files to disk that
|
||||||
// are actually just containing error messages from the scraper service. The
|
// are actually just containing error messages from the scraper service. The
|
||||||
// proper solution is to implement file checksum checks to determine if the
|
// proper solution is to implement file checksum checks to determine if the
|
||||||
// server response contains valid media. The problem with this temporary
|
// server response contains valid media. As for the current approach, if the
|
||||||
// solution is of course that any tiny media files of less than 300 bytes
|
// file is less than 350 bytes, we check if FreeImage can actually detect a
|
||||||
// will not be saved to disk.
|
// valid format, and if not, we present an error message. Black/empty images
|
||||||
|
// are sometimes returned from the scraper service and these can actually be
|
||||||
|
// less than 350 bytes in size.
|
||||||
if (Settings::getInstance()->getBool("ScraperHaltOnInvalidMedia") &&
|
if (Settings::getInstance()->getBool("ScraperHaltOnInvalidMedia") &&
|
||||||
mResult.thumbnailImageData.size() < 350) {
|
mResult.thumbnailImageData.size() < 350) {
|
||||||
setError("The file \"" + Utils::FileSystem::getFileName(filePath) +
|
|
||||||
"\" returned by the scraper seems to be invalid as it's less than " +
|
FIMEMORY* memoryStream = FreeImage_OpenMemory(
|
||||||
"350 bytes in size");
|
reinterpret_cast<BYTE*>(&mResult.thumbnailImageData.at(0)),
|
||||||
return;
|
mResult.thumbnailImageData.size());
|
||||||
|
|
||||||
|
FREE_IMAGE_FORMAT imageFormat = FreeImage_GetFileTypeFromMemory(memoryStream, 0);
|
||||||
|
FreeImage_CloseMemory(memoryStream);
|
||||||
|
|
||||||
|
if (imageFormat == FIF_UNKNOWN) {
|
||||||
|
setError("The file \"" + Utils::FileSystem::getFileName(filePath) +
|
||||||
|
"\" returned by the scraper seems to be invalid as it's less than " +
|
||||||
|
"350 bytes in size");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any existing media file before attempting to write a new one.
|
// Remove any existing media file before attempting to write a new one.
|
||||||
|
@ -401,17 +413,34 @@ void MediaDownloadHandle::update()
|
||||||
|
|
||||||
// Download is done, save it to disk.
|
// Download is done, save it to disk.
|
||||||
|
|
||||||
// This is just a temporary workaround to avoid saving media files to disk that
|
// This is just a temporary workaround to avoid saving media files to disk that are
|
||||||
// are actually just containing error messages from the scraper service. The
|
// actually just containing error messages from the scraper service. The proper solution
|
||||||
// proper solution is to implement file checksum checks to determine if the
|
// is to implement file checksum checks to determine if the server response contains valid
|
||||||
// server response contains valid media. The problem with this temporary
|
// media. As for the current approach, if the file is less than 350 bytes, we check if
|
||||||
// solution is of course that any tiny media files of less than 300 bytes
|
// FreeImage can actually detect a valid format, and if not, we present an error message.
|
||||||
// will not be saved to disk.
|
// Black/empty images are sometimes returned from the scraper service and these can actually
|
||||||
|
// be less than 350 bytes in size.
|
||||||
if (Settings::getInstance()->getBool("ScraperHaltOnInvalidMedia") &&
|
if (Settings::getInstance()->getBool("ScraperHaltOnInvalidMedia") &&
|
||||||
mReq->getContent().size() < 350) {
|
mReq->getContent().size() < 350) {
|
||||||
setError("The file \"" + Utils::FileSystem::getFileName(mSavePath) + "\" returned by the " +
|
|
||||||
"scraper seems to be invalid as it's less than 350 bytes in size");
|
FREE_IMAGE_FORMAT imageFormat = FIF_UNKNOWN;
|
||||||
return;
|
|
||||||
|
if (mMediaType != "videos") {
|
||||||
|
std::string imageData = mReq->getContent();
|
||||||
|
|
||||||
|
FIMEMORY* memoryStream = FreeImage_OpenMemory(
|
||||||
|
reinterpret_cast<BYTE*>(&imageData.at(0)), imageData.size());
|
||||||
|
|
||||||
|
imageFormat = FreeImage_GetFileTypeFromMemory(memoryStream, 0);
|
||||||
|
FreeImage_CloseMemory(memoryStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (imageFormat == FIF_UNKNOWN) {
|
||||||
|
setError("The file \"" + Utils::FileSystem::getFileName(mSavePath) +
|
||||||
|
"\" returned by the scraper seems to be invalid as it's less than " +
|
||||||
|
"350 bytes in size");
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove any existing media file before attempting to write a new one.
|
// Remove any existing media file before attempting to write a new one.
|
||||||
|
|
Loading…
Reference in a new issue