-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
galushko
committed
Feb 20, 2024
1 parent
64325fc
commit 4292b6a
Showing
18 changed files
with
206 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
file/src/main/java/com/halushko/kinocat/file/Constants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.halushko.kinocat.file; | ||
|
||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
|
||
public interface Constants { | ||
String PATH_TO_UNAPPROVED_FOLDER = "/tmp/unapproved"; | ||
String PATH_TO_DESTINATION_FOLDER = "/home/torrent_files"; | ||
String EMPTY_SERVICE_DEFAULT_NAME = "main"; | ||
Map<String, String> FOLDERS = new FoldersProcessor(System.getenv("TORRENT_IP")) | ||
.values.keySet().stream() | ||
.collect(Collectors.toMap(key -> key, key -> String.format(PATH_TO_DESTINATION_FOLDER + "%s", !key.isEmpty() ? "_" + key : ""))); | ||
String NAME_LINE = "^\\s+Name:\\s+"; | ||
String SIZE_LINE = "^\\s+Total Size:\\s+"; | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
file/src/main/java/com/halushko/kinocat/file/FoldersProcessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.halushko.kinocat.file; | ||
|
||
import com.halushko.kinocat.core.JsonConstants; | ||
import com.halushko.kinocat.core.prcessors.ServicesInfoProcessor; | ||
import com.halushko.kinocat.core.prcessors.ValueProcessor; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class FoldersProcessor extends ServicesInfoProcessor { | ||
|
||
public FoldersProcessor(String json) { | ||
super(json); | ||
} | ||
|
||
@Override | ||
public ValueProcessor getNameProcessor() { | ||
return new ValueProcessor(JsonConstants.WebKeys.KEY_NAME, ""); | ||
} | ||
|
||
@Override | ||
public List<ValueProcessor> getServiceProcessors() { | ||
return new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
public String getUrlTemplate() { | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
file/src/main/java/com/halushko/kinocat/file/MoveToDestinationFolder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.halushko.kinocat.file; | ||
|
||
import com.halushko.kinocat.core.JsonConstants.SmartJsonKeys; | ||
import com.halushko.kinocat.core.Queues; | ||
import com.halushko.kinocat.core.handlers.input.CliCommandExecutor; | ||
import com.halushko.kinocat.core.rabbit.SmartJson; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@Slf4j | ||
public class MoveToDestinationFolder extends CliCommandExecutor { | ||
@Override | ||
protected String getQueue() { | ||
return Queues.File.MOVE_TO_FOLDER; | ||
} | ||
|
||
@Override | ||
protected String getScript(SmartJson rabbitMessage) { | ||
List<Object> arguments = rabbitMessage.getSubMessage(SmartJsonKeys.COMMAND_ARGUMENTS).convertToList(); | ||
String folder = (String) arguments.get(0); | ||
String file = (String) arguments.get(1); | ||
|
||
return String.format("mv -f %s/%s.torrent %s/%s.torrent", | ||
Constants.PATH_TO_UNAPPROVED_FOLDER, | ||
file, | ||
Constants.FOLDERS.get(folder), | ||
UUID.randomUUID() | ||
); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
file/src/main/java/com/halushko/kinocat/file/PrintDestinations.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.halushko.kinocat.file; | ||
|
||
import com.halushko.kinocat.core.Commands; | ||
import com.halushko.kinocat.core.JsonConstants.SmartJsonKeys; | ||
import com.halushko.kinocat.core.Queues; | ||
import com.halushko.kinocat.core.handlers.input.CliCommandExecutor; | ||
import com.halushko.kinocat.core.rabbit.SmartJson; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Slf4j | ||
public class PrintDestinations extends CliCommandExecutor { | ||
@Override | ||
protected String getResultString(List<String> lines, SmartJson rabbitMessage) { | ||
String[] result = new String[4]; | ||
result[0] = "("; | ||
result[2] = ") "; | ||
for (String line : lines) { | ||
if (line.matches(Constants.NAME_LINE)) { | ||
result[3] = line.replaceFirst(Constants.NAME_LINE, ""); | ||
} | ||
if (line.matches(Constants.SIZE_LINE)) { | ||
result[1] = line.replaceFirst(Constants.SIZE_LINE, ""); | ||
} | ||
} | ||
String fileName = rabbitMessage.getValue(SmartJsonKeys.FILE_ID).replaceAll("\\.torrent$", ""); | ||
return String.format("%s%s", | ||
String.join("", result), | ||
Constants.FOLDERS.keySet().stream() | ||
.map(folder -> | ||
String.format("\\n%s: %s_%s_%s", | ||
getServiceLable(folder), | ||
Commands.File.SELECT_DESTINATION, | ||
getServiceLable(folder), | ||
fileName | ||
) | ||
) | ||
.collect(Collectors.joining("")) | ||
); | ||
} | ||
|
||
private static String getServiceLable(String folder) { | ||
return folder.isEmpty() ? Constants.EMPTY_SERVICE_DEFAULT_NAME : folder; | ||
} | ||
|
||
@Override | ||
protected String getQueue() { | ||
return Queues.File.CHOOSE_THE_DESTINATION; | ||
} | ||
|
||
@Override | ||
protected String getScript(SmartJson rabbitMessage) { | ||
return String.format("transmission-show %s", rabbitMessage.getValue(SmartJsonKeys.FILE_PATH)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.