Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
962ad67
refactor code and add web panel
SegoCode Mar 13, 2025
2efabf4
Update .gitignore
SegoCode Mar 13, 2025
647fbee
Update PanelController.java
SegoCode Mar 13, 2025
9de2f6f
Update PanelController.java
SegoCode Mar 13, 2025
59f6960
move views to resource folder
SegoCode Mar 13, 2025
4302910
Create demo3.png
SegoCode Mar 13, 2025
25cb168
Update CommandExecutor.java
SegoCode Mar 23, 2025
d2c1860
Update admin.html
SegoCode Mar 23, 2025
4c6cc53
Update admin.html
SegoCode Mar 24, 2025
a2a4c3b
Update CommandExecutor.java
SegoCode Mar 25, 2025
512f68c
Update CommandExecutor.java
SegoCode Mar 25, 2025
ef8a109
Update CommandExecutor.java
SegoCode Mar 25, 2025
52fead9
Update CommandExecutor.java
SegoCode Mar 25, 2025
fa09a3f
Update CommandExecutor.java
SegoCode Mar 25, 2025
e108ef3
Update Messages.java
SegoCode Mar 25, 2025
d9e69d1
Update CommandExecutor.java
SegoCode Mar 25, 2025
5096c82
Delete CommandExecutor.java
SegoCode Mar 25, 2025
5a5c7bc
Delete Utils.java
SegoCode Mar 27, 2025
5640c54
Update FileUtil.java
SegoCode Mar 27, 2025
5c9255d
Update Webdlbot.java
SegoCode Mar 27, 2025
13c5476
Update Webdlbot.java
SegoCode Mar 27, 2025
3b88ef3
Update Main.java
SegoCode Mar 27, 2025
53ee2a1
Update Webdlbot.java
SegoCode Mar 27, 2025
619ec1f
Update Webdlbot.java
SegoCode Mar 27, 2025
ff70c20
Update admin.html
SegoCode Mar 28, 2025
386aee8
Update admin.html
SegoCode Mar 28, 2025
a7727be
Update admin.html
SegoCode Mar 28, 2025
f0e6405
Update admin.html
SegoCode Mar 28, 2025
6f47b4d
Update admin.html
SegoCode Mar 28, 2025
8e525ad
Update admin.html
SegoCode Mar 28, 2025
1978b07
Update update-license.yml
SegoCode Apr 1, 2025
d5166ef
Create demoPanel.png
SegoCode Apr 2, 2025
8960170
Update README.md
SegoCode Apr 2, 2025
cd36ca8
Update LICENSE with repository information
invalid-email-address Apr 2, 2025
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
6 changes: 3 additions & 3 deletions .github/workflows/update-license.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: main
ref: develop

- name: Setup git
run: |
Expand Down Expand Up @@ -55,5 +55,5 @@ jobs:
# Only commit if there are changes
git diff --staged --quiet || git commit -m "Update LICENSE with repository information"

# Push directly to main branch
git push origin main
# Push directly to develop branch
git push origin develop
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
### Custom ###

code/.idea/*
code/storage/*
code/target/*

# Created by https://www.toptal.com/developers/gitignore/api/git,gpg,ssh,vim,linux,macos,windows,notepadpp,sublimetext,intellij+all,visualstudiocode,dotenv
# Edit at https://www.toptal.com/developers/gitignore?templates=git,gpg,ssh,vim,linux,macos,windows,notepadpp,sublimetext,intellij+all,visualstudiocode,dotenv
Expand Down
150 changes: 75 additions & 75 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
Copyright (c) SegoCode
All rights reserved.

Section 1 - Definitions

1.1 "NonCommercial" pertains to any use, distribution, or modification of the
licensed material that does not primarily aim to achieve commercial
advantage or generate monetary compensation. This includes, but is not
limited to, activities such as distributing the licensed material as part
of an application or product that is sold, using the licensed material in
advertising, and creating products or services with the licensed material
that are subsequently sold.

1.2 "Adapted Material" refers to any work derived from or based upon the licensed
material. This includes, but is not limited to, translations, alterations,
rearrangements, transformations, source code modifications, compiled code
alterations, architectural redesigns, or the integration of the licensed
material into other software projects.

1.3 "NonAdapted Material" refers to exact copies of the licensed material, either
in source code or binary form, which are reproduced without any changes,
modifications, or transformations.

Section 2 - License Conditions

2.1 Distribution and usage in source or binary forms are permitted solely for
NonCommercial purposes for both NonAdapted Material and Adapted Material
excluding NonAdapted Material cases in 2.4 section.

2.2 Redistributions for any NonAdapted Material or Adapted Material, either
in source code or binary form, must include the original copyright notice,
this license, the disclaimer, and comply with the requirements specified
herein. For binary form redistributions, these documents must be included
in any provided documentation or materials or a clearly accessible link
to this license ensuring that recipients can easily review the license terms.

2.3 For any Adapted Material, whether in source code or binary form, and for any
instance of the licensed material utilized in applications accessible over
the internet that run on a server, the source code must be made accessible
through a public repository, a downloadable archive, or an equivalent
method, ensuring that users have the capability to access, review, and
download the code, and must clearly credit the original work and author.

2.4 For any NonAdapted Material that are offered on download sites, marketplaces, or
software distribution platforms, are permitted under the condition that any
economic benefit derived from such distribution is strictly indirect, including
but not limited to advertisements or link redirectors. Direct sales or charges
for access to the licensed material are not permitted under this license. Upon
the original author distributing the material on the same platform, all alternative
downloads and any associated revenue-generating mechanisms must be discontinued
immediately. Acceptance of this license constitutes agreement that the copyright
holder may request the immediate cessation of such downloads and activities on
such platforms, and the distributor must comply with such request without delay.

2.5 Distributing the licensed material alongside unrelated or harmful software, such as adware,
malware, or spyware or implying endorsement or association with the original author
or recognized entities without permission, is prohibited.

Section 3 - Updates and Revisions

3.1 The copyright holder retains the right to amend, update, or otherwise modify this
license at any time without prior notice. Users should periodically review the
license terms to stay informed of any changes.

3.2 Continued use of the licensed material after such changes signifies acceptance of the
revised license terms. It is the user's responsibility to ensure ongoing compliance
with the most current version of the license.

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

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

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

- Dynamic interaction with messages

- Panel with usage statistics

## Quick Start & Information

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.
Expand All @@ -35,8 +38,11 @@ Use a temp volume for the download, it will delete after send.
```
mvn clean package
docker build -t webdl-image .
docker run -e BOT_TOKEN=your-bot-token -v /mnt/drive/data/webdl:/downloads --name webdl webdl-image
docker run -e BOT_TOKEN=your-bot-token -p 8080:8080 -v /mnt/drive/data/webdl:/downloads --name webdl webdl-image
```



---
<p align="center"><a href="https://github.com/SegoCode/webdl/graphs/contributors">
<img src="https://contrib.rocks/image?repo=SegoCode/webdl" />
Expand Down
21 changes: 21 additions & 0 deletions code/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,27 @@
<artifactId>logback-classic</artifactId>
<version>1.4.14</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.36</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.store</groupId>
<artifactId>storage-embedded</artifactId>
<version>2.1.2</version>
</dependency>
<dependency>
<groupId>io.javalin</groupId>
<artifactId>javalin</artifactId>
<version>6.5.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.12.1</version>
</dependency>
</dependencies>

<build>
Expand Down
15 changes: 13 additions & 2 deletions code/src/main/java/org/segocode/Main.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
package org.segocode;

import io.javalin.Javalin;
import org.eclipse.store.storage.embedded.types.EmbeddedStorage;
import org.eclipse.store.storage.embedded.types.EmbeddedStorageManager;
import org.eclipse.store.storage.types.StorageManager;
import org.segocode.bot.Webdlbot;
import org.segocode.panel.PanelController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.updatesreceivers.DefaultBotSession;

import java.util.Date;

public class Main {
private static final Logger LOGGER = LoggerFactory.getLogger(Main.class);

public static void main(String[] args) {
try {
LOGGER.info("Starting the video download bot...");
LOGGER.info("Starting storage manager...");
final EmbeddedStorageManager storageManager = EmbeddedStorage.start();
TelegramBotsApi botsApi = new TelegramBotsApi(DefaultBotSession.class);
botsApi.registerBot(new Webdlbot());
LOGGER.info("Starting the video download bot...");
botsApi.registerBot(new Webdlbot(storageManager));
LOGGER.info("Bot started successfully and ready to download videos 🚀");
LOGGER.info("Starting webp anel app...");
PanelController.start(storageManager);
} catch (Exception e) {
LOGGER.error("Error while attempting to start the bot. Error details:", e);
}
Expand Down
58 changes: 52 additions & 6 deletions code/src/main/java/org/segocode/bot/Webdlbot.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
package org.segocode.bot;

import org.segocode.bot.utils.Utils;
import org.segocode.system.CommandExecutor;
import org.segocode.service.VideoService;
import org.eclipse.store.storage.types.StorageManager;
import org.segocode.bot.model.DataRootContainer;
import org.segocode.bot.model.User;
import org.segocode.system.command.CommandExecutor;
import org.segocode.bot.service.VideoService;
import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.segocode.service.MessageService;
import org.segocode.bot.service.MessageService;
import org.slf4j.Logger;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;

import java.time.LocalDateTime;
import java.util.Optional;
import java.util.concurrent.*;

import static org.segocode.bot.constants.Messages.*;
import static org.segocode.bot.utils.Utils.*;
import static org.segocode.bot.util.MessageUtil.*;
import static org.segocode.system.util.FileUtil.*;

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

private final StorageManager storageManager;

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

public Webdlbot(StorageManager storageManager) {
this.storageManager = storageManager;
initializeRootContainer();
}

private void initializeRootContainer() {
Object root = storageManager.root();
if (!(root instanceof DataRootContainer)) {
storageManager.setRoot(new DataRootContainer());
LOGGER.info("Initialized new DataRootContainer as db root object");
}
LOGGER.info("Root db object contains {} users", ((DataRootContainer) storageManager.root()).getUsers().size());
}

@Override
public String getBotUsername() {
return "webdl";
Expand All @@ -51,7 +71,7 @@ public void onUpdateReceived(Update update) {
if (update.hasMessage() && update.getMessage().hasText()) {
try {
Integer queuedMessageId;
if (executorService.getActiveCount() > 0 || executorService.getQueue().size() > 0) {
if (executorService.getActiveCount() > 0 || !executorService.getQueue().isEmpty()) {
String messageTime = DOWNLOAD_REQUEST_QUEUED + " (<" + executorService.getQueue().size() + "m)";
LOGGER.info("Executor is busy, queuing the message from @{}", update.getMessage().getFrom().getUserName());
queuedMessageId = execute(MessageService.sendTextMessage(update.getMessage().getChatId(), update.getMessage().getMessageId(), messageTime)).getMessageId();
Expand All @@ -74,6 +94,9 @@ public void onUpdateReceived(Update update) {
} catch (Exception e) {
LOGGER.error("Failed on onUpdateReceived, error: {}", e.getMessage(), e);
handleDispatchError(update, e);
} finally {
storageManager.setRoot(loadMetricsData(update));
storageManager.storeRoot();
}
}
}
Expand Down Expand Up @@ -107,6 +130,29 @@ private void handleDispatchError(Update update, Exception e) {
cleanDownloadsFolder();
}
}

private DataRootContainer loadMetricsData(Update update) {
// Create or update user data from the Telegram update
org.telegram.telegrambots.meta.api.objects.User telegramUser = update.getMessage().getFrom();

DataRootContainer rootContainer = (DataRootContainer) storageManager.root();

// Find existing user or create new one
String userId = telegramUser.getId().toString();
Optional<User> existingUser = rootContainer.findUserById(userId);

if (existingUser.isPresent()) {
User user = existingUser.get();
user.recordNewMessage();
} else {
User newUser = new User(userId, update.getMessage().getChatId(), telegramUser.getUserName(), telegramUser.getFirstName(),
telegramUser.getLastName(), telegramUser.getLanguageCode(), telegramUser.getIsPremium(),
1,LocalDateTime.now().toString());
rootContainer.getUsers().add(newUser);
LOGGER.info("New user registered: {}", newUser.getUserName());
}
return rootContainer;
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ public class Messages {
public static final String NOT_VALID_LINK = "❌ That doesn't seem to be a valid link";
public static final String DOWNLOAD_REQUEST = "🔄 Download request processing...";
public static final String DOWNLOAD_REQUEST_QUEUED = "⌛ Your request is in queue...";
public static final String DOWNLOAD_REQUEST_ERROR = "❌ An error occurred while processing your request: web not supported, private profile or reach limit.";
public static final String DOWNLOAD_REQUEST_ERROR = "❌ Unable to download: web not supported, private post or reach limit";
}
Loading