Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -146,6 +146,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 All @@ -156,11 +166,17 @@ private float duration() {
* @return {@code true} if the animation is compliant
*/
private static boolean isAnimationCompliant(AnimationDetails animation) {
return animation != null
boolean isCompliant = animation != null
&& animation.frameRate() <= MAX_ANIMATION_FRAME_RATE
&& animation.duration() <= MAX_ANIMATION_DURATION_SECONDS
&& animation.width() == MAX_SIDE_LENGTH
&& animation.height() == MAX_SIDE_LENGTH;

if (!isCompliant) {
LOGGER.atWarn().log("The {} doesn't meet Telegram's requirements", animation);
}

return isCompliant;
}

/**
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 archive = loadResource("non_compliant_animated_sticker.gz");

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

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