From 6f2cf5a843ff817f4e43b958cbeb11216bcb40a4 Mon Sep 17 00:00:00 2001 From: "stephane.david" Date: Thu, 14 Nov 2024 17:32:31 +0100 Subject: [PATCH] Initial --- src/DownloadList.java | 19 +++++----- src/Main.java | 83 +++++++++++++++++++++++++++++-------------- src/TorrentList.java | 12 +++++-- 3 files changed, 74 insertions(+), 40 deletions(-) diff --git a/src/DownloadList.java b/src/DownloadList.java index bcf8abd..90ed03c 100644 --- a/src/DownloadList.java +++ b/src/DownloadList.java @@ -13,26 +13,23 @@ public class DownloadList { { 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); + for (File fileNiv2 : fileNiv1.listFiles()) { + if (fileNiv2.isDirectory() && !fileNiv2.getName().equals("Screens")) { + downloadList.add(fileNiv2); + if (fileNiv2.isDirectory()) { + for (File fileNiv3 : fileNiv2.listFiles()) { + if (!fileNiv3.getName().equals("Screens") && fileNiv3.isDirectory()) { + downloadList.add(fileNiv3); } } } } } - }//System.out.println("Dir :"+file.getName()); } + downloadList.add(fileNiv1); } //for (File file:downloadList // ) { diff --git a/src/Main.java b/src/Main.java index 243cebe..81d2070 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,45 +1,74 @@ import java.io.File; import java.io.IOException; +import java.lang.reflect.Array; 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<>(); + static ArrayList orphanDownloadedTorrentList = new ArrayList<>(); + static TorrentList transmission = new TorrentList(); + static DownloadList drive = new DownloadList(); + static ArrayList downloadedTorrentFiles = new ArrayList<>(); + static ArrayList copiedTorrentFiles = new ArrayList<>(); + static ArrayList notCopiedTorrentFiles = new ArrayList<>(); + static ArrayList notCopiedPreferedTorrentFiles = new ArrayList<>(); + static String[] preferedfiles = {"tushy","blacked","blackedraw","tushyraw","bangbus","woodmancasting","private"}; + + static boolean find; + 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"); + /* Vide la liste des torrent orphelins */ + orphanDownloadedTorrentList.clear(); + /* Construit la liste des torrents téléchargés */ + System.out.println("Création de la liste des torrents téléchargés"); + downloadedTorrentFiles = drive.RequestList("\\F:\\var\\lib\\transmission-daemon\\downloads"); + /* Construit la liste des torrents copiés */ + System.out.println("Création de la liste des torrents copiés"); + copiedTorrentFiles = drive.RequestList("\\\\dartydisk6\\downloads"); + /* Construit la liste des torrents actifs */ + System.out.println("Création de la liste des torrents actifs"); + ArrayList activeTorrentList = transmission.RequestList(); + /* Etablit la liste des torrents téléchargés mais plus actifs */ + System.out.println("Création de la liste des torrents orphelins"); + for (File file: downloadedTorrentFiles) { + if (!transmission.FindTorrentByName(file.getName())) { + orphanDownloadedTorrentList.add(file); + } + } + orphanDownloadedTorrentList.forEach(file -> { + System.out.println("Orphean :" + file.getAbsolutePath()); + System.out.println("sudo rm -R \""+file.getName()+"\""); + }); - orphanList.forEach(file -> { - for (File file2 : copiedFiles) { - if (file.getName().equals(file2.getName())) { - break; + /* Etablit la liste des torrents téléchargés pas copiés */ + System.out.println("Création de la liste des torrents à copier"); + for (File file: downloadedTorrentFiles) { + find = false; + for (File copiedFile : copiedTorrentFiles) { + if (file.getName().equals(copiedFile.getName())) { + find = true; } } - System.out.println("Orphean :" + file.getName()); + if (!find) { + notCopiedTorrentFiles.add(file); + for (String name : preferedfiles) { + if (file.getName().toLowerCase().contains(name)) { + notCopiedPreferedTorrentFiles.add(file); + } + } + } + } + + notCopiedTorrentFiles.forEach(file -> { + System.out.println("Not Copied :" + file.getAbsolutePath()); + }); + notCopiedPreferedTorrentFiles.forEach(file -> { + System.out.println("Not Copied Prefered :" + file.getAbsolutePath()); }); } - 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/TorrentList.java b/src/TorrentList.java index 00be1d5..b9d322f 100644 --- a/src/TorrentList.java +++ b/src/TorrentList.java @@ -6,7 +6,7 @@ import java.util.ArrayList; public class TorrentList { ArrayList torrentArrayList = new ArrayList<>(); - ArrayList RequestList() throws IOException, InterruptedException { + 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() { @@ -48,7 +48,7 @@ public class TorrentList { //System.out.println(e); return; } - Torrent e = new Torrent("name", "status", "ratio"); + Torrent e = new Torrent(name, status, ratio); this.torrentArrayList.add(e); //this.torrentArrayList.set(i, new Torrent("name", "status", "ratio")); //System.out.println(line); @@ -56,5 +56,13 @@ public class TorrentList { //System.out.println(status); //System.out.println(ratio); } + boolean FindTorrentByName (String name) { + for (Torrent torrent : this.torrentArrayList) { + if(torrent.name.equals(name)) { + return true; + } + } + return false; + } }