Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,12 @@ private static boolean isAnimatedStickerCompliant(File file, String mimeType) th
try {
var sticker = GSON.fromJson(uncompressedContent, AnimationDetails.class);

return isAnimationCompliant(sticker) && isFileSizeLowerThan(file, MAX_ANIMATION_FILE_SIZE);
boolean isAnimationCompliant = isAnimationCompliant(sticker);
if (isAnimationCompliant) {
return isFileSizeLowerThan(file, MAX_ANIMATION_FILE_SIZE);
}

LOGGER.atWarn().log("The {} doesn't meet Telegram's requirements", sticker);
} catch (JsonSyntaxException _) {
LOGGER.atInfo().log("The archive isn't an animated sticker");
}
Expand All @@ -146,6 +151,16 @@ private record AnimationDetails(@SerializedName("w") int width, @SerializedName(
private float duration() {
return (end - start) / frameRate;
}

@Override
public String toString() {
return "animated sticker [" +
"width=" + width +
", height=" + height +
", frameRate=" + frameRate +
", duration=" + duration() +
']';
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,13 @@ void noLowFpsAnimatedStickerConversionNeeded() throws Exception {
assertThat(result, is(nullValue()));
}

@Test
void nonCompliantAnimatedSticker() {
var animatedSticker = loadResource("non_compliant_animated_sticker.tgs");

assertThrows(MediaException.class, () -> MediaHelper.convert(animatedSticker));
}

@Test
void unsupportedGzipArchive() {
var archive = loadResource("unsupported_archive.gz");
Expand Down
Binary file not shown.
Loading