Skip to content

Commit 04616a4

Browse files
github-actions[bot]SegoCodegithub-actions
authored
Sync from develop to main (#7)
* refactor code and add web panel * Update .gitignore * Update PanelController.java * Update PanelController.java * move views to resource folder * Create demo3.png * Update CommandExecutor.java * Update admin.html * Update admin.html * Update CommandExecutor.java * Update CommandExecutor.java * Update CommandExecutor.java * Update CommandExecutor.java * Update CommandExecutor.java * Update Messages.java * Update CommandExecutor.java * Delete CommandExecutor.java * Delete Utils.java * Update FileUtil.java * Update Webdlbot.java * Update Webdlbot.java * Update Main.java * Update Webdlbot.java * Update Webdlbot.java * Update admin.html * Update admin.html * Update admin.html * Update admin.html * Update admin.html * Update admin.html * Update update-license.yml * Create demoPanel.png * Update README.md * Update LICENSE with repository information --------- Co-authored-by: SegoCode <[email protected]> Co-authored-by: github-actions <[email protected]>
1 parent adcb9b0 commit 04616a4

File tree

19 files changed

+655
-98
lines changed

19 files changed

+655
-98
lines changed

.github/workflows/update-license.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
- name: Checkout repository
1717
uses: actions/checkout@v4
1818
with:
19-
ref: main
19+
ref: develop
2020

2121
- name: Setup git
2222
run: |
@@ -55,5 +55,5 @@ jobs:
5555
# Only commit if there are changes
5656
git diff --staged --quiet || git commit -m "Update LICENSE with repository information"
5757
58-
# Push directly to main branch
59-
git push origin main
58+
# Push directly to develop branch
59+
git push origin develop

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
### Custom ###
22

33
code/.idea/*
4+
code/storage/*
5+
code/target/*
46

57
# Created by https://www.toptal.com/developers/gitignore/api/git,gpg,ssh,vim,linux,macos,windows,notepadpp,sublimetext,intellij+all,visualstudiocode,dotenv
68
# Edit at https://www.toptal.com/developers/gitignore?templates=git,gpg,ssh,vim,linux,macos,windows,notepadpp,sublimetext,intellij+all,visualstudiocode,dotenv

LICENSE

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,75 @@
1-
Copyright (c) SegoCode
2-
All rights reserved.
3-
4-
Section 1 - Definitions
5-
6-
1.1 "NonCommercial" pertains to any use, distribution, or modification of the
7-
licensed material that does not primarily aim to achieve commercial
8-
advantage or generate monetary compensation. This includes, but is not
9-
limited to, activities such as distributing the licensed material as part
10-
of an application or product that is sold, using the licensed material in
11-
advertising, and creating products or services with the licensed material
12-
that are subsequently sold.
13-
14-
1.2 "Adapted Material" refers to any work derived from or based upon the licensed
15-
material. This includes, but is not limited to, translations, alterations,
16-
rearrangements, transformations, source code modifications, compiled code
17-
alterations, architectural redesigns, or the integration of the licensed
18-
material into other software projects.
19-
20-
1.3 "NonAdapted Material" refers to exact copies of the licensed material, either
21-
in source code or binary form, which are reproduced without any changes,
22-
modifications, or transformations.
23-
24-
Section 2 - License Conditions
25-
26-
2.1 Distribution and usage in source or binary forms are permitted solely for
27-
NonCommercial purposes for both NonAdapted Material and Adapted Material
28-
excluding NonAdapted Material cases in 2.4 section.
29-
30-
2.2 Redistributions for any NonAdapted Material or Adapted Material, either
31-
in source code or binary form, must include the original copyright notice,
32-
this license, the disclaimer, and comply with the requirements specified
33-
herein. For binary form redistributions, these documents must be included
34-
in any provided documentation or materials or a clearly accessible link
35-
to this license ensuring that recipients can easily review the license terms.
36-
37-
2.3 For any Adapted Material, whether in source code or binary form, and for any
38-
instance of the licensed material utilized in applications accessible over
39-
the internet that run on a server, the source code must be made accessible
40-
through a public repository, a downloadable archive, or an equivalent
41-
method, ensuring that users have the capability to access, review, and
42-
download the code, and must clearly credit the original work and author.
43-
44-
2.4 For any NonAdapted Material that are offered on download sites, marketplaces, or
45-
software distribution platforms, are permitted under the condition that any
46-
economic benefit derived from such distribution is strictly indirect, including
47-
but not limited to advertisements or link redirectors. Direct sales or charges
48-
for access to the licensed material are not permitted under this license. Upon
49-
the original author distributing the material on the same platform, all alternative
50-
downloads and any associated revenue-generating mechanisms must be discontinued
51-
immediately. Acceptance of this license constitutes agreement that the copyright
52-
holder may request the immediate cessation of such downloads and activities on
53-
such platforms, and the distributor must comply with such request without delay.
54-
55-
2.5 Distributing the licensed material alongside unrelated or harmful software, such as adware,
56-
malware, or spyware or implying endorsement or association with the original author
57-
or recognized entities without permission, is prohibited.
58-
59-
Section 3 - Updates and Revisions
60-
61-
3.1 The copyright holder retains the right to amend, update, or otherwise modify this
62-
license at any time without prior notice. Users should periodically review the
63-
license terms to stay informed of any changes.
64-
65-
3.2 Continued use of the licensed material after such changes signifies acceptance of the
66-
revised license terms. It is the user's responsibility to ensure ongoing compliance
67-
with the most current version of the license.
68-
69-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
70-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
71-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
72-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
73-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
74-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
75-
SOFTWARE.
1+
Copyright (c) SegoCode
2+
All rights reserved.
3+
4+
Section 1 - Definitions
5+
6+
1.1 "NonCommercial" pertains to any use, distribution, or modification of the
7+
licensed material that does not primarily aim to achieve commercial
8+
advantage or generate monetary compensation. This includes, but is not
9+
limited to, activities such as distributing the licensed material as part
10+
of an application or product that is sold, using the licensed material in
11+
advertising, and creating products or services with the licensed material
12+
that are subsequently sold.
13+
14+
1.2 "Adapted Material" refers to any work derived from or based upon the licensed
15+
material. This includes, but is not limited to, translations, alterations,
16+
rearrangements, transformations, source code modifications, compiled code
17+
alterations, architectural redesigns, or the integration of the licensed
18+
material into other software projects.
19+
20+
1.3 "NonAdapted Material" refers to exact copies of the licensed material, either
21+
in source code or binary form, which are reproduced without any changes,
22+
modifications, or transformations.
23+
24+
Section 2 - License Conditions
25+
26+
2.1 Distribution and usage in source or binary forms are permitted solely for
27+
NonCommercial purposes for both NonAdapted Material and Adapted Material
28+
excluding NonAdapted Material cases in 2.4 section.
29+
30+
2.2 Redistributions for any NonAdapted Material or Adapted Material, either
31+
in source code or binary form, must include the original copyright notice,
32+
this license, the disclaimer, and comply with the requirements specified
33+
herein. For binary form redistributions, these documents must be included
34+
in any provided documentation or materials or a clearly accessible link
35+
to this license ensuring that recipients can easily review the license terms.
36+
37+
2.3 For any Adapted Material, whether in source code or binary form, and for any
38+
instance of the licensed material utilized in applications accessible over
39+
the internet that run on a server, the source code must be made accessible
40+
through a public repository, a downloadable archive, or an equivalent
41+
method, ensuring that users have the capability to access, review, and
42+
download the code, and must clearly credit the original work and author.
43+
44+
2.4 For any NonAdapted Material that are offered on download sites, marketplaces, or
45+
software distribution platforms, are permitted under the condition that any
46+
economic benefit derived from such distribution is strictly indirect, including
47+
but not limited to advertisements or link redirectors. Direct sales or charges
48+
for access to the licensed material are not permitted under this license. Upon
49+
the original author distributing the material on the same platform, all alternative
50+
downloads and any associated revenue-generating mechanisms must be discontinued
51+
immediately. Acceptance of this license constitutes agreement that the copyright
52+
holder may request the immediate cessation of such downloads and activities on
53+
such platforms, and the distributor must comply with such request without delay.
54+
55+
2.5 Distributing the licensed material alongside unrelated or harmful software, such as adware,
56+
malware, or spyware or implying endorsement or association with the original author
57+
or recognized entities without permission, is prohibited.
58+
59+
Section 3 - Updates and Revisions
60+
61+
3.1 The copyright holder retains the right to amend, update, or otherwise modify this
62+
license at any time without prior notice. Users should periodically review the
63+
license terms to stay informed of any changes.
64+
65+
3.2 Continued use of the licensed material after such changes signifies acceptance of the
66+
revised license terms. It is the user's responsibility to ensure ongoing compliance
67+
with the most current version of the license.
68+
69+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
70+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
71+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
72+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
73+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
74+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
75+
SOFTWARE.

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# webdl
22

33
<img src="https://raw.githubusercontent.com/SegoCode/webdl_bot/main/media/demo2.gif">
4+
<img src="https://raw.githubusercontent.com/SegoCode/webdl_bot/main/media/demoPanel.png">
45

56
<p align="center">
67
<a href="#about">About</a> •
@@ -18,6 +19,8 @@ Telegram bot in Java for downloading social media videos using yt-dlp
1819

1920
- Dynamic interaction with messages
2021

22+
- Panel with usage statistics
23+
2124
## Quick Start & Information
2225

2326
Webdl accepts a video URL, downloads it using [yt-dlp](https://github.com/yt-dlp/yt-dlp), and sends it back to the user as a video message.
@@ -35,8 +38,11 @@ Use a temp volume for the download, it will delete after send.
3538
```
3639
mvn clean package
3740
docker build -t webdl-image .
38-
docker run -e BOT_TOKEN=your-bot-token -v /mnt/drive/data/webdl:/downloads --name webdl webdl-image
41+
docker run -e BOT_TOKEN=your-bot-token -p 8080:8080 -v /mnt/drive/data/webdl:/downloads --name webdl webdl-image
3942
```
43+
44+
45+
4046
---
4147
<p align="center"><a href="https://github.com/SegoCode/webdl/graphs/contributors">
4248
<img src="https://contrib.rocks/image?repo=SegoCode/webdl" />

code/pom.xml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,27 @@
2525
<artifactId>logback-classic</artifactId>
2626
<version>1.4.14</version>
2727
</dependency>
28+
<dependency>
29+
<groupId>org.projectlombok</groupId>
30+
<artifactId>lombok</artifactId>
31+
<version>1.18.36</version>
32+
<scope>provided</scope>
33+
</dependency>
34+
<dependency>
35+
<groupId>org.eclipse.store</groupId>
36+
<artifactId>storage-embedded</artifactId>
37+
<version>2.1.2</version>
38+
</dependency>
39+
<dependency>
40+
<groupId>io.javalin</groupId>
41+
<artifactId>javalin</artifactId>
42+
<version>6.5.0</version>
43+
</dependency>
44+
<dependency>
45+
<groupId>com.google.code.gson</groupId>
46+
<artifactId>gson</artifactId>
47+
<version>2.12.1</version>
48+
</dependency>
2849
</dependencies>
2950

3051
<build>

code/src/main/java/org/segocode/Main.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
package org.segocode;
22

3+
import io.javalin.Javalin;
4+
import org.eclipse.store.storage.embedded.types.EmbeddedStorage;
5+
import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager;
6+
import org.eclipse.store.storage.types.StorageManager;
37
import org.segocode.bot.Webdlbot;
8+
import org.segocode.panel.PanelController;
49
import org.slf4j.Logger;
510
import org.slf4j.LoggerFactory;
611
import org.telegram.telegrambots.meta.TelegramBotsApi;
712
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;
813

14+
import java.util.Date;
15+
916
public class Main {
1017
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);
1118

1219
public static void main(String[] args) {
1320
try {
14-
LOGGER.info("Starting the video download bot...");
21+
LOGGER.info("Starting storage manager...");
22+
final EmbeddedStorageManager storageManager = EmbeddedStorage.start();
1523
TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class);
16-
botsApi.registerBot(new Webdlbot());
24+
LOGGER.info("Starting the video download bot...");
25+
botsApi.registerBot(new Webdlbot(storageManager));
1726
LOGGER.info("Bot started successfully and ready to download videos 🚀");
27+
LOGGER.info("Starting webp anel app...");
28+
PanelController.start(storageManager);
1829
} catch (Exception e) {
1930
LOGGER.error("Error while attempting to start the bot. Error details:", e);
2031
}

code/src/main/java/org/segocode/bot/Webdlbot.java

Lines changed: 52 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
11
package org.segocode.bot;
22

3-
import org.segocode.bot.utils.Utils;
4-
import org.segocode.system.CommandExecutor;
5-
import org.segocode.service.VideoService;
3+
import org.eclipse.store.storage.types.StorageManager;
4+
import org.segocode.bot.model.DataRootContainer;
5+
import org.segocode.bot.model.User;
6+
import org.segocode.system.command.CommandExecutor;
7+
import org.segocode.bot.service.VideoService;
68
import org.slf4j.LoggerFactory;
79
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
810
import org.telegram.telegrambots.meta.api.objects.Message;
911
import org.telegram.telegrambots.meta.api.objects.Update;
10-
import org.segocode.service.MessageService;
12+
import org.segocode.bot.service.MessageService;
1113
import org.slf4j.Logger;
1214
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
1315

16+
import java.time.LocalDateTime;
17+
import java.util.Optional;
1418
import java.util.concurrent.*;
1519

1620
import static org.segocode.bot.constants.Messages.*;
17-
import static org.segocode.bot.utils.Utils.*;
21+
import static org.segocode.bot.util.MessageUtil.*;
1822
import static org.segocode.system.util.FileUtil.*;
1923

2024
public class Webdlbot extends TelegramLongPollingBot {
2125
private static final Logger LOGGER = LoggerFactory.getLogger(Webdlbot.class);
2226
private static final String BOT_TOKEN = System.getenv("BOT_TOKEN");
2327

28+
private final StorageManager storageManager;
29+
2430
// Create a ThreadPoolExecutor with a single virtual thread
2531
private final ThreadPoolExecutor executorService = new ThreadPoolExecutor(
2632
1, // corePoolSize: the number of threads to keep in the pool, even if they are idle
@@ -31,6 +37,20 @@ public class Webdlbot extends TelegramLongPollingBot {
3137
Thread.ofVirtual().factory() // the factory to use when creating new threads
3238
);
3339

40+
public Webdlbot(StorageManager storageManager) {
41+
this.storageManager = storageManager;
42+
initializeRootContainer();
43+
}
44+
45+
private void initializeRootContainer() {
46+
Object root = storageManager.root();
47+
if (!(root instanceof DataRootContainer)) {
48+
storageManager.setRoot(new DataRootContainer());
49+
LOGGER.info("Initialized new DataRootContainer as db root object");
50+
}
51+
LOGGER.info("Root db object contains {} users", ((DataRootContainer) storageManager.root()).getUsers().size());
52+
}
53+
3454
@Override
3555
public String getBotUsername() {
3656
return "webdl";
@@ -51,7 +71,7 @@ public void onUpdateReceived(Update update) {
5171
if (update.hasMessage() && update.getMessage().hasText()) {
5272
try {
5373
Integer queuedMessageId;
54-
if (executorService.getActiveCount() > 0 || executorService.getQueue().size() > 0) {
74+
if (executorService.getActiveCount() > 0 || !executorService.getQueue().isEmpty()) {
5575
String messageTime = DOWNLOAD_REQUEST_QUEUED + " (<" + executorService.getQueue().size() + "m)";
5676
LOGGER.info("Executor is busy, queuing the message from @{}", update.getMessage().getFrom().getUserName());
5777
queuedMessageId = execute(MessageService.sendTextMessage(update.getMessage().getChatId(), update.getMessage().getMessageId(), messageTime)).getMessageId();
@@ -74,6 +94,9 @@ public void onUpdateReceived(Update update) {
7494
} catch (Exception e) {
7595
LOGGER.error("Failed on onUpdateReceived, error: {}", e.getMessage(), e);
7696
handleDispatchError(update, e);
97+
} finally {
98+
storageManager.setRoot(loadMetricsData(update));
99+
storageManager.storeRoot();
77100
}
78101
}
79102
}
@@ -107,6 +130,29 @@ private void handleDispatchError(Update update, Exception e) {
107130
cleanDownloadsFolder();
108131
}
109132
}
133+
134+
private DataRootContainer loadMetricsData(Update update) {
135+
// Create or update user data from the Telegram update
136+
org.telegram.telegrambots.meta.api.objects.User telegramUser = update.getMessage().getFrom();
137+
138+
DataRootContainer rootContainer = (DataRootContainer) storageManager.root();
139+
140+
// Find existing user or create new one
141+
String userId = telegramUser.getId().toString();
142+
Optional<User> existingUser = rootContainer.findUserById(userId);
143+
144+
if (existingUser.isPresent()) {
145+
User user = existingUser.get();
146+
user.recordNewMessage();
147+
} else {
148+
User newUser = new User(userId, update.getMessage().getChatId(), telegramUser.getUserName(), telegramUser.getFirstName(),
149+
telegramUser.getLastName(), telegramUser.getLanguageCode(), telegramUser.getIsPremium(),
150+
1,LocalDateTime.now().toString());
151+
rootContainer.getUsers().add(newUser);
152+
LOGGER.info("New user registered: {}", newUser.getUserName());
153+
}
154+
return rootContainer;
155+
}
110156
}
111157

112158

code/src/main/java/org/segocode/bot/constants/Messages.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ public class Messages {
44
public static final String NOT_VALID_LINK = "❌ That doesn't seem to be a valid link";
55
public static final String DOWNLOAD_REQUEST = "🔄 Download request processing...";
66
public static final String DOWNLOAD_REQUEST_QUEUED = "⌛ Your request is in queue...";
7-
public static final String DOWNLOAD_REQUEST_ERROR = "❌ An error occurred while processing your request: web not supported, private profile or reach limit.";
7+
public static final String DOWNLOAD_REQUEST_ERROR = "❌ Unable to download: web not supported, private post or reach limit";
88
}

0 commit comments

Comments
 (0)