Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.19.1 #51

Merged
merged 6 commits into from
Jul 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 9 additions & 0 deletions config/examples/docker-compose/start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ while (( "$#" )); do
-tt) start_torrent; keys_specified=true ;;
-th) start_torrent_hdd; keys_specified=true ;;
-tl) start_torrent_low; keys_specified=true ;;
-h) echo "Tool for kino-cat docker-containers start:" ;
echo " -h print help" ;
echo " -r start broker" :
echo " -m start media" ;
echo " -b start bot" ;
echo " -t start all torrent clients";
echo " -tt start main torrent client";
echo " -th start HDD torrent client";
echo " -tl start Low torrent client"; keys_specified=true ;;
*) echo "Unexpected key: $1" >&2; exit 1 ;;
esac
shift
Expand Down
9 changes: 9 additions & 0 deletions config/examples/docker-compose/stop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ while (( "$#" )); do
-th) stop_torrent_hdd; keys_specified=true ;;
-tl) stop_torrent_low; keys_specified=true ;;
-t) stop_torrent; stop_torrent_hdd; stop_torrent_low; keys_specified=true ;;
-h) echo "Tool for kino-cat docker-containers stop:" ;
echo " -h print help" ;
echo " -r stop broker" :
echo " -m stop media" ;
echo " -b stop bot" ;
echo " -t stop all torrent clients";
echo " -tt stop main torrent client";
echo " -th stop HDD torrent client";
echo " -tl stop Low torrent client"; keys_specified=true ;;
*) echo "Unexpected key: $1" >&2; exit 1 ;;
esac
shift
Expand Down
21 changes: 7 additions & 14 deletions config/examples/docker-compose/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,20 @@ update_torrent() {
/usr/bin/docker-compose -f /home/dima/media/docker-compose-torrent.yml pull
}

update_torrent_hdd() {
/usr/bin/docker-compose -f /home/dima/media/docker-compose-torrent-hdd.yml pull
}

update_torrent_low() {
/usr/bin/docker-compose -f /home/dima/media/docker-compose-torrent-low.yml pull
}

keys_specified=false

while (( "$#" )); do
case "$1" in
-r) update_broker; keys_specified=true ;;
-m) update_media; keys_specified=true ;;
-b) update_bot; keys_specified=true ;;
-t) update_torrent; update_torrent_hdd; update_torrent_low; keys_specified=true ;;
-tt) update_torrent; keys_specified=true ;;
-th) update_torrent_hdd; keys_specified=true ;;
-tl) update_torrent_low; keys_specified=true ;;
-t) update_torrent; keys_specified=true ;;
-h) echo "Tool for kino-cat docker-containers pull:" ;
echo " -h print help" ;
echo " -r update broker" :
echo " -m update media" ;
echo " -b update bot" ;
echo " -t update torrent clients"; keys_specified=true ;;
*) echo "Unexpected key: $1" >&2; exit 1 ;;
esac
shift
Expand All @@ -45,8 +40,6 @@ if ! $keys_specified; then
update_media
update_bot
update_torrent
update_torrent_hdd
update_torrent_low
fi

echo "All images files have been updated."
1 change: 1 addition & 0 deletions core/src/main/java/com/halushko/kinocat/core/Queues.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface Torrent {
String DELETE = "EXECUTE_TORRENT_COMMAND_DELETE";
String DELETE_ONLY_TORRENT = "EXECUTE_TORRENT_COMMAND_DELETE_ONLY_TORRENT";
String DELETE_WITH_FILES = "EXECUTE_TORRENT_COMMAND_DELETE_WITH_FILES";
String SEARCH_BY_NAME = "EXECUTE_TORRENT_COMMAND_SEARCH_BY_NAME";
}

