Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/thumbnails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,31 @@ QByteArray withPlainText(const QByteArray &png) {
return out;
}

// The spec's Exec field: %i input path, %u input URI, %o output, %s size.
// The spec's Exec field, such as "ffmpegthumbnailer -i %i -o %o -s %s -f": %i input path, %u input URI, %o output, %s size, %% a percent sign.
// Each code is read once, so a name that holds one arrives as it is.
QStringList expandCommand(const QString &command, const QString &input, const QString &output, int size) {
QStringList args = QProcess::splitCommand(command);
for (QString &arg : args) {
arg.replace("%i", input).replace("%u", fileUri(input)).replace("%o", output)
.replace("%s", QString::number(size)).replace("%%", "%");
QString expanded;
for (qsizetype at = 0; at < arg.size(); ++at) {
const QChar code = arg.at(at) == '%' && at + 1 < arg.size() ? arg.at(at + 1) : QChar();
if (code == 'i')
expanded += input;
Comment thread
dhh marked this conversation as resolved.
Resolved
else if (code == 'u')
expanded += fileUri(input);
else if (code == 'o')
expanded += output;
else if (code == 's')
expanded += QString::number(size);
else if (code == '%')
expanded += '%';
else {
expanded += arg.at(at);
continue;
}
++at;
}
arg = expanded;
}
return args;
}
Expand Down Expand Up @@ -385,8 +404,9 @@ void Thumbnails::remember(QImage image, const QString &path, int size, const QDa
}

// Markers say which round of thumbnailing failed: ones from before a fix
// (round 2: files on other machines) are tried again once.
static const QString failedRound = QStringLiteral("2");
// (round 2: files on other machines; round 3: names holding a %, helpers
// that never started, camera RAW) are tried again once.
static const QString failedRound = QStringLiteral("3");

void Thumbnails::rememberFailure(const QString &path, const QDateTime &modified) const {
QImage marker(1, 1, QImage::Format_ARGB32);
Expand Down
25 changes: 23 additions & 2 deletions tests/folio_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6402,6 +6402,26 @@ private slots:
QVERIFY(QFile::exists(dir.filePath("cache/fail/folio/" + Thumbnails::cacheKey(dir.filePath("clip.mp4")))));
}

void thumbnailsHandAThumbnailerANameThatHoldsACode()
{
QTemporaryDir dir;
// The thumbnailer copies its input out and notes the third argument it was given beside itself.
const QString script = dir.filePath("copy.sh");
write(script, "cp \"$1\" \"$2\" && printf %s \"$3\" > \"$0.said\"\n");
write(dir.filePath("demo.thumbnailer"), "[Thumbnailer Entry]\nExec=/bin/sh \"" + script.toUtf8()
+ "\" %i %o \"--size=%s,%s 100%% %u\"\nMimeType=video/mp4;\n");
Thumbnails thumbnails(dir.filePath("cache"), {dir.path()});

// A name with every code in it is still one file to the thumbnailer, by path and by URI.
const QString clip = dir.filePath("50%off %sale %up %in 100%%.mp4");
QVERIFY(QImage(10, 20, QImage::Format_RGB32).save(clip, "PNG"));
QCOMPARE(thumbnails.load(clip, "video/mp4", 128).size(), QSize(10, 20));
QFile said(script + ".said");
QVERIFY(said.open(QIODevice::ReadOnly));
QCOMPARE(QString::fromUtf8(said.readAll()),
"--size=128,128 100% " + QUrl::fromLocalFile(clip).toString(QUrl::FullyEncoded));
}

void thumbnailsRememberOnlyWhatFailed()
{
QTemporaryDir dir;
Expand Down Expand Up @@ -6431,12 +6451,13 @@ private slots:
write(dir.filePath("never.broken"), "x");
QVERIFY(withBroken.load(dir.filePath("never.broken"), "image/x-broken", 128).isNull());
const QImage marker(dir.filePath("cache/fail/folio/" + Thumbnails::cacheKey(dir.filePath("never.broken"))));
QCOMPARE(marker.text("X-Folio::Round"), QString("2"));
// An old marker, without its round, for a picture that can be made.
QCOMPARE(marker.text("X-Folio::Round"), QString("3"));
// A marker from round 2, for a picture that can be made.
const QFileInfo picture(dir.filePath("frame.png"));
QImage old(1, 1, QImage::Format_ARGB32);
old.setText("Thumb::MTime", QString::number(picture.lastModified().toSecsSinceEpoch()));
old.setText("X-Folio::MTime", QString::number(picture.lastModified().toMSecsSinceEpoch()));
old.setText("X-Folio::Round", "2");
QVERIFY(old.save(dir.filePath("cache/fail/folio/" + Thumbnails::cacheKey(picture.filePath()))));
QVERIFY(!withBroken.load(picture.filePath(), "image/png", 128).isNull());
}
Expand Down
Loading