From a6e490a24c2881378b7d9366207ecb8d64adc4f1 Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Tue, 7 Nov 2023 00:36:37 +0530 Subject: [PATCH 01/14] Update Main.java added color in CLI text --- src/main/java/CLI/Main.java | 63 ++++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 29 deletions(-) diff --git a/src/main/java/CLI/Main.java b/src/main/java/CLI/Main.java index c2b149aaf..469d55102 100644 --- a/src/main/java/CLI/Main.java +++ b/src/main/java/CLI/Main.java @@ -42,14 +42,19 @@ public class Main { private static String batchDownloadingFile; private static final String MSG_FILE_EXISTS_NO_HISTORY = "\"%s\" exists in \"%s\" folder. It will be renamed to \"%s\"."; private static final String MSG_FILE_EXISTS_HAS_HISTORY = "You have previously downloaded \"%s\" and it exists in \"%s\" folder.\nDo you want to download it again? "; - + public static final String RESET = "\u001B[0m"; + public static final String BLUE = "\033[0;34m"; + public static final String YELLOW = "\u001B[33m"; + public static final String RED = "\u001B[31m"; + public static final String GREEN = "\u001B[32m"; + public static void main(String[] args) { LOGGER.log(MessageType.INFO, CLI_APPLICATION_STARTED); messageBroker = new MessageBroker(System.out); Environment.setMessageBroker(messageBroker); - messageBroker.msgInitInfo("Initializing environment..."); + messageBroker.msgInitInfo(GREEN+"Initializing environment..."+RESET); Environment.initializeEnvironment(); - messageBroker.msgInitInfo("Environment initialized successfully!"); + messageBroker.msgInitInfo(GREEN+"Environment initialized successfully!"+RESET); utility = new Utility(); jobHistory = AppSettings.GET.jobHistory(); printBanner(); @@ -77,7 +82,7 @@ public static void main(String[] args) { if (isURL(args[i])) { link = args[i]; } else { - messageBroker.msgInitError("Invalid argument(s) passed!"); + messageBroker.msgInitError(RED+"Invalid argument(s) passed!"+RESET); System.exit(1); } } @@ -89,7 +94,7 @@ public static void main(String[] args) { isUrlValid = Utility.isLinkValid(link); } else { isUrlValid = false; - messageBroker.msgLinkError("Link is invalid!"); + messageBroker.msgLinkError(RED+"Link is invalid!"+RESET); } if (isUrlValid) { isYoutubeURL = isYoutube(link); @@ -108,7 +113,7 @@ public static void main(String[] args) { link = link + "?utm_source=ig_embed"; } } - messageBroker.msgFilenameInfo("Retrieving filename from link..."); + messageBroker.msgFilenameInfo(GREEN+"Retrieving filename from link..."+RESET); fileName = findFilenameInLink(link); if (!fileName.isEmpty()) { Job job = new Job(link, downloadsFolder, fileName, false); @@ -133,7 +138,7 @@ public static void main(String[] args) { batchDownloadingFile = SC.next(); SC.nextLine(); if (!(batchDownloadingFile.endsWith(".yml") || batchDownloadingFile.endsWith(".yaml"))) { - messageBroker.msgBatchError("The data file should be a YAML file!"); + messageBroker.msgBatchError(RED+"The data file should be a YAML file!"+RESET); } else { batchDownloader(); break; @@ -153,7 +158,7 @@ public static void main(String[] args) { if (Utility.isURL(link)) { Utility.isLinkValid(link); } else { - messageBroker.msgLinkError("Link is invalid!"); + messageBroker.msgLinkError(RED+"Link is invalid!"+RESET); continue; } System.out.print("Download directory (\".\" for default or \"L\" for " + AppSettings.GET.lastDownloadFolder() + ") : "); @@ -172,7 +177,7 @@ public static void main(String[] args) { link = link + "?utm_source=ig_embed"; } } - messageBroker.msgFilenameInfo("Retrieving filename from link..."); + messageBroker.msgFilenameInfo(GREEN+"Retrieving filename from link..."+RESET); fileName = findFilenameInLink(link); if (!fileName.isEmpty()) { Job job = new Job(link, downloadsFolder, fileName, false); @@ -203,7 +208,7 @@ private static void printVersion() { } private static void handleSpotifyPlaylist() { - messageBroker.msgFilenameInfo("Retrieving the number of tracks in the playlist..."); + messageBroker.msgFilenameInfo(GREEN+"Retrieving the number of tracks in the playlist..."+RESET); LinkedList linkMetadataList = Utility.getLinkMetadata(link); String json = makePretty(linkMetadataList.get(0)); String playlistLengthRegex = "(\"list_length\": )(.+)"; @@ -212,9 +217,9 @@ private static void handleSpotifyPlaylist() { int numberOfSongs = 0; if (lengthMatcher.find()) { numberOfSongs = Integer.parseInt(lengthMatcher.group(2)); - messageBroker.msgFilenameInfo("Number of tracks in the playlist : " + numberOfSongs); + messageBroker.msgFilenameInfo(GREEN+"Number of tracks in the playlist : " + numberOfSongs+RESET); } else { - messageBroker.msgFilenameError("Failed to retrieve the number of tracks in the playlist!"); + messageBroker.msgFilenameError(GREEN+"Failed to retrieve the number of tracks in the playlist!"+RESET); } for (int i = 0; i < numberOfSongs; i++) { messageBroker.msgStyleInfo(BANNER_BORDER); @@ -224,20 +229,20 @@ private static void handleSpotifyPlaylist() { if (linkMatcher.find(i)) { link = linkMatcher.group(2); } else { - messageBroker.msgLinkError("Failed to retrieve link from playlist!"); + messageBroker.msgLinkError(RED+"Failed to retrieve link from playlist!"+RESET); continue; } - messageBroker.msgLinkInfo("[" + (i + 1) + "/" + numberOfSongs + "] " + "Processing link : " + link); + messageBroker.msgLinkInfo(GREEN+"[" + (i + 1) + "/" + numberOfSongs + "] " + "Processing link : " + link+RESET); if (fileName != null) { String filenameRegex = "(\"name\": \")(.+)(\",)"; Pattern filenamePattern = Pattern.compile(filenameRegex); Matcher filenameMatcher = filenamePattern.matcher(json); if (filenameMatcher.find(i)) { fileName = cleanFilename(filenameMatcher.group(2)) + ".mp3"; - messageBroker.msgFilenameInfo(FILENAME_DETECTED + "\"" + fileName + "\""); + messageBroker.msgFilenameInfo(GREEN+FILENAME_DETECTED + "\"" + fileName + "\""+RESET); } else { fileName = cleanFilename("Unknown_Filename_") + randomString(15) + ".mp3"; - messageBroker.msgFilenameError(FILENAME_DETECTION_ERROR); + messageBroker.msgFilenameError(RED+FILENAME_DETECTION_ERROR+RESET); } } Job job = new Job(link, downloadsFolder, fileName, false); @@ -248,22 +253,22 @@ private static void handleSpotifyPlaylist() { private static void batchDownloader() { Yaml yamlParser = new Yaml(); try { - messageBroker.msgLogInfo("Trying to load YAML data file (" + batchDownloadingFile + ") ..."); + messageBroker.msgLogInfo(GREEN+"Trying to load YAML data file (" + batchDownloadingFile + ") ..."+RESET); InputStreamReader yamlDataFile = new InputStreamReader(new FileInputStream(batchDownloadingFile)); Map> data = yamlParser.load(yamlDataFile); - messageBroker.msgLogInfo("YAML data file (" + batchDownloadingFile + ") loaded successfully"); + messageBroker.msgLogInfo(GREEN+"YAML data file (" + batchDownloadingFile + ") loaded successfully"+RESET); int numberOfLinks; try { numberOfLinks = data.get("links").size(); } catch (NullPointerException e) { - messageBroker.msgLinkInfo("No links specified. Exiting..."); + messageBroker.msgLinkInfo(GREEN+"No links specified. Exiting..."+RESET); return; } int numberOfFileNames; if (data.containsKey("fileNames")) { numberOfFileNames = data.get("fileNames").size(); } else { - messageBroker.msgFilenameInfo("No filename specified. Filename will be retrieved from the link."); + messageBroker.msgFilenameInfo(GREEN+"No filename specified. Filename will be retrieved from the link."+RESET); numberOfFileNames = 0; } int numberOfDirectories; @@ -277,7 +282,7 @@ private static void batchDownloader() { } else if (data.containsKey("directories")) { numberOfDirectories = data.get("directories").size(); } else { - messageBroker.msgDirInfo("No directory specified. Default downloads folder will be used."); + messageBroker.msgDirInfo(GREEN+"No directory specified. Default downloads folder will be used."+RESET); numberOfDirectories = 0; downloadsFolder = "."; } @@ -299,11 +304,11 @@ private static void batchDownloader() { } else { fileNameMessage = numberOfFileNames + " filenames"; } - messageBroker.msgBatchInfo("You have provided\n\t" + linkMessage + "\n\t" + directoryMessage + "\n\t" + fileNameMessage); + messageBroker.msgBatchInfo(GREEN+"You have provided\n\t" + linkMessage + "\n\t" + directoryMessage + "\n\t" + fileNameMessage+RESET); for (int i = 0; i < numberOfLinks; i++) { messageBroker.msgStyleInfo(BANNER_BORDER); link = data.get("links").get(i); - messageBroker.msgLinkInfo("[" + (i + 1) + "/" + numberOfLinks + "] " + "Processing link : " + link); + messageBroker.msgLinkInfo(GREEN+"[" + (i + 1) + "/" + numberOfLinks + "] " + "Processing link : " + link+RESET); isYoutubeURL = isYoutube(link); isInstagramLink = isInstagram(link); isSpotifyLink = isSpotify(link); @@ -331,7 +336,7 @@ private static void batchDownloader() { link = link + "?utm_source=ig_embed"; } } - messageBroker.msgFilenameInfo("Retrieving filename from link..."); + messageBroker.msgFilenameInfo(GREEN+"Retrieving filename from link..."+RESET); fileName = findFilenameInLink(link); if (!fileName.isEmpty()) { renameFilenameIfRequired(false); @@ -345,7 +350,7 @@ private static void batchDownloader() { checkHistoryAddJobsAndDownload(job, false); } } catch (FileNotFoundException e) { - messageBroker.msgDownloadError("YAML Data file (" + batchDownloadingFile + ") not found ! " + e.getMessage()); + messageBroker.msgDownloadError(RED+"YAML Data file (" + batchDownloadingFile + ") not found ! " + e.getMessage()+RESET); } } @@ -384,14 +389,14 @@ private static String getProperDownloadsFolder(String downloadsFolder) { } } if (new File(downloadsFolder).exists()) { - messageBroker.msgDirInfo("Download folder exists!"); + messageBroker.msgDirInfo(GREEN+"Download folder exists!"+RESET); } else { - messageBroker.msgDirError("Download folder does not exist!"); + messageBroker.msgDirError(RED+"Download folder does not exist!"+RESET); try { Files.createDirectory(Path.of(downloadsFolder)); - messageBroker.msgDirInfo("Download folder created successfully!"); + messageBroker.msgDirInfo(GREEN+"Download folder created successfully!"+RESET); } catch (IOException e) { - messageBroker.msgDirError("Failed to create download folder! " + e.getMessage()); + messageBroker.msgDirError(RED+"Failed to create download folder! " + e.getMessage()+RESET); } } AppSettings.SET.lastFolder(downloadsFolder); From 6ffcc02a3e03cb8a79a3f85f10d412b21c514393 Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Tue, 7 Nov 2023 09:29:27 +0530 Subject: [PATCH 02/14] Update Main.java trying to get rid of ES lint error by checkstyle From 20f113b184bc8ea5f1f0bc3e911a3c0336b22117 Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Tue, 7 Nov 2023 10:10:33 +0530 Subject: [PATCH 03/14] Update Main.java added white space in between added text for colour ex GREEN + insted of GREEN+ --- src/main/java/CLI/Main.java | 56 ++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/CLI/Main.java b/src/main/java/CLI/Main.java index 469d55102..47ae50d79 100644 --- a/src/main/java/CLI/Main.java +++ b/src/main/java/CLI/Main.java @@ -52,9 +52,9 @@ public static void main(String[] args) { LOGGER.log(MessageType.INFO, CLI_APPLICATION_STARTED); messageBroker = new MessageBroker(System.out); Environment.setMessageBroker(messageBroker); - messageBroker.msgInitInfo(GREEN+"Initializing environment..."+RESET); + messageBroker.msgInitInfo(GREEN +"Initializing environment..."+ RESET); Environment.initializeEnvironment(); - messageBroker.msgInitInfo(GREEN+"Environment initialized successfully!"+RESET); + messageBroker.msgInitInfo(GREEN +"Environment initialized successfully!"+ RESET); utility = new Utility(); jobHistory = AppSettings.GET.jobHistory(); printBanner(); @@ -82,7 +82,7 @@ public static void main(String[] args) { if (isURL(args[i])) { link = args[i]; } else { - messageBroker.msgInitError(RED+"Invalid argument(s) passed!"+RESET); + messageBroker.msgInitError(RED+"Invalid argument(s) passed!"+ RESET); System.exit(1); } } @@ -94,7 +94,7 @@ public static void main(String[] args) { isUrlValid = Utility.isLinkValid(link); } else { isUrlValid = false; - messageBroker.msgLinkError(RED+"Link is invalid!"+RESET); + messageBroker.msgLinkError(RED+"Link is invalid!"+ RESET); } if (isUrlValid) { isYoutubeURL = isYoutube(link); @@ -113,7 +113,7 @@ public static void main(String[] args) { link = link + "?utm_source=ig_embed"; } } - messageBroker.msgFilenameInfo(GREEN+"Retrieving filename from link..."+RESET); + messageBroker.msgFilenameInfo(GREEN +"Retrieving filename from link..."+ RESET); fileName = findFilenameInLink(link); if (!fileName.isEmpty()) { Job job = new Job(link, downloadsFolder, fileName, false); @@ -138,7 +138,7 @@ public static void main(String[] args) { batchDownloadingFile = SC.next(); SC.nextLine(); if (!(batchDownloadingFile.endsWith(".yml") || batchDownloadingFile.endsWith(".yaml"))) { - messageBroker.msgBatchError(RED+"The data file should be a YAML file!"+RESET); + messageBroker.msgBatchError(RED+"The data file should be a YAML file!"+ RESET); } else { batchDownloader(); break; @@ -158,7 +158,7 @@ public static void main(String[] args) { if (Utility.isURL(link)) { Utility.isLinkValid(link); } else { - messageBroker.msgLinkError(RED+"Link is invalid!"+RESET); + messageBroker.msgLinkError(RED+"Link is invalid!"+ RESET); continue; } System.out.print("Download directory (\".\" for default or \"L\" for " + AppSettings.GET.lastDownloadFolder() + ") : "); @@ -177,7 +177,7 @@ public static void main(String[] args) { link = link + "?utm_source=ig_embed"; } } - messageBroker.msgFilenameInfo(GREEN+"Retrieving filename from link..."+RESET); + messageBroker.msgFilenameInfo(GREEN +"Retrieving filename from link..."+ RESET); fileName = findFilenameInLink(link); if (!fileName.isEmpty()) { Job job = new Job(link, downloadsFolder, fileName, false); @@ -208,7 +208,7 @@ private static void printVersion() { } private static void handleSpotifyPlaylist() { - messageBroker.msgFilenameInfo(GREEN+"Retrieving the number of tracks in the playlist..."+RESET); + messageBroker.msgFilenameInfo(GREEN +"Retrieving the number of tracks in the playlist..."+ RESET); LinkedList linkMetadataList = Utility.getLinkMetadata(link); String json = makePretty(linkMetadataList.get(0)); String playlistLengthRegex = "(\"list_length\": )(.+)"; @@ -217,9 +217,9 @@ private static void handleSpotifyPlaylist() { int numberOfSongs = 0; if (lengthMatcher.find()) { numberOfSongs = Integer.parseInt(lengthMatcher.group(2)); - messageBroker.msgFilenameInfo(GREEN+"Number of tracks in the playlist : " + numberOfSongs+RESET); + messageBroker.msgFilenameInfo(GREEN +"Number of tracks in the playlist : " + numberOfSongs+ RESET); } else { - messageBroker.msgFilenameError(GREEN+"Failed to retrieve the number of tracks in the playlist!"+RESET); + messageBroker.msgFilenameError(GREEN +"Failed to retrieve the number of tracks in the playlist!"+ RESET); } for (int i = 0; i < numberOfSongs; i++) { messageBroker.msgStyleInfo(BANNER_BORDER); @@ -229,20 +229,20 @@ private static void handleSpotifyPlaylist() { if (linkMatcher.find(i)) { link = linkMatcher.group(2); } else { - messageBroker.msgLinkError(RED+"Failed to retrieve link from playlist!"+RESET); + messageBroker.msgLinkError(RED+"Failed to retrieve link from playlist!"+ RESET); continue; } - messageBroker.msgLinkInfo(GREEN+"[" + (i + 1) + "/" + numberOfSongs + "] " + "Processing link : " + link+RESET); + messageBroker.msgLinkInfo(GREEN +"[" + (i + 1) + "/" + numberOfSongs + "] " + "Processing link : " + link+ RESET); if (fileName != null) { String filenameRegex = "(\"name\": \")(.+)(\",)"; Pattern filenamePattern = Pattern.compile(filenameRegex); Matcher filenameMatcher = filenamePattern.matcher(json); if (filenameMatcher.find(i)) { fileName = cleanFilename(filenameMatcher.group(2)) + ".mp3"; - messageBroker.msgFilenameInfo(GREEN+FILENAME_DETECTED + "\"" + fileName + "\""+RESET); + messageBroker.msgFilenameInfo(GREEN +FILENAME_DETECTED + "\"" + fileName + "\""+ RESET); } else { fileName = cleanFilename("Unknown_Filename_") + randomString(15) + ".mp3"; - messageBroker.msgFilenameError(RED+FILENAME_DETECTION_ERROR+RESET); + messageBroker.msgFilenameError(RED+FILENAME_DETECTION_ERROR+ RESET); } } Job job = new Job(link, downloadsFolder, fileName, false); @@ -253,22 +253,22 @@ private static void handleSpotifyPlaylist() { private static void batchDownloader() { Yaml yamlParser = new Yaml(); try { - messageBroker.msgLogInfo(GREEN+"Trying to load YAML data file (" + batchDownloadingFile + ") ..."+RESET); + messageBroker.msgLogInfo(GREEN +"Trying to load YAML data file (" + batchDownloadingFile + ") ..."+ RESET); InputStreamReader yamlDataFile = new InputStreamReader(new FileInputStream(batchDownloadingFile)); Map> data = yamlParser.load(yamlDataFile); - messageBroker.msgLogInfo(GREEN+"YAML data file (" + batchDownloadingFile + ") loaded successfully"+RESET); + messageBroker.msgLogInfo(GREEN +"YAML data file (" + batchDownloadingFile + ") loaded successfully"+ RESET); int numberOfLinks; try { numberOfLinks = data.get("links").size(); } catch (NullPointerException e) { - messageBroker.msgLinkInfo(GREEN+"No links specified. Exiting..."+RESET); + messageBroker.msgLinkInfo(GREEN +"No links specified. Exiting..."+ RESET); return; } int numberOfFileNames; if (data.containsKey("fileNames")) { numberOfFileNames = data.get("fileNames").size(); } else { - messageBroker.msgFilenameInfo(GREEN+"No filename specified. Filename will be retrieved from the link."+RESET); + messageBroker.msgFilenameInfo(GREEN +"No filename specified. Filename will be retrieved from the link."+ RESET); numberOfFileNames = 0; } int numberOfDirectories; @@ -282,7 +282,7 @@ private static void batchDownloader() { } else if (data.containsKey("directories")) { numberOfDirectories = data.get("directories").size(); } else { - messageBroker.msgDirInfo(GREEN+"No directory specified. Default downloads folder will be used."+RESET); + messageBroker.msgDirInfo(GREEN +"No directory specified. Default downloads folder will be used."+ RESET); numberOfDirectories = 0; downloadsFolder = "."; } @@ -304,11 +304,11 @@ private static void batchDownloader() { } else { fileNameMessage = numberOfFileNames + " filenames"; } - messageBroker.msgBatchInfo(GREEN+"You have provided\n\t" + linkMessage + "\n\t" + directoryMessage + "\n\t" + fileNameMessage+RESET); + messageBroker.msgBatchInfo(GREEN +"You have provided\n\t" + linkMessage + "\n\t" + directoryMessage + "\n\t" + fileNameMessage+ RESET); for (int i = 0; i < numberOfLinks; i++) { messageBroker.msgStyleInfo(BANNER_BORDER); link = data.get("links").get(i); - messageBroker.msgLinkInfo(GREEN+"[" + (i + 1) + "/" + numberOfLinks + "] " + "Processing link : " + link+RESET); + messageBroker.msgLinkInfo(GREEN +"[" + (i + 1) + "/" + numberOfLinks + "] " + "Processing link : " + link+ RESET); isYoutubeURL = isYoutube(link); isInstagramLink = isInstagram(link); isSpotifyLink = isSpotify(link); @@ -336,7 +336,7 @@ private static void batchDownloader() { link = link + "?utm_source=ig_embed"; } } - messageBroker.msgFilenameInfo(GREEN+"Retrieving filename from link..."+RESET); + messageBroker.msgFilenameInfo(GREEN +"Retrieving filename from link..."+ RESET); fileName = findFilenameInLink(link); if (!fileName.isEmpty()) { renameFilenameIfRequired(false); @@ -350,7 +350,7 @@ private static void batchDownloader() { checkHistoryAddJobsAndDownload(job, false); } } catch (FileNotFoundException e) { - messageBroker.msgDownloadError(RED+"YAML Data file (" + batchDownloadingFile + ") not found ! " + e.getMessage()+RESET); + messageBroker.msgDownloadError(RED+"YAML Data file (" + batchDownloadingFile + ") not found ! " + e.getMessage()+ RESET); } } @@ -389,14 +389,14 @@ private static String getProperDownloadsFolder(String downloadsFolder) { } } if (new File(downloadsFolder).exists()) { - messageBroker.msgDirInfo(GREEN+"Download folder exists!"+RESET); + messageBroker.msgDirInfo(GREEN +"Download folder exists!"+ RESET); } else { - messageBroker.msgDirError(RED+"Download folder does not exist!"+RESET); + messageBroker.msgDirError(RED+"Download folder does not exist!"+ RESET); try { Files.createDirectory(Path.of(downloadsFolder)); - messageBroker.msgDirInfo(GREEN+"Download folder created successfully!"+RESET); + messageBroker.msgDirInfo(GREEN +"Download folder created successfully!"+ RESET); } catch (IOException e) { - messageBroker.msgDirError(RED+"Failed to create download folder! " + e.getMessage()+RESET); + messageBroker.msgDirError(RED+"Failed to create download folder! " + e.getMessage()+ RESET); } } AppSettings.SET.lastFolder(downloadsFolder); From b40f063caebe8960778950aa7392b40862175603 Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Tue, 7 Nov 2023 10:29:04 +0530 Subject: [PATCH 04/14] Update Main.java more chages as needed --- src/main/java/CLI/Main.java | 56 ++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/src/main/java/CLI/Main.java b/src/main/java/CLI/Main.java index 47ae50d79..40049237a 100644 --- a/src/main/java/CLI/Main.java +++ b/src/main/java/CLI/Main.java @@ -52,9 +52,9 @@ public static void main(String[] args) { LOGGER.log(MessageType.INFO, CLI_APPLICATION_STARTED); messageBroker = new MessageBroker(System.out); Environment.setMessageBroker(messageBroker); - messageBroker.msgInitInfo(GREEN +"Initializing environment..."+ RESET); + messageBroker.msgInitInfo(GREEN + "Initializing environment..." + RESET); Environment.initializeEnvironment(); - messageBroker.msgInitInfo(GREEN +"Environment initialized successfully!"+ RESET); + messageBroker.msgInitInfo(GREEN + "Environment initialized successfully!" + RESET); utility = new Utility(); jobHistory = AppSettings.GET.jobHistory(); printBanner(); @@ -82,7 +82,7 @@ public static void main(String[] args) { if (isURL(args[i])) { link = args[i]; } else { - messageBroker.msgInitError(RED+"Invalid argument(s) passed!"+ RESET); + messageBroker.msgInitError(RED + "Invalid argument(s) passed!" + RESET); System.exit(1); } } @@ -94,7 +94,7 @@ public static void main(String[] args) { isUrlValid = Utility.isLinkValid(link); } else { isUrlValid = false; - messageBroker.msgLinkError(RED+"Link is invalid!"+ RESET); + messageBroker.msgLinkError(RED + "Link is invalid!" + RESET); } if (isUrlValid) { isYoutubeURL = isYoutube(link); @@ -113,7 +113,7 @@ public static void main(String[] args) { link = link + "?utm_source=ig_embed"; } } - messageBroker.msgFilenameInfo(GREEN +"Retrieving filename from link..."+ RESET); + messageBroker.msgFilenameInfo(GREEN + "Retrieving filename from link..." + RESET); fileName = findFilenameInLink(link); if (!fileName.isEmpty()) { Job job = new Job(link, downloadsFolder, fileName, false); @@ -138,7 +138,7 @@ public static void main(String[] args) { batchDownloadingFile = SC.next(); SC.nextLine(); if (!(batchDownloadingFile.endsWith(".yml") || batchDownloadingFile.endsWith(".yaml"))) { - messageBroker.msgBatchError(RED+"The data file should be a YAML file!"+ RESET); + messageBroker.msgBatchError(RED + "The data file should be a YAML file!" + RESET); } else { batchDownloader(); break; @@ -158,7 +158,7 @@ public static void main(String[] args) { if (Utility.isURL(link)) { Utility.isLinkValid(link); } else { - messageBroker.msgLinkError(RED+"Link is invalid!"+ RESET); + messageBroker.msgLinkError(RED + "Link is invalid!" + RESET); continue; } System.out.print("Download directory (\".\" for default or \"L\" for " + AppSettings.GET.lastDownloadFolder() + ") : "); @@ -177,7 +177,7 @@ public static void main(String[] args) { link = link + "?utm_source=ig_embed"; } } - messageBroker.msgFilenameInfo(GREEN +"Retrieving filename from link..."+ RESET); + messageBroker.msgFilenameInfo(GREEN + "Retrieving filename from link..." + RESET); fileName = findFilenameInLink(link); if (!fileName.isEmpty()) { Job job = new Job(link, downloadsFolder, fileName, false); @@ -208,7 +208,7 @@ private static void printVersion() { } private static void handleSpotifyPlaylist() { - messageBroker.msgFilenameInfo(GREEN +"Retrieving the number of tracks in the playlist..."+ RESET); + messageBroker.msgFilenameInfo(GREEN + "Retrieving the number of tracks in the playlist..." + RESET); LinkedList linkMetadataList = Utility.getLinkMetadata(link); String json = makePretty(linkMetadataList.get(0)); String playlistLengthRegex = "(\"list_length\": )(.+)"; @@ -217,9 +217,9 @@ private static void handleSpotifyPlaylist() { int numberOfSongs = 0; if (lengthMatcher.find()) { numberOfSongs = Integer.parseInt(lengthMatcher.group(2)); - messageBroker.msgFilenameInfo(GREEN +"Number of tracks in the playlist : " + numberOfSongs+ RESET); + messageBroker.msgFilenameInfo(GREEN + "Number of tracks in the playlist : " + numberOfSongs+ RESET); } else { - messageBroker.msgFilenameError(GREEN +"Failed to retrieve the number of tracks in the playlist!"+ RESET); + messageBroker.msgFilenameError(GREEN + "Failed to retrieve the number of tracks in the playlist!" + RESET); } for (int i = 0; i < numberOfSongs; i++) { messageBroker.msgStyleInfo(BANNER_BORDER); @@ -229,20 +229,20 @@ private static void handleSpotifyPlaylist() { if (linkMatcher.find(i)) { link = linkMatcher.group(2); } else { - messageBroker.msgLinkError(RED+"Failed to retrieve link from playlist!"+ RESET); + messageBroker.msgLinkError(RED + "Failed to retrieve link from playlist!" + RESET); continue; } - messageBroker.msgLinkInfo(GREEN +"[" + (i + 1) + "/" + numberOfSongs + "] " + "Processing link : " + link+ RESET); + messageBroker.msgLinkInfo(GREEN + "[" + (i + 1) + "/" + numberOfSongs + "] " + "Processing link : " + link+ RESET); if (fileName != null) { String filenameRegex = "(\"name\": \")(.+)(\",)"; Pattern filenamePattern = Pattern.compile(filenameRegex); Matcher filenameMatcher = filenamePattern.matcher(json); if (filenameMatcher.find(i)) { fileName = cleanFilename(filenameMatcher.group(2)) + ".mp3"; - messageBroker.msgFilenameInfo(GREEN +FILENAME_DETECTED + "\"" + fileName + "\""+ RESET); + messageBroker.msgFilenameInfo(GREEN +FILENAME_DETECTED + "\"" + fileName + "\"" + RESET); } else { fileName = cleanFilename("Unknown_Filename_") + randomString(15) + ".mp3"; - messageBroker.msgFilenameError(RED+FILENAME_DETECTION_ERROR+ RESET); + messageBroker.msgFilenameError(RED +FILENAME_DETECTION_ERROR+ RESET); } } Job job = new Job(link, downloadsFolder, fileName, false); @@ -253,22 +253,22 @@ private static void handleSpotifyPlaylist() { private static void batchDownloader() { Yaml yamlParser = new Yaml(); try { - messageBroker.msgLogInfo(GREEN +"Trying to load YAML data file (" + batchDownloadingFile + ") ..."+ RESET); + messageBroker.msgLogInfo(GREEN + "Trying to load YAML data file (" + batchDownloadingFile + ") ..." + RESET); InputStreamReader yamlDataFile = new InputStreamReader(new FileInputStream(batchDownloadingFile)); Map> data = yamlParser.load(yamlDataFile); - messageBroker.msgLogInfo(GREEN +"YAML data file (" + batchDownloadingFile + ") loaded successfully"+ RESET); + messageBroker.msgLogInfo(GREEN + "YAML data file (" + batchDownloadingFile + ") loaded successfully" + RESET); int numberOfLinks; try { numberOfLinks = data.get("links").size(); } catch (NullPointerException e) { - messageBroker.msgLinkInfo(GREEN +"No links specified. Exiting..."+ RESET); + messageBroker.msgLinkInfo(GREEN + "No links specified. Exiting..." + RESET); return; } int numberOfFileNames; if (data.containsKey("fileNames")) { numberOfFileNames = data.get("fileNames").size(); } else { - messageBroker.msgFilenameInfo(GREEN +"No filename specified. Filename will be retrieved from the link."+ RESET); + messageBroker.msgFilenameInfo(GREEN + "No filename specified. Filename will be retrieved from the link." + RESET); numberOfFileNames = 0; } int numberOfDirectories; @@ -282,7 +282,7 @@ private static void batchDownloader() { } else if (data.containsKey("directories")) { numberOfDirectories = data.get("directories").size(); } else { - messageBroker.msgDirInfo(GREEN +"No directory specified. Default downloads folder will be used."+ RESET); + messageBroker.msgDirInfo(GREEN + "No directory specified. Default downloads folder will be used." + RESET); numberOfDirectories = 0; downloadsFolder = "."; } @@ -304,11 +304,11 @@ private static void batchDownloader() { } else { fileNameMessage = numberOfFileNames + " filenames"; } - messageBroker.msgBatchInfo(GREEN +"You have provided\n\t" + linkMessage + "\n\t" + directoryMessage + "\n\t" + fileNameMessage+ RESET); + messageBroker.msgBatchInfo(GREEN + "You have provided\n\t" + linkMessage + "\n\t" + directoryMessage + "\n\t" + fileNameMessage+ RESET); for (int i = 0; i < numberOfLinks; i++) { messageBroker.msgStyleInfo(BANNER_BORDER); link = data.get("links").get(i); - messageBroker.msgLinkInfo(GREEN +"[" + (i + 1) + "/" + numberOfLinks + "] " + "Processing link : " + link+ RESET); + messageBroker.msgLinkInfo(GREEN + "[" + (i + 1) + "/" + numberOfLinks + "] " + "Processing link : " + link+ RESET); isYoutubeURL = isYoutube(link); isInstagramLink = isInstagram(link); isSpotifyLink = isSpotify(link); @@ -336,7 +336,7 @@ private static void batchDownloader() { link = link + "?utm_source=ig_embed"; } } - messageBroker.msgFilenameInfo(GREEN +"Retrieving filename from link..."+ RESET); + messageBroker.msgFilenameInfo(GREEN + "Retrieving filename from link..." + RESET); fileName = findFilenameInLink(link); if (!fileName.isEmpty()) { renameFilenameIfRequired(false); @@ -350,7 +350,7 @@ private static void batchDownloader() { checkHistoryAddJobsAndDownload(job, false); } } catch (FileNotFoundException e) { - messageBroker.msgDownloadError(RED+"YAML Data file (" + batchDownloadingFile + ") not found ! " + e.getMessage()+ RESET); + messageBroker.msgDownloadError(RED + "YAML Data file (" + batchDownloadingFile + ") not found ! " + e.getMessage() + RESET); } } @@ -389,14 +389,14 @@ private static String getProperDownloadsFolder(String downloadsFolder) { } } if (new File(downloadsFolder).exists()) { - messageBroker.msgDirInfo(GREEN +"Download folder exists!"+ RESET); + messageBroker.msgDirInfo(GREEN + "Download folder exists!" + RESET); } else { - messageBroker.msgDirError(RED+"Download folder does not exist!"+ RESET); + messageBroker.msgDirError(RED + "Download folder does not exist!" + RESET); try { Files.createDirectory(Path.of(downloadsFolder)); - messageBroker.msgDirInfo(GREEN +"Download folder created successfully!"+ RESET); + messageBroker.msgDirInfo(GREEN + "Download folder created successfully!" + RESET); } catch (IOException e) { - messageBroker.msgDirError(RED+"Failed to create download folder! " + e.getMessage()+ RESET); + messageBroker.msgDirError(RED + "Failed to create download folder! " + e.getMessage() + RESET); } } AppSettings.SET.lastFolder(downloadsFolder); From 9d271527f33191f92a6da28bc199dc4a4ded01e7 Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Tue, 7 Nov 2023 15:21:09 +0530 Subject: [PATCH 05/14] Update Main.java taking all chage back --- src/main/java/CLI/Main.java | 63 +++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 34 deletions(-) diff --git a/src/main/java/CLI/Main.java b/src/main/java/CLI/Main.java index 40049237a..c2b149aaf 100644 --- a/src/main/java/CLI/Main.java +++ b/src/main/java/CLI/Main.java @@ -42,19 +42,14 @@ public class Main { private static String batchDownloadingFile; private static final String MSG_FILE_EXISTS_NO_HISTORY = "\"%s\" exists in \"%s\" folder. It will be renamed to \"%s\"."; private static final String MSG_FILE_EXISTS_HAS_HISTORY = "You have previously downloaded \"%s\" and it exists in \"%s\" folder.\nDo you want to download it again? "; - public static final String RESET = "\u001B[0m"; - public static final String BLUE = "\033[0;34m"; - public static final String YELLOW = "\u001B[33m"; - public static final String RED = "\u001B[31m"; - public static final String GREEN = "\u001B[32m"; - + public static void main(String[] args) { LOGGER.log(MessageType.INFO, CLI_APPLICATION_STARTED); messageBroker = new MessageBroker(System.out); Environment.setMessageBroker(messageBroker); - messageBroker.msgInitInfo(GREEN + "Initializing environment..." + RESET); + messageBroker.msgInitInfo("Initializing environment..."); Environment.initializeEnvironment(); - messageBroker.msgInitInfo(GREEN + "Environment initialized successfully!" + RESET); + messageBroker.msgInitInfo("Environment initialized successfully!"); utility = new Utility(); jobHistory = AppSettings.GET.jobHistory(); printBanner(); @@ -82,7 +77,7 @@ public static void main(String[] args) { if (isURL(args[i])) { link = args[i]; } else { - messageBroker.msgInitError(RED + "Invalid argument(s) passed!" + RESET); + messageBroker.msgInitError("Invalid argument(s) passed!"); System.exit(1); } } @@ -94,7 +89,7 @@ public static void main(String[] args) { isUrlValid = Utility.isLinkValid(link); } else { isUrlValid = false; - messageBroker.msgLinkError(RED + "Link is invalid!" + RESET); + messageBroker.msgLinkError("Link is invalid!"); } if (isUrlValid) { isYoutubeURL = isYoutube(link); @@ -113,7 +108,7 @@ public static void main(String[] args) { link = link + "?utm_source=ig_embed"; } } - messageBroker.msgFilenameInfo(GREEN + "Retrieving filename from link..." + RESET); + messageBroker.msgFilenameInfo("Retrieving filename from link..."); fileName = findFilenameInLink(link); if (!fileName.isEmpty()) { Job job = new Job(link, downloadsFolder, fileName, false); @@ -138,7 +133,7 @@ public static void main(String[] args) { batchDownloadingFile = SC.next(); SC.nextLine(); if (!(batchDownloadingFile.endsWith(".yml") || batchDownloadingFile.endsWith(".yaml"))) { - messageBroker.msgBatchError(RED + "The data file should be a YAML file!" + RESET); + messageBroker.msgBatchError("The data file should be a YAML file!"); } else { batchDownloader(); break; @@ -158,7 +153,7 @@ public static void main(String[] args) { if (Utility.isURL(link)) { Utility.isLinkValid(link); } else { - messageBroker.msgLinkError(RED + "Link is invalid!" + RESET); + messageBroker.msgLinkError("Link is invalid!"); continue; } System.out.print("Download directory (\".\" for default or \"L\" for " + AppSettings.GET.lastDownloadFolder() + ") : "); @@ -177,7 +172,7 @@ public static void main(String[] args) { link = link + "?utm_source=ig_embed"; } } - messageBroker.msgFilenameInfo(GREEN + "Retrieving filename from link..." + RESET); + messageBroker.msgFilenameInfo("Retrieving filename from link..."); fileName = findFilenameInLink(link); if (!fileName.isEmpty()) { Job job = new Job(link, downloadsFolder, fileName, false); @@ -208,7 +203,7 @@ private static void printVersion() { } private static void handleSpotifyPlaylist() { - messageBroker.msgFilenameInfo(GREEN + "Retrieving the number of tracks in the playlist..." + RESET); + messageBroker.msgFilenameInfo("Retrieving the number of tracks in the playlist..."); LinkedList linkMetadataList = Utility.getLinkMetadata(link); String json = makePretty(linkMetadataList.get(0)); String playlistLengthRegex = "(\"list_length\": )(.+)"; @@ -217,9 +212,9 @@ private static void handleSpotifyPlaylist() { int numberOfSongs = 0; if (lengthMatcher.find()) { numberOfSongs = Integer.parseInt(lengthMatcher.group(2)); - messageBroker.msgFilenameInfo(GREEN + "Number of tracks in the playlist : " + numberOfSongs+ RESET); + messageBroker.msgFilenameInfo("Number of tracks in the playlist : " + numberOfSongs); } else { - messageBroker.msgFilenameError(GREEN + "Failed to retrieve the number of tracks in the playlist!" + RESET); + messageBroker.msgFilenameError("Failed to retrieve the number of tracks in the playlist!"); } for (int i = 0; i < numberOfSongs; i++) { messageBroker.msgStyleInfo(BANNER_BORDER); @@ -229,20 +224,20 @@ private static void handleSpotifyPlaylist() { if (linkMatcher.find(i)) { link = linkMatcher.group(2); } else { - messageBroker.msgLinkError(RED + "Failed to retrieve link from playlist!" + RESET); + messageBroker.msgLinkError("Failed to retrieve link from playlist!"); continue; } - messageBroker.msgLinkInfo(GREEN + "[" + (i + 1) + "/" + numberOfSongs + "] " + "Processing link : " + link+ RESET); + messageBroker.msgLinkInfo("[" + (i + 1) + "/" + numberOfSongs + "] " + "Processing link : " + link); if (fileName != null) { String filenameRegex = "(\"name\": \")(.+)(\",)"; Pattern filenamePattern = Pattern.compile(filenameRegex); Matcher filenameMatcher = filenamePattern.matcher(json); if (filenameMatcher.find(i)) { fileName = cleanFilename(filenameMatcher.group(2)) + ".mp3"; - messageBroker.msgFilenameInfo(GREEN +FILENAME_DETECTED + "\"" + fileName + "\"" + RESET); + messageBroker.msgFilenameInfo(FILENAME_DETECTED + "\"" + fileName + "\""); } else { fileName = cleanFilename("Unknown_Filename_") + randomString(15) + ".mp3"; - messageBroker.msgFilenameError(RED +FILENAME_DETECTION_ERROR+ RESET); + messageBroker.msgFilenameError(FILENAME_DETECTION_ERROR); } } Job job = new Job(link, downloadsFolder, fileName, false); @@ -253,22 +248,22 @@ private static void handleSpotifyPlaylist() { private static void batchDownloader() { Yaml yamlParser = new Yaml(); try { - messageBroker.msgLogInfo(GREEN + "Trying to load YAML data file (" + batchDownloadingFile + ") ..." + RESET); + messageBroker.msgLogInfo("Trying to load YAML data file (" + batchDownloadingFile + ") ..."); InputStreamReader yamlDataFile = new InputStreamReader(new FileInputStream(batchDownloadingFile)); Map> data = yamlParser.load(yamlDataFile); - messageBroker.msgLogInfo(GREEN + "YAML data file (" + batchDownloadingFile + ") loaded successfully" + RESET); + messageBroker.msgLogInfo("YAML data file (" + batchDownloadingFile + ") loaded successfully"); int numberOfLinks; try { numberOfLinks = data.get("links").size(); } catch (NullPointerException e) { - messageBroker.msgLinkInfo(GREEN + "No links specified. Exiting..." + RESET); + messageBroker.msgLinkInfo("No links specified. Exiting..."); return; } int numberOfFileNames; if (data.containsKey("fileNames")) { numberOfFileNames = data.get("fileNames").size(); } else { - messageBroker.msgFilenameInfo(GREEN + "No filename specified. Filename will be retrieved from the link." + RESET); + messageBroker.msgFilenameInfo("No filename specified. Filename will be retrieved from the link."); numberOfFileNames = 0; } int numberOfDirectories; @@ -282,7 +277,7 @@ private static void batchDownloader() { } else if (data.containsKey("directories")) { numberOfDirectories = data.get("directories").size(); } else { - messageBroker.msgDirInfo(GREEN + "No directory specified. Default downloads folder will be used." + RESET); + messageBroker.msgDirInfo("No directory specified. Default downloads folder will be used."); numberOfDirectories = 0; downloadsFolder = "."; } @@ -304,11 +299,11 @@ private static void batchDownloader() { } else { fileNameMessage = numberOfFileNames + " filenames"; } - messageBroker.msgBatchInfo(GREEN + "You have provided\n\t" + linkMessage + "\n\t" + directoryMessage + "\n\t" + fileNameMessage+ RESET); + messageBroker.msgBatchInfo("You have provided\n\t" + linkMessage + "\n\t" + directoryMessage + "\n\t" + fileNameMessage); for (int i = 0; i < numberOfLinks; i++) { messageBroker.msgStyleInfo(BANNER_BORDER); link = data.get("links").get(i); - messageBroker.msgLinkInfo(GREEN + "[" + (i + 1) + "/" + numberOfLinks + "] " + "Processing link : " + link+ RESET); + messageBroker.msgLinkInfo("[" + (i + 1) + "/" + numberOfLinks + "] " + "Processing link : " + link); isYoutubeURL = isYoutube(link); isInstagramLink = isInstagram(link); isSpotifyLink = isSpotify(link); @@ -336,7 +331,7 @@ private static void batchDownloader() { link = link + "?utm_source=ig_embed"; } } - messageBroker.msgFilenameInfo(GREEN + "Retrieving filename from link..." + RESET); + messageBroker.msgFilenameInfo("Retrieving filename from link..."); fileName = findFilenameInLink(link); if (!fileName.isEmpty()) { renameFilenameIfRequired(false); @@ -350,7 +345,7 @@ private static void batchDownloader() { checkHistoryAddJobsAndDownload(job, false); } } catch (FileNotFoundException e) { - messageBroker.msgDownloadError(RED + "YAML Data file (" + batchDownloadingFile + ") not found ! " + e.getMessage() + RESET); + messageBroker.msgDownloadError("YAML Data file (" + batchDownloadingFile + ") not found ! " + e.getMessage()); } } @@ -389,14 +384,14 @@ private static String getProperDownloadsFolder(String downloadsFolder) { } } if (new File(downloadsFolder).exists()) { - messageBroker.msgDirInfo(GREEN + "Download folder exists!" + RESET); + messageBroker.msgDirInfo("Download folder exists!"); } else { - messageBroker.msgDirError(RED + "Download folder does not exist!" + RESET); + messageBroker.msgDirError("Download folder does not exist!"); try { Files.createDirectory(Path.of(downloadsFolder)); - messageBroker.msgDirInfo(GREEN + "Download folder created successfully!" + RESET); + messageBroker.msgDirInfo("Download folder created successfully!"); } catch (IOException e) { - messageBroker.msgDirError(RED + "Failed to create download folder! " + e.getMessage() + RESET); + messageBroker.msgDirError("Failed to create download folder! " + e.getMessage()); } } AppSettings.SET.lastFolder(downloadsFolder); From 8667e74b3ae711e321d2e95827995df27bff39d7 Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Tue, 7 Nov 2023 15:21:59 +0530 Subject: [PATCH 06/14] Update MessageBroker.java as requested --- src/main/java/Utils/MessageBroker.java | 225 +++++++++++++------------ 1 file changed, 116 insertions(+), 109 deletions(-) diff --git a/src/main/java/Utils/MessageBroker.java b/src/main/java/Utils/MessageBroker.java index a2ceaa3f3..82d69137e 100644 --- a/src/main/java/Utils/MessageBroker.java +++ b/src/main/java/Utils/MessageBroker.java @@ -5,118 +5,125 @@ import Enums.Mode; import GUI.Forms.FormsController; import javafx.scene.paint.Color; - import java.io.PrintStream; - import static Enums.MessageCategory.LOG; import static Enums.Colors.*; public class MessageBroker { - private final Logger logger; - private PrintStream output = new PrintStream(System.out); - - public MessageBroker(PrintStream consoleOutput) { - output = consoleOutput; - logger = Logger.getInstance(); - } - - public MessageBroker() { - logger = Logger.getInstance(); - } - - public void msgDownloadInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.DOWNLOAD); - } - - public void msgDownloadError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.DOWNLOAD); - } - - public void msgLinkInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.LINK); - } - - public void msgLinkError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.LINK); - } - - public void msgLogInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.LOG); - } - - public void msgLogError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.LOG); - } - - public void msgLogWarning(String message) { - sendMessage(message, MessageType.WARN, MessageCategory.LOG); - } - - public void msgInitInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.INITIALIZATION); - } - - public void msgInitError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.INITIALIZATION); - } - - public void msgDirInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.DIRECTORY); - } - - public void msgDirError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.DIRECTORY); - } - - public void msgFilenameInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.FILENAME); - } - - public void msgFilenameError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.FILENAME); - } - - public void msgBatchInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.BATCH); - } - - public void msgBatchError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.BATCH); - } - - public void msgStyleInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.STYLE); - } - - private void sendMessage(String message, MessageType messageType, MessageCategory messageCategory) { - if (Mode.isCLI()) { - if (!messageCategory.equals(LOG)) { - output.println(message); - } - logger.log(messageType, message); - } else if (Mode.isGUI()) { - FormsController ui; - if (!messageCategory.equals(LOG)) { - ui = FormsController.INSTANCE; - } else { - ui = null; - } - Color color = switch (messageType) { - case ERROR -> RED; - case INFO -> GREEN; - default -> YELLOW; - }; - switch (messageCategory) { - case LINK -> ui.setLinkOutput(color, message); - case FILENAME -> ui.setFilenameOutput(color, message); - case DIRECTORY -> ui.setDirOutput(color, message); - case DOWNLOAD -> ui.setDownloadOutput(color, message); - default -> { - if (!message.isEmpty()) { - logger.log(messageType, message); - } - } - } - } - } + private final Logger logger; + private PrintStream output = new PrintStream(System.out); + + public MessageBroker(PrintStream consoleOutput) { + output = consoleOutput; + logger = Logger.getInstance(); + } + + public MessageBroker() { + logger = Logger.getInstance(); + } + + public void msgDownloadInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.DOWNLOAD); + } + + public void msgDownloadError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.DOWNLOAD); + } + + public void msgLinkInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.LINK); + } + + public void msgLinkError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.LINK); + } + + public void msgLogInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.LOG); + } + + public void msgLogError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.LOG); + } + + public void msgLogWarning(String message) { + sendMessage(message, MessageType.WARN, MessageCategory.LOG); + } + + public void msgInitInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.INITIALIZATION); + } + + public void msgInitError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.INITIALIZATION); + } + + public void msgDirInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.DIRECTORY); + } + + public void msgDirError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.DIRECTORY); + } + + public void msgFilenameInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.FILENAME); + } + + public void msgFilenameError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.FILENAME); + } + + public void msgBatchInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.BATCH); + } + + public void msgBatchError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.BATCH); + } + + public void msgStyleInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.STYLE); + } + + private void sendMessage(String message, MessageType messageType, MessageCategory messageCategory) { + if (Mode.isCLI()) { + if (messageType.equals(MessageType.INFO)) { + message = "\033[92m" + message + "\033[0m"; + } + if (messageType.equals(MessageType.ERROR)) { + message = "\033[91m" + message + "\033[0m"; + } + if (messageType.equals(MessageType.WARN)) { + message = "\033[93m" + message + "\033[0m"; + } + if (!messageCategory.equals(LOG)) { + output.println(message); + } + logger.log(messageType, message); + } else if (Mode.isGUI()) { + FormsController ui; + if (!messageCategory.equals(LOG)) { + ui = FormsController.INSTANCE; + } else { + ui = null; + } + Color color = switch (messageType) { + case ERROR -> RED; + case INFO -> GREEN; + default -> YELLOW; + }; + switch (messageCategory) { + case LINK -> ui.setLinkOutput(color, message); + case FILENAME -> ui.setFilenameOutput(color, message); + case DIRECTORY -> ui.setDirOutput(color, message); + case DOWNLOAD -> ui.setDownloadOutput(color, message); + default -> { + if (!message.isEmpty()) { + logger.log(messageType, message); + } + } + } + } + } } From c4681e5df8fbb31846362c26315d3c56150b85ac Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Tue, 7 Nov 2023 20:21:42 +0530 Subject: [PATCH 07/14] Update MessageBroker.java as per new requrment added swich case and changed space in IDE for space --- src/main/java/Utils/MessageBroker.java | 239 +++++++++++++------------ 1 file changed, 123 insertions(+), 116 deletions(-) diff --git a/src/main/java/Utils/MessageBroker.java b/src/main/java/Utils/MessageBroker.java index 82d69137e..7b4fe8d77 100644 --- a/src/main/java/Utils/MessageBroker.java +++ b/src/main/java/Utils/MessageBroker.java @@ -5,125 +5,132 @@ import Enums.Mode; import GUI.Forms.FormsController; import javafx.scene.paint.Color; + import java.io.PrintStream; + import static Enums.MessageCategory.LOG; import static Enums.Colors.*; public class MessageBroker { - private final Logger logger; - private PrintStream output = new PrintStream(System.out); - - public MessageBroker(PrintStream consoleOutput) { - output = consoleOutput; - logger = Logger.getInstance(); - } - - public MessageBroker() { - logger = Logger.getInstance(); - } - - public void msgDownloadInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.DOWNLOAD); - } - - public void msgDownloadError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.DOWNLOAD); - } - - public void msgLinkInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.LINK); - } - - public void msgLinkError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.LINK); - } - - public void msgLogInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.LOG); - } - - public void msgLogError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.LOG); - } - - public void msgLogWarning(String message) { - sendMessage(message, MessageType.WARN, MessageCategory.LOG); - } - - public void msgInitInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.INITIALIZATION); - } - - public void msgInitError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.INITIALIZATION); - } - - public void msgDirInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.DIRECTORY); - } - - public void msgDirError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.DIRECTORY); - } - - public void msgFilenameInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.FILENAME); - } - - public void msgFilenameError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.FILENAME); - } - - public void msgBatchInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.BATCH); - } - - public void msgBatchError(String message) { - sendMessage(message, MessageType.ERROR, MessageCategory.BATCH); - } - - public void msgStyleInfo(String message) { - sendMessage(message, MessageType.INFO, MessageCategory.STYLE); - } - - private void sendMessage(String message, MessageType messageType, MessageCategory messageCategory) { - if (Mode.isCLI()) { - if (messageType.equals(MessageType.INFO)) { - message = "\033[92m" + message + "\033[0m"; - } - if (messageType.equals(MessageType.ERROR)) { - message = "\033[91m" + message + "\033[0m"; - } - if (messageType.equals(MessageType.WARN)) { - message = "\033[93m" + message + "\033[0m"; - } - if (!messageCategory.equals(LOG)) { - output.println(message); - } - logger.log(messageType, message); - } else if (Mode.isGUI()) { - FormsController ui; - if (!messageCategory.equals(LOG)) { - ui = FormsController.INSTANCE; - } else { - ui = null; - } - Color color = switch (messageType) { - case ERROR -> RED; - case INFO -> GREEN; - default -> YELLOW; - }; - switch (messageCategory) { - case LINK -> ui.setLinkOutput(color, message); - case FILENAME -> ui.setFilenameOutput(color, message); - case DIRECTORY -> ui.setDirOutput(color, message); - case DOWNLOAD -> ui.setDownloadOutput(color, message); - default -> { - if (!message.isEmpty()) { - logger.log(messageType, message); - } - } - } - } - } + private final Logger logger; + private PrintStream output = new PrintStream(System.out); + + public MessageBroker(PrintStream consoleOutput) { + output = consoleOutput; + logger = Logger.getInstance(); + } + + public MessageBroker() { + logger = Logger.getInstance(); + } + + public void msgDownloadInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.DOWNLOAD); + } + + public void msgDownloadError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.DOWNLOAD); + } + + public void msgLinkInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.LINK); + } + + public void msgLinkError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.LINK); + } + + public void msgLogInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.LOG); + } + + public void msgLogError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.LOG); + } + + public void msgLogWarning(String message) { + sendMessage(message, MessageType.WARN, MessageCategory.LOG); + } + + public void msgInitInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.INITIALIZATION); + } + + public void msgInitError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.INITIALIZATION); + } + + public void msgDirInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.DIRECTORY); + } + + public void msgDirError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.DIRECTORY); + } + + public void msgFilenameInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.FILENAME); + } + + public void msgFilenameError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.FILENAME); + } + + public void msgBatchInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.BATCH); + } + + public void msgBatchError(String message) { + sendMessage(message, MessageType.ERROR, MessageCategory.BATCH); + } + + public void msgStyleInfo(String message) { + sendMessage(message, MessageType.INFO, MessageCategory.STYLE); + } + + private void sendMessage(String message, MessageType messageType, MessageCategory messageCategory) { + if (Mode.isCLI()) { + switch (messageType) { + case INFO: + message = "\033[92m" + message + "\033[0m"; + break; + case ERROR: + message = "\033[91m" + message + "\033[0m"; + break; + case WARN: + message = "\033[93m" + message + "\033[0m"; + break; + default: + output.println(message); + break; + } + if (!messageCategory.equals(LOG)) { + output.println(message); + } + logger.log(messageType, message); + } else if (Mode.isGUI()) { + FormsController ui; + if (!messageCategory.equals(LOG)) { + ui = FormsController.INSTANCE; + } else { + ui = null; + } + Color color = switch (messageType) { + case ERROR -> RED; + case INFO -> GREEN; + default -> YELLOW; + }; + switch (messageCategory) { + case LINK -> ui.setLinkOutput(color, message); + case FILENAME -> ui.setFilenameOutput(color, message); + case DIRECTORY -> ui.setDirOutput(color, message); + case DOWNLOAD -> ui.setDownloadOutput(color, message); + default -> { + if (!message.isEmpty()) { + logger.log(messageType, message); + } + } + } + } + } } From bac72ad9d9d45cba7e672bb2c0fd144f1242b67e Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Tue, 7 Nov 2023 20:37:37 +0530 Subject: [PATCH 08/14] Update MessageBroker.java updated --- src/main/java/Utils/MessageBroker.java | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main/java/Utils/MessageBroker.java b/src/main/java/Utils/MessageBroker.java index 7b4fe8d77..35f554a81 100644 --- a/src/main/java/Utils/MessageBroker.java +++ b/src/main/java/Utils/MessageBroker.java @@ -116,21 +116,21 @@ private void sendMessage(String message, MessageType messageType, MessageCategor ui = null; } Color color = switch (messageType) { - case ERROR -> RED; - case INFO -> GREEN; - default -> YELLOW; + case ERROR -> RED; + case INFO -> GREEN; + default -> YELLOW; }; switch (messageCategory) { - case LINK -> ui.setLinkOutput(color, message); - case FILENAME -> ui.setFilenameOutput(color, message); - case DIRECTORY -> ui.setDirOutput(color, message); - case DOWNLOAD -> ui.setDownloadOutput(color, message); - default -> { - if (!message.isEmpty()) { - logger.log(messageType, message); - } + case LINK -> ui.setLinkOutput(color, message); + case FILENAME -> ui.setFilenameOutput(color, message); + case DIRECTORY -> ui.setDirOutput(color, message); + case DOWNLOAD -> ui.setDownloadOutput(color, message); + default -> { + if (!message.isEmpty()) { + logger.log(messageType, message); } } + } } } } From 0278fb8f237149b8ecab82eca153db945398560f Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Tue, 7 Nov 2023 21:11:10 +0530 Subject: [PATCH 09/14] Update MessageBroker.java new update --- src/main/java/Utils/MessageBroker.java | 38 ++++++++++---------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/src/main/java/Utils/MessageBroker.java b/src/main/java/Utils/MessageBroker.java index 35f554a81..f36c2c7be 100644 --- a/src/main/java/Utils/MessageBroker.java +++ b/src/main/java/Utils/MessageBroker.java @@ -91,18 +91,10 @@ public void msgStyleInfo(String message) { private void sendMessage(String message, MessageType messageType, MessageCategory messageCategory) { if (Mode.isCLI()) { switch (messageType) { - case INFO: - message = "\033[92m" + message + "\033[0m"; - break; - case ERROR: - message = "\033[91m" + message + "\033[0m"; - break; - case WARN: - message = "\033[93m" + message + "\033[0m"; - break; - default: - output.println(message); - break; + case INFO -> message = "\033[92m" + message + "\033[0m"; + case WARN -> message = "\033[93m" + message + "\033[0m"; + case ERROR -> message = "\033[91m" + message + "\033[0m"; + default -> message = message; } if (!messageCategory.equals(LOG)) { output.println(message); @@ -116,21 +108,21 @@ private void sendMessage(String message, MessageType messageType, MessageCategor ui = null; } Color color = switch (messageType) { - case ERROR -> RED; - case INFO -> GREEN; - default -> YELLOW; + case ERROR -> RED; + case INFO -> GREEN; + default -> YELLOW; }; switch (messageCategory) { - case LINK -> ui.setLinkOutput(color, message); - case FILENAME -> ui.setFilenameOutput(color, message); - case DIRECTORY -> ui.setDirOutput(color, message); - case DOWNLOAD -> ui.setDownloadOutput(color, message); - default -> { - if (!message.isEmpty()) { - logger.log(messageType, message); + case LINK -> ui.setLinkOutput(color, message); + case FILENAME -> ui.setFilenameOutput(color, message); + case DIRECTORY -> ui.setDirOutput(color, message); + case DOWNLOAD -> ui.setDownloadOutput(color, message); + default -> { + if (!message.isEmpty()) { + logger.log(messageType, message); + } } } - } } } } From e838dd4c60213df3d081e58ac6d997a12d018eee Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Wed, 8 Nov 2023 08:49:37 +0530 Subject: [PATCH 10/14] Update MessageBroker.java added messge = switch {.. }; --- src/main/java/Utils/MessageBroker.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/Utils/MessageBroker.java b/src/main/java/Utils/MessageBroker.java index f36c2c7be..fa56fc126 100644 --- a/src/main/java/Utils/MessageBroker.java +++ b/src/main/java/Utils/MessageBroker.java @@ -90,12 +90,12 @@ public void msgStyleInfo(String message) { private void sendMessage(String message, MessageType messageType, MessageCategory messageCategory) { if (Mode.isCLI()) { - switch (messageType) { + message = switch (messageType) { case INFO -> message = "\033[92m" + message + "\033[0m"; case WARN -> message = "\033[93m" + message + "\033[0m"; case ERROR -> message = "\033[91m" + message + "\033[0m"; default -> message = message; - } + }; if (!messageCategory.equals(LOG)) { output.println(message); } From 46ef6904da6931acf92c2791dcb75d29c4c8a9c1 Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Wed, 8 Nov 2023 20:01:16 +0530 Subject: [PATCH 11/14] Update src/main/java/Utils/MessageBroker.java as needed Co-authored-by: Saptarshi Sarkar --- src/main/java/Utils/MessageBroker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Utils/MessageBroker.java b/src/main/java/Utils/MessageBroker.java index fa56fc126..54f5c707b 100644 --- a/src/main/java/Utils/MessageBroker.java +++ b/src/main/java/Utils/MessageBroker.java @@ -91,7 +91,7 @@ public void msgStyleInfo(String message) { private void sendMessage(String message, MessageType messageType, MessageCategory messageCategory) { if (Mode.isCLI()) { message = switch (messageType) { - case INFO -> message = "\033[92m" + message + "\033[0m"; + case INFO -> "\033[92m" + message + "\033[0m"; case WARN -> message = "\033[93m" + message + "\033[0m"; case ERROR -> message = "\033[91m" + message + "\033[0m"; default -> message = message; From f11bffb9380bfe268f86e1cc1ec1f77498762866 Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Wed, 8 Nov 2023 20:01:29 +0530 Subject: [PATCH 12/14] Update src/main/java/Utils/MessageBroker.java Co-authored-by: Saptarshi Sarkar --- src/main/java/Utils/MessageBroker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Utils/MessageBroker.java b/src/main/java/Utils/MessageBroker.java index 54f5c707b..400709ad2 100644 --- a/src/main/java/Utils/MessageBroker.java +++ b/src/main/java/Utils/MessageBroker.java @@ -92,7 +92,7 @@ private void sendMessage(String message, MessageType messageType, MessageCategor if (Mode.isCLI()) { message = switch (messageType) { case INFO -> "\033[92m" + message + "\033[0m"; - case WARN -> message = "\033[93m" + message + "\033[0m"; + case WARN -> "\033[93m" + message + "\033[0m"; case ERROR -> message = "\033[91m" + message + "\033[0m"; default -> message = message; }; From bcdac7164d8cf61fb8cea68f0250fee415495519 Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Wed, 8 Nov 2023 20:01:37 +0530 Subject: [PATCH 13/14] Update src/main/java/Utils/MessageBroker.java Co-authored-by: Saptarshi Sarkar --- src/main/java/Utils/MessageBroker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Utils/MessageBroker.java b/src/main/java/Utils/MessageBroker.java index 400709ad2..ade3adcc0 100644 --- a/src/main/java/Utils/MessageBroker.java +++ b/src/main/java/Utils/MessageBroker.java @@ -94,7 +94,7 @@ private void sendMessage(String message, MessageType messageType, MessageCategor case INFO -> "\033[92m" + message + "\033[0m"; case WARN -> "\033[93m" + message + "\033[0m"; case ERROR -> message = "\033[91m" + message + "\033[0m"; - default -> message = message; + default -> message; }; if (!messageCategory.equals(LOG)) { output.println(message); From 7c3745627ea72ab00e1174f857cb93b6f13e10d4 Mon Sep 17 00:00:00 2001 From: Groot <57068478+J9414@users.noreply.github.com> Date: Wed, 8 Nov 2023 20:02:45 +0530 Subject: [PATCH 14/14] Update src/main/java/Utils/MessageBroker.java Co-authored-by: Saptarshi Sarkar --- src/main/java/Utils/MessageBroker.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/Utils/MessageBroker.java b/src/main/java/Utils/MessageBroker.java index ade3adcc0..b507635f8 100644 --- a/src/main/java/Utils/MessageBroker.java +++ b/src/main/java/Utils/MessageBroker.java @@ -93,7 +93,7 @@ private void sendMessage(String message, MessageType messageType, MessageCategor message = switch (messageType) { case INFO -> "\033[92m" + message + "\033[0m"; case WARN -> "\033[93m" + message + "\033[0m"; - case ERROR -> message = "\033[91m" + message + "\033[0m"; + case ERROR -> "\033[91m" + message + "\033[0m"; default -> message; }; if (!messageCategory.equals(LOG)) {