interface Text {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ private void getDeliverCallbackLog(SmartJson message) {
log.debug("[InputMessageHandler] Finish processing with result: {}", result);
}

protected String printResult(long chatId, String text){
protected String printResult(long chatId, String text) {
String replacedString = text.replaceAll(OUTPUT_SEPARATOR + "(?=" + OUTPUT_SEPARATOR + ")", ",");
RabbitUtils.postMessage(chatId, replacedString, Queues.Telegram.TELEGRAM_OUTPUT_TEXT);
return replacedString;
}

@SuppressWarnings("unused")
protected void executePostAction(SmartJson input, String output){
protected void executePostAction(SmartJson input, String output) {
}

protected abstract String getDeliverCallbackPrivate(SmartJson message);
Expand Down
6 changes: 6 additions & 0 deletions text/src/main/java/com/halushko/kinocat/text/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,12 @@ public interface Constants {
CommandProperties.CONTAINS_SERVER_NUMBER
);

addValue("<текст>",
Queues.Torrent.SEARCH_BY_NAME,
"шукати токент за назвою",
CommandProperties.EMPTY_INSTANCE
);

addValue(Commands.Text.HELP,
Queues.Text.HELP,
"вивести інформацію по всім командам"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import com.halushko.kinocat.text.commands.CommandProperties;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class UserTextMessageHandler extends InputMessageHandler {
@Override
Expand All @@ -20,23 +23,39 @@ protected String getDeliverCallbackPrivate(SmartJson rabbitMessage) {
long userId = rabbitMessage.getUserId();
log.debug("[UserMessageHandler] user_id={} text={}", userId, text);
Command command = Constants.COMMANDS_COLLECTION.getCommand(text);
log.debug("[UserMessageHandler] Command: queue={}, arguments={}", command.getQueue(), command.getArguments());

SmartJson message = new SmartJson(userId).addValue(SmartJsonKeys.COMMAND_ARGUMENTS, command.getArguments());
List<String> arguments;
String queue;
boolean isSearchCommand = command.getCommand().trim().isEmpty();

if(command.getAdditionalProperties().contains(CommandProperties.EMPTY_INSTANCE)){
message.addValue(SmartJsonKeys.TEXT, "Такої команди не знайдено");
if (isSearchCommand) {
arguments = new ArrayList<>() {{
add(text);
}};
queue = Queues.Torrent.SEARCH_BY_NAME;
} else {
arguments = command.getArguments();
queue = command.getQueue();
}
if(command.getAdditionalProperties().contains(CommandProperties.CONTAINS_SERVER_NUMBER) && !command.getArguments().isEmpty()){
String serverNumber = command.getArguments().get(0);
try {
Integer.parseInt(serverNumber);
message.addValue(SmartJsonKeys.SELECT_SERVER, serverNumber);
} catch (NumberFormatException ignored) {

log.debug("[UserMessageHandler] Command: queue={}, arguments={}", queue, arguments);
SmartJson message = new SmartJson(userId).addValue(SmartJsonKeys.COMMAND_ARGUMENTS, arguments);

if (!isSearchCommand) {
if (command.getAdditionalProperties().contains(CommandProperties.EMPTY_INSTANCE)) {
message.addValue(SmartJsonKeys.TEXT, "Такої команди не знайдено");
}
if (command.getAdditionalProperties().contains(CommandProperties.CONTAINS_SERVER_NUMBER) && !command.getArguments().isEmpty()) {
String serverNumber = command.getArguments().get(0);
try {
Integer.parseInt(serverNumber);
message.addValue(SmartJsonKeys.SELECT_SERVER, serverNumber);
} catch (NumberFormatException ignored) {
}
}
}

RabbitUtils.postMessage(message, command.getQueue());
RabbitUtils.postMessage(message, queue);

log.debug("[UserMessageHandler] Finish DeliverCallbackPrivate for {}", getQueue());
} catch (Exception e) {
log.error("[UserMessageHandler] During message handle got an error: ", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static void main(String[] args) {
new RemoveTorrentCommand().run();
new PrintTorrentCommands().run();
new TorrentsList().run();
new SearchByName().run();

new PauseAll().run();
new ResumeAll().run();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,17 @@ protected HashSet<Integer> getNotRequestArgumentIndexes() {
protected Predicate<? super TorrentEntity> getSmartFilter(List<String> arguments) {
return element -> true;
}

protected static String constructProgressBar(int blocks, int blackBlocks) {
StringBuilder line = new StringBuilder();

IntStream.range(0, blackBlocks).mapToObj(i -> "█").forEach(line::append);
if (blackBlocks < blocks) {
line.append("▒");
}
if (blackBlocks + 1 < blocks) {
IntStream.range(blackBlocks + 1, blocks).mapToObj(i -> "░").forEach(line::append);
}
return line.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ protected final String getDeliverCallbackPrivate(SmartJson message) {
StringBuilder output = new StringBuilder();

analyzeServer(message, serversToApply, output, chatId);

for (val serverNumber : serversToApply) {
String serverName = serverNames.get(serverNumber);

Expand All @@ -54,7 +53,7 @@ protected final String getDeliverCallbackPrivate(SmartJson message) {
if (i == 1 || i % 10 == 0) {
log.debug("[getDeliverCallbackPrivate] New message created");
if (sb != null) {
log.debug("[getDeliverCallbackPrivate] Print result:\n{}", sb);
log.debug("[getDeliverCallbackPrivate] Print result internal:\n{}", sb);
output.append(printResult(chatId, sb.toString())).append(OUTPUT_SEPARATOR);
}
sb = new StringBuilder();
Expand All @@ -69,7 +68,7 @@ protected final String getDeliverCallbackPrivate(SmartJson message) {
log.debug("[getDeliverCallbackPrivate] Message:\n{}", sb);
}
if (sb != null) {
log.debug("[getDeliverCallbackPrivate] Print result:\n{}", sb);
log.debug("[getDeliverCallbackPrivate] Print result last:\n{}", sb);
output.append(printResult(chatId, sb.toString()));
} else {
log.debug("[getDeliverCallbackPrivate] Result is empty");
Expand Down Expand Up @@ -127,7 +126,7 @@ private void generateSessionId(String serverNumber, String serverName) {
}
}

private void analyzeServer(SmartJson message, List<String> serversToApply, StringBuilder output, long chatId) {
protected void analyzeServer(SmartJson message, List<String> serversToApply, StringBuilder output, long chatId) {
String selectedServer = message.getValue(SmartJsonKeys.SELECT_SERVER);
if(!selectedServer.isEmpty()) {
try {
Expand Down Expand Up @@ -176,5 +175,4 @@ protected String getDefaultPort() {
protected String getDefaultSuffix() {
return "transmission/rpc";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.halushko.kinocat.torrent.entities.TorrentEntity;
import com.halushko.kinocat.torrent.requests.common.GetTorrent;

import java.util.stream.IntStream;

public class FilesList extends GetTorrent {

@Override
Expand Down Expand Up @@ -42,19 +40,9 @@ protected String getProgressBar(SubTorrentEntity torrent) {
long completed = torrent.getBytesCompleted();
long full = torrent.getLength();
double percents = (double) completed / full;

int blackBlocks = (int) (percents * blocks);
StringBuilder line = new StringBuilder();

IntStream.range(0, blackBlocks).mapToObj(i -> "█").forEach(line::append);

if(blackBlocks < blocks) {
line.append("▒");
}
if(blackBlocks + 1 < blocks) {
IntStream.range(blackBlocks + 1, blocks).mapToObj(i -> "░").forEach(line::append);
}
return line.toString();
return constructProgressBar(blocks, blackBlocks);
}

protected String getFolderText(SubTorrentEntity previousFile, SubTorrentEntity currentFile) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.halushko.kinocat.torrent.requests.concrete;

import com.halushko.kinocat.core.Queues;
import com.halushko.kinocat.torrent.entities.TorrentEntity;

import java.util.List;
import java.util.function.Predicate;

public class SearchByName extends TorrentsList {
private final static String SYMBOLS_TO_IGNORE = "[\\s._\"']";

@Override
protected String getQueue() {
return Queues.Torrent.SEARCH_BY_NAME;
}

@Override
protected Predicate<? super TorrentEntity> getSmartFilter(List<String> arguments) {
return element -> arguments.isEmpty()
|| (arguments.size() == 1 && serverNames.containsKey(arguments.get(0)))
|| arguments
.stream()
.anyMatch(a -> ignoreSymbols(element.getName().toUpperCase())
.contains(ignoreSymbols(a).toUpperCase())
);
}

private String ignoreSymbols(String str) {
return str.replaceAll(SYMBOLS_TO_IGNORE, "");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,8 @@
import com.halushko.kinocat.torrent.requests.common.GetTorrent;
import lombok.extern.slf4j.Slf4j;

import java.util.List;
import java.util.function.Predicate;
import java.util.stream.IntStream;

@Slf4j
public class TorrentsList extends GetTorrent {
private final static String SYMBOLS_TO_IGNORE = "[\\s._\"']";

public TorrentsList() {
super();
}
Expand All @@ -31,17 +25,7 @@ protected String generateAnswer(TorrentEntity torrent, String serverNumber, Stri
protected String getProgressBar(TorrentEntity torrent) {
int blocks = 20;
int blackBlocks = (int) (torrent.getPercentDone() * blocks);
StringBuilder line = new StringBuilder();

IntStream.range(0, blackBlocks).mapToObj(i -> "█").forEach(line::append);
if (blackBlocks < blocks) {
line.append("▒");
}
if (blackBlocks + 1 < blocks) {
IntStream.range(blackBlocks + 1, blocks).mapToObj(i -> "░").forEach(line::append);
}

return "||" + line + "||";
return "||" + constructProgressBar(blocks, blackBlocks) + "||";
}

protected String getGigabytesLeft(TorrentEntity torrent) {
Expand Down Expand Up @@ -77,19 +61,4 @@ protected String getRequest() {
protected String textOfMessageBegin() {
return "Торенти ";
}

@Override
protected Predicate<? super TorrentEntity> getSmartFilter(List<String> arguments) {
return element -> arguments.isEmpty()
|| (arguments.size() == 1 && serverNames.containsKey(arguments.get(0)))
|| arguments
.stream()
.anyMatch(a -> ignoreSymbols(element.getName().toUpperCase())
.contains(ignoreSymbols(a).toUpperCase())
);
}

private String ignoreSymbols(String str) {
return str.replaceAll(SYMBOLS_TO_IGNORE, "");
}
}
4 changes: 2 additions & 2 deletions versions.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
### 1.18.1
- add auto generation of transmission configs after ENV files edition
- fix /list_<number> command
### 1.19 (alpha/latest)
### 1.19 (latest)
- fix percents in /list
- add one start/stop script
- fix access of unauthorized users
### 1.19.1 (beta)
### 1.19.1 (alpha/beta)
- change search, remove it from /list
## 1.20 Planning (_TODO_)
- fix error `build_core / build_core The 'save-state' command is deprecated and will be disabled soon. Please upgrade to using Environment Files. For more information see: https://github.blog/changelog/2022-10-11-github-actions-deprecating-save-state-and-set-output-commands/`
Expand Down
Loading