Skip to content

Commit

Permalink
Add two torrent folders and two media folders
Browse files Browse the repository at this point in the history
Add usb mounting
  • Loading branch information
Dmytro Galushko committed Jan 17, 2024
1 parent df025d6 commit dd0ea91
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 21 deletions.
20 changes: 10 additions & 10 deletions config/examples/docker-compose/docker-compose-bot_debug.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
version: '3.7'

services:
# torrent_debug:
# image: halushko/cinema-torrent:beta
# env_file:
# - constants.env
# restart: always
# container_name: "torrent_debug"
# volumes:
# - ./workdir/config/transmission:/home/app/transmission_config
# - ./workdir/config/logs:/home/app/logs
# network_mode: host
torrent_debug:
image: halushko/cinema-torrent:beta
env_file:
- constants.env
restart: always
container_name: "torrent_debug"
volumes:
- ./workdir/config/transmission:/home/app/transmission_config
- ./workdir/config/logs:/home/app/logs
network_mode: host
bot_debug:
image: halushko/cinema-bot:beta
env_file:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
- TZ=Etc/UTC
volumes:
- ./workdir/config/transmission_hdd:/config
- ./workdir/mediadata_hdd:/downloads/complete
- ./workdir/mediadata/hdd/mediadata:/downloads/complete
- ./workdir/config/files_from_telegram_hdd:/watch
ports:
- 9092:9091
Expand Down
2 changes: 1 addition & 1 deletion config/examples/etc/systemd/services/bot-down.service
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=Shut down Bot
Requires=docker.service
After=message-broker.service
After=mount-hdd.service

[Service]
Type=oneshot
Expand Down
5 changes: 4 additions & 1 deletion config/examples/etc/systemd/services/create_services.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ systemctl stop torrent-pull.service
systemctl stop torrent-hdd.service
systemctl stop torrent-hdd-down.service
systemctl stop torrent-hdd-pull.service
systemctl stop mount-hdd.service

systemctl disable bot.service
systemctl disable bot-debug-down.service
Expand All @@ -33,6 +34,7 @@ systemctl disable torrent-pull.service
systemctl disable torrent-hdd.service
systemctl disable torrent-hdd-down.service
systemctl disable torrent-hdd-pull.service
systemctl disable mount-hdd.service

cp -f *.service /etc/systemd/system

Expand All @@ -51,4 +53,5 @@ systemctl enable torrent-down.service
systemctl enable torrent-pull.service
systemctl enable torrent-hdd.service
systemctl enable torrent-hdd-down.service
systemctl enable torrent-hdd-pull.service
systemctl enable torrent-hdd-pull.service
systemctl enable mount-hdd.service
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=Media server down
Requires=docker.service
After=docker.service
After=mount-hdd.service

[Service]
Type=oneshot
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=Message brocker Service
Requires=docker.service
After=docker.service
After=mount-hdd.service

[Service]
Type=oneshot
Expand Down
14 changes: 14 additions & 0 deletions config/examples/etc/systemd/services/mount-hdd.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[Unit]
Description=Mount HDD disc
Requires=docker.service
After=docker.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=mount -t ntfs /dev/sdb1 /home/dima/media/workdir/mediadata/hdd/
#ExecStop=umount /dev/sdb1
TimeoutStartSec=0

[Install]
WantedBy=default.target
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[Unit]
Description=Torent client Service
Requires=docker.service
After=docker.service
After=mount-hdd.service

[Service]
Type=oneshot
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,23 @@
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;

import static com.halushko.kinocat.core.rabbit.SmartJson.KEYS.*;
@Slf4j
public class UserMessageHandler extends InputMessageHandler {
private static final String FILE_URL_PREFIX = String.format("%s%s/", "https://api.telegram.org/file/bot", System.getenv("BOT_TOKEN"));
private final static String FILE_URL_PREFIX = String.format("%s%s/", "https://api.telegram.org/file/bot", System.getenv("BOT_TOKEN"));

@SuppressWarnings("unchecked")
private final static Set<String> folders = new LinkedHashSet<>() {{
new SmartJson(System.getenv("TORRENT_IP"))
.convertToList()
.stream()
.map((x -> (Map<String, Object>) x))
.forEach(x -> add(String.valueOf(x.getOrDefault("name", "default"))));
}};

@Override
protected String getDeliverCallbackPrivate(SmartJson rabbitMessage) {
Expand All @@ -41,9 +53,12 @@ protected void handleTorrent(SmartJson rm) throws MalformedURLException {
long userId = rm.getUserId();
String fileName = String.format("%s%s", rm.getValue(FILE_ID), ".torrent");
String message = rm.getValue(TEXT);

File localFile = "hdd".equalsIgnoreCase(message) ? new File("/home/torrent_files_hdd/" + fileName) : new File("/home/torrent_files/" + fileName);

if(message == null || message.trim().isEmpty()) {
message = "";
} else if(folders.contains(message.trim())){
message = "_" + message.trim();
}
File localFile = new File(String.format("/home/torrent_files%s/%s", message, fileName));
try (InputStream is = fileUrl.openStream()) {
FileUtils.copyInputStreamToFile(is, localFile);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected final String getDeliverCallbackPrivate(SmartJson message) {
output.append(printResult(chatId, sb.toString()));
} else {
log.debug("[getDeliverCallbackPrivate] Result is empty");
output.append(printResult(chatId, "Нажаль результат запиту порожній"));
output.append(printResult(chatId, String.format("%s: Нажаль результат запиту порожній", session.getKey())));
}
} else {
String errorText = String.format("Server: %s result of request is: %s", session.getKey(), responceBody);
Expand Down

0 comments on commit dd0ea91

Please sign in to comment.