Skip to content

Commit 4fadad2

Browse files
authored
Log non-compliant animated stickers (#302)
1 parent 8248f67 commit 4fadad2

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

src/main/java/com/github/stickerifier/stickerify/media/MediaHelper.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,12 @@ private static boolean isAnimatedStickerCompliant(File file, String mimeType) th
133133
try {
134134
var sticker = GSON.fromJson(uncompressedContent, AnimationDetails.class);
135135

136-
return isAnimationCompliant(sticker) && isFileSizeLowerThan(file, MAX_ANIMATION_FILE_SIZE);
136+
boolean isAnimationCompliant = isAnimationCompliant(sticker);
137+
if (isAnimationCompliant) {
138+
return isFileSizeLowerThan(file, MAX_ANIMATION_FILE_SIZE);
139+
}
140+
141+
LOGGER.atWarn().log("The {} doesn't meet Telegram's requirements", sticker);
137142
} catch (JsonSyntaxException _) {
138143
LOGGER.atInfo().log("The archive isn't an animated sticker");
139144
}
@@ -146,6 +151,16 @@ private record AnimationDetails(@SerializedName("w") int width, @SerializedName(
146151
private float duration() {
147152
return (end - start) / frameRate;
148153
}
154+
155+
@Override
156+
public String toString() {
157+
return "animated sticker [" +
158+
"width=" + width +
159+
", height=" + height +
160+
", frameRate=" + frameRate +
161+
", duration=" + duration() +
162+
']';
163+
}
149164
}
150165

151166
/**

src/test/java/com/github/stickerifier/stickerify/media/MediaHelperTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ void noLowFpsAnimatedStickerConversionNeeded() throws Exception {
239239
assertThat(result, is(nullValue()));
240240
}
241241

242+
@Test
243+
void nonCompliantAnimatedSticker() {
244+
var animatedSticker = loadResource("non_compliant_animated_sticker.tgs");
245+
246+
assertThrows(MediaException.class, () -> MediaHelper.convert(animatedSticker));
247+
}
248+
242249
@Test
243250
void unsupportedGzipArchive() {
244251
var archive = loadResource("unsupported_archive.gz");
3.45 KB
Binary file not shown.

0 commit comments

Comments
 (0)