From 8fca6d5a887abba24d7c3e95d09a28c348f36a66 Mon Sep 17 00:00:00 2001 From: "stephane.david" Date: Tue, 20 Jun 2023 21:59:29 +0200 Subject: [PATCH] Initial --- .gitignore | 29 +++++++++++++ .idea/.gitignore | 3 ++ .idea/libraries/commons_io_2_13_0.xml | 15 +++++++ .idea/misc.xml | 6 +++ .idea/modules.xml | 8 ++++ ManageTorrent.iml | 12 ++++++ src/Download.java | 5 +++ src/DownloadList.java | 46 ++++++++++++++++++++ src/Main.java | 45 ++++++++++++++++++++ src/Torrent.java | 12 ++++++ src/TorrentList.java | 60 +++++++++++++++++++++++++++ 11 files changed, 241 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/libraries/commons_io_2_13_0.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 ManageTorrent.iml create mode 100644 src/Download.java create mode 100644 src/DownloadList.java create mode 100644 src/Main.java create mode 100644 src/Torrent.java create mode 100644 src/TorrentList.java diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f68d109 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +### IntelliJ IDEA ### +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/.idea/libraries/commons_io_2_13_0.xml b/.idea/libraries/commons_io_2_13_0.xml new file mode 100644 index 0000000..e487156 --- /dev/null +++ b/.idea/libraries/commons_io_2_13_0.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2a824a2 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..d1a6319 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/ManageTorrent.iml b/ManageTorrent.iml new file mode 100644 index 0000000..024fd23 --- /dev/null +++ b/ManageTorrent.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Download.java b/src/Download.java new file mode 100644 index 0000000..7ee7773 --- /dev/null +++ b/src/Download.java @@ -0,0 +1,5 @@ +public class Download { + String name; + + +} diff --git a/src/DownloadList.java b/src/DownloadList.java new file mode 100644 index 0000000..bcf8abd --- /dev/null +++ b/src/DownloadList.java @@ -0,0 +1,46 @@ +import java.util.ArrayList; +import java.io.File; + + +public class DownloadList { + private ArrayList downloadList; + + ArrayList RequestList(String path) + { + File parentDirectory = new File(path); + downloadList = new ArrayList<>(); + if (parentDirectory.exists() && parentDirectory.isDirectory()) + { + for (File fileNiv1: parentDirectory.listFiles()) + { + //files.add(file); + if (fileNiv1.isDirectory()) + { + downloadList.add(fileNiv1); + if (fileNiv1.isDirectory()) { + for (File directoryNiv1 : fileNiv1.listFiles()) { + if (directoryNiv1.isDirectory() && !directoryNiv1.getName().equals("Screens")) { + downloadList.add(directoryNiv1); + if (directoryNiv1.isDirectory()) { + for (File fileNiv2 : directoryNiv1.listFiles()) { + if (!fileNiv2.getName().equals("Screens") && fileNiv2.isDirectory()) { + downloadList.add(fileNiv2); + } + } + } + } + } + + }//System.out.println("Dir :"+file.getName()); + } + } + //for (File file:downloadList + // ) { + // System.out.println(file.getName()); + //} + //System.out.println(files[0].getName()); + } + return downloadList; + } +} + diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..243cebe --- /dev/null +++ b/src/Main.java @@ -0,0 +1,45 @@ +import java.io.File; +import java.io.IOException; +import java.util.ArrayList; + +public class Main { + + static ArrayList orphanList = new ArrayList<>(); + static TorrentList torrentList = new TorrentList(); + static DownloadList downloadList = new DownloadList(); + static DownloadList copiedList = new DownloadList(); + static ArrayList downloadedFiles = new ArrayList<>(); + + public static void main(String[] args) throws IOException, InterruptedException { + System.out.println("ManageTorrent by SDA Corporation"); + orphanList.clear(); + downloadedFiles = downloadList.RequestList("\\F:\\var\\lib\\transmission-daemon\\downloads"); + ArrayList copiedFiles = copiedList.RequestList("\\\\dartydisk6\\downloads"); + + + + orphanList.forEach(file -> { + for (File file2 : copiedFiles) { + if (file.getName().equals(file2.getName())) { + break; + } + } + System.out.println("Orphean :" + file.getName()); + }); + } + + public void ListTorrents() throws IOException, InterruptedException { + ArrayList torrentDownloadedList = torrentList.RequestList(); + + for (File file:downloadedFiles + ) { + for (Torrent torrent:torrentDownloadedList + ) { + if (file.getName().equals(torrent.name)) { + break; + } + } + orphanList.add(file); + } + } +} \ No newline at end of file diff --git a/src/Torrent.java b/src/Torrent.java new file mode 100644 index 0000000..a97d178 --- /dev/null +++ b/src/Torrent.java @@ -0,0 +1,12 @@ +public class Torrent { + String name; + String status; + String ratio; + + + public Torrent(String name, String status, String ratio) { + this.name = name; + this.status = status; + this.ratio = ratio; + } +} diff --git a/src/TorrentList.java b/src/TorrentList.java new file mode 100644 index 0000000..00be1d5 --- /dev/null +++ b/src/TorrentList.java @@ -0,0 +1,60 @@ +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; + +public class TorrentList { + ArrayList torrentArrayList = new ArrayList<>(); + + ArrayList RequestList() throws IOException, InterruptedException { + final Process p = Runtime.getRuntime().exec("cmd /c C:\\PROGRA~1\\Transmission\\transmission-remote.exe seedbox.sda.zone:19091 -l"); + + new Thread(new Runnable() { + public void run() { + BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream())); + String line = null; + Integer i=0; + try { + while ((line = input.readLine()) != null) + AddTorrentToList(line,i); + } catch (IOException e) { + e.printStackTrace(); + } + i++; + } + }).start(); + p.waitFor(); + return this.torrentArrayList; + } + void AddTorrentToList(String line, Integer i) { + String name = null; + String ratio = null; + String status = null; + try { + ratio = line.substring(51,58); + } catch (StringIndexOutOfBoundsException e) { + //System.out.println(e); + return; + } + try { + status = line.substring(59,65); + } catch (StringIndexOutOfBoundsException e) { + //System.out.println(e); + return; + } + try { + name = line.substring(72); + } catch (StringIndexOutOfBoundsException e) { + //System.out.println(e); + return; + } + Torrent e = new Torrent("name", "status", "ratio"); + this.torrentArrayList.add(e); + //this.torrentArrayList.set(i, new Torrent("name", "status", "ratio")); + //System.out.println(line); + //System.out.println(name + " " + status + " " + ratio); + //System.out.println(status); + //System.out.println(ratio); + } + +}