Skip to content

Commit 2722b50

Browse files
Use ffmpeg also for image conversion
1 parent fc630ed commit 2722b50

File tree

15 files changed

+624
-282
lines changed

15 files changed

+624
-282
lines changed

Dockerfile

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ FROM eclipse-temurin:24-alpine AS builder
22

33
WORKDIR /app
44
COPY . .
5-
RUN --mount=type=cache,target=/root/.gradle ./gradlew jlink shadowJar
5+
RUN --mount=type=cache,target=/root/.gradle ./gradlew installDist
66

77
# bump: alpine /FROM alpine:([\d.]+)/ docker:alpine|^3
88
# bump: alpine link "Release notes" https://alpinelinux.org/posts/Alpine-$LATEST-released.html
99
FROM alpine:3.22.1 AS bot
1010

11-
RUN apk --no-cache add libwebp-tools
12-
1311
# bump: ffmpeg /static-ffmpeg:([\d.]+)/ docker:mwader/static-ffmpeg|~7.0
1412
COPY --from=mwader/static-ffmpeg:7.0.2 /ffmpeg /usr/bin/
15-
ENV FFMPEG_PATH=/usr/bin/ffmpeg
13+
COPY --from=builder /app/build/install/Stickerify/ .
1614

17-
COPY --from=builder /app/build/jlink/jre jre
18-
COPY --from=builder /app/build/libs/*-all.jar Stickerify.jar
19-
20-
CMD ["jre/bin/java", "-Dcom.sksamuel.scrimage.webp.binary.dir=/usr/bin", "-jar", "Stickerify.jar"]
15+
ENV CONCURRENT_PROCESSES=5
16+
ENV FFMPEG_PATH=/usr/bin/ffmpeg
17+
CMD ["./bin/Stickerify"]

Railway.dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ ARG DOCKER_TAG=latest
22
FROM rob93c/stickerify:$DOCKER_TAG
33
ARG STICKERIFY_TOKEN
44
ARG LOG_LEVEL
5-
ARG CONCURRENT_THREADS
5+
ARG CONCURRENT_PROCESSES
66
ENV STICKERIFY_TOKEN=$STICKERIFY_TOKEN \
77
LOG_LEVEL=$LOG_LEVEL \
8-
CONCURRENT_THREADS=$CONCURRENT_THREADS
8+
CONCURRENT_PROCESSES=$CONCURRENT_PROCESSES

build.gradle

Lines changed: 20 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2,48 +2,30 @@ import com.github.stickerifier.stickerify.JlinkJavaLauncher
22
import com.github.stickerifier.stickerify.JlinkTask
33

44
plugins {
5-
id('application')
65
id('java')
76
id('jacoco')
8-
alias(libs.plugins.shadow)
7+
id('application')
98
}
109

1110
repositories {
1211
mavenCentral()
1312
}
1413

1514
dependencies {
16-
implementation(libs.batik)
1715
implementation(libs.gson)
18-
implementation(libs.imageio.batik)
19-
implementation(libs.imageio.psd)
2016
implementation(libs.jave)
2117
implementation(libs.logback.classic)
22-
implementation(libs.logback.core)
23-
implementation(libs.scrimage.core)
24-
implementation(libs.scrimage.formats.extra)
25-
implementation(libs.scrimage.webp)
26-
implementation(libs.slf4j.api)
2718
implementation(libs.telegram.bot.api)
2819
implementation(libs.tika)
2920

3021
testImplementation(libs.hamcrest)
3122
testImplementation(libs.junit.jupiter)
3223
testImplementation(libs.mockwebserver)
3324
testRuntimeOnly(libs.junit.platform)
34-
35-
constraints {
36-
implementation('org.apache.commons:commons-lang3') {
37-
version {
38-
strictly('[3.18.0, 4)')
39-
}
40-
because('CVE-2025-48924: Apache Commons Lang is vulnerable to Uncontrolled Recursion when processing long inputs')
41-
}
42-
}
4325
}
4426

4527
group = 'com.github.stickerifier'
46-
version = '1.0'
28+
version = '2.0'
4729
description = 'Telegram bot to convert medias in the format required to be used as Telegram stickers'
4830

4931
java.toolchain {
@@ -58,7 +40,12 @@ updateDaemonJvm {
5840

5941
def jlink = tasks.register('jlink', JlinkTask) {
6042
options = ['--strip-debug', '--no-header-files', '--no-man-pages']
61-
modules = ['java.desktop', 'java.instrument', 'java.naming', 'java.sql', 'jdk.crypto.ec', 'jdk.unsupported']
43+
modules = [
44+
'java.instrument', // for junit
45+
'java.naming', // for logback
46+
'java.sql', // for tika
47+
'jdk.unsupported', // for gson
48+
]
6249
includeModulePath = false
6350

6451
group = 'build'
@@ -73,7 +60,7 @@ test {
7360
finalizedBy(jacocoTestReport)
7461

7562
testLogging {
76-
events 'passed', 'failed', 'skipped'
63+
events('passed', 'failed', 'skipped')
7764
}
7865
}
7966

@@ -99,19 +86,15 @@ application {
9986
mainClass = 'com.github.stickerifier.stickerify.runner.Main'
10087
}
10188

102-
shadowJar {
103-
duplicatesStrategy = DuplicatesStrategy.INCLUDE
104-
mergeServiceFiles()
105-
failOnDuplicateEntries = true
106-
107-
exclude('dist_webp_binaries/',
108-
'META-INF/LICENSE',
109-
'META-INF/LICENSE.txt',
110-
'META-INF/NOTICE',
111-
'META-INF/NOTICE.txt',
112-
'license/LICENSE',
113-
'license/LICENSE.dom-documentation.txt',
114-
'license/LICENSE.dom-software.txt',
115-
'license/NOTICE',
116-
'license/README.dom.txt')
89+
distributions {
90+
main {
91+
contents {
92+
from(jlink)
93+
}
94+
}
95+
}
96+
97+
tasks.named('startScripts', CreateStartScripts) {
98+
unixStartScriptGenerator.template = resources.text.fromFile('src/main/resources/customUnixStartScript.txt')
99+
windowsStartScriptGenerator.template = resources.text.fromFile('src/main/resources/customWindowsStartScript.txt')
117100
}

buildSrc/src/main/java/com/github/stickerifier/stickerify/JlinkTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public JlinkTask(ProjectLayout layout, JavaToolchainService javaToolchain) {
5353
getOptions().convention(List.of());
5454
getModules().convention(List.of("ALL-MODULE-PATH"));
5555
getIncludeModulePath().convention(true);
56-
getOutputDirectory().convention(layout.getBuildDirectory().dir("jlink"));
56+
getOutputDirectory().convention(layout.getBuildDirectory().dir(getName()));
5757

5858
var toolchain = getProject().getExtensions().getByType(JavaPluginExtension.class).getToolchain();
5959
getJavaCompiler().convention(javaToolchain.compilerFor(toolchain));

gradle/libs.versions.toml

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,10 @@
1-
[versions]
2-
logback = "1.5.18"
3-
scrimage = "4.3.3"
4-
twelvemonkeys = "3.12.0"
5-
61
[libraries]
7-
batik = "org.apache.xmlgraphics:batik-transcoder:1.19"
82
gson = "com.google.code.gson:gson:2.13.1"
93
hamcrest = "org.hamcrest:hamcrest:3.0"
10-
imageio-batik = { module = "com.twelvemonkeys.imageio:imageio-batik", version.ref = "twelvemonkeys" }
11-
imageio-psd = { module = "com.twelvemonkeys.imageio:imageio-psd", version.ref = "twelvemonkeys" }
124
jave = "ws.schild:jave-core:3.5.0"
135
junit-jupiter = "org.junit.jupiter:junit-jupiter:5.13.4"
146
junit-platform = { module = "org.junit.platform:junit-platform-launcher" }
15-
logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
16-
logback-core = { module = "ch.qos.logback:logback-core", version.ref = "logback" }
7+
logback-classic = "ch.qos.logback:logback-classic:1.5.18"
178
mockwebserver = "com.squareup.okhttp3:mockwebserver3-junit5:5.1.0"
18-
scrimage-core = { module = "com.sksamuel.scrimage:scrimage-core", version.ref = "scrimage" }
19-
scrimage-formats-extra = { module = "com.sksamuel.scrimage:scrimage-formats-extra", version.ref = "scrimage" }
20-
scrimage-webp = { module = "com.sksamuel.scrimage:scrimage-webp", version.ref = "scrimage" }
21-
slf4j-api = "org.slf4j:slf4j-api:2.0.17"
229
telegram-bot-api = "com.github.pengrad:java-telegram-bot-api:9.2.0"
2310
tika = "org.apache.tika:tika-core:3.2.2"
24-
25-
[plugins]
26-
shadow = "com.gradleup.shadow:9.1.0"

src/main/java/com/github/stickerifier/stickerify/bot/Stickerify.java

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import static com.github.stickerifier.stickerify.telegram.Answer.FILE_TOO_LARGE;
88
import static com.pengrad.telegrambot.model.request.ParseMode.MarkdownV2;
99
import static java.util.HashSet.newHashSet;
10-
import static java.util.concurrent.Executors.newFixedThreadPool;
10+
import static java.util.concurrent.Executors.newThreadPerTaskExecutor;
1111

1212
import com.github.stickerifier.stickerify.exception.BaseException;
1313
import com.github.stickerifier.stickerify.exception.CorruptedVideoException;
@@ -48,7 +48,7 @@
4848
*
4949
* @author Roberto Cella
5050
*/
51-
public record Stickerify(TelegramBot bot, Executor executor) implements ExceptionHandler {
51+
public record Stickerify(TelegramBot bot, Executor executor) implements UpdatesListener, ExceptionHandler {
5252

5353
private static final Logger LOGGER = LoggerFactory.getLogger(Stickerify.class);
5454
private static final String BOT_TOKEN = System.getenv("STICKERIFY_TOKEN");
@@ -60,7 +60,7 @@ public record Stickerify(TelegramBot bot, Executor executor) implements Exceptio
6060
* @see Stickerify
6161
*/
6262
public Stickerify() {
63-
this(new TelegramBot.Builder(BOT_TOKEN).updateListenerSleep(500).build(), newFixedThreadPool(getMaxConcurrentThreads(), VIRTUAL_THREAD_FACTORY));
63+
this(new TelegramBot.Builder(BOT_TOKEN).updateListenerSleep(500).build(), newThreadPerTaskExecutor(VIRTUAL_THREAD_FACTORY));
6464
}
6565

6666
/**
@@ -69,15 +69,11 @@ public Stickerify() {
6969
* @see Stickerify
7070
*/
7171
public Stickerify {
72-
bot.setUpdatesListener(this::handleUpdates, this, new GetUpdates().timeout(50));
72+
bot.setUpdatesListener(this, this, new GetUpdates().timeout(50));
7373
}
7474

7575
@Override
76-
public void onException(TelegramException e) {
77-
LOGGER.atError().log("There was an unexpected failure: {}", e.getMessage());
78-
}
79-
80-
private int handleUpdates(List<Update> updates) {
76+
public int process(List<Update> updates) {
8177
updates.forEach(update -> executor.execute(() -> {
8278
if (update.message() != null) {
8379
var request = new TelegramRequest(update.message());
@@ -90,6 +86,11 @@ private int handleUpdates(List<Update> updates) {
9086
return UpdatesListener.CONFIRMED_UPDATES_ALL;
9187
}
9288

89+
@Override
90+
public void onException(TelegramException e) {
91+
LOGGER.atError().log("There was an unexpected failure: {}", e.getMessage());
92+
}
93+
9394
private void answer(TelegramRequest request) {
9495
var file = request.getFile();
9596

@@ -228,9 +229,4 @@ private static void deleteTempFiles(Set<Path> pathsToDelete) {
228229
}
229230
}
230231
}
231-
232-
private static int getMaxConcurrentThreads() {
233-
var value = System.getenv("CONCURRENT_THREADS");
234-
return value == null ? 5 : Integer.parseInt(value);
235-
}
236232
}

src/main/java/com/github/stickerifier/stickerify/exception/FileOperationException.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ public FileOperationException(Throwable cause) {
55
super(cause);
66
}
77

8+
public FileOperationException(String message) {
9+
super(message);
10+
}
11+
812
public FileOperationException(String message, Throwable cause) {
913
super(message, cause);
1014
}

src/main/java/com/github/stickerifier/stickerify/exception/MediaOptimizationException.java

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)