Skip to content

Commit

Permalink
fix: Fixed bad logic in download method for downloading a github file…
Browse files Browse the repository at this point in the history
… and fixed auto-close of input buffer before the user has given their input

1. A bad logic was present in the download method, which caused Drifty to pass the normal file download link to yt-dlp instead of downloading through URL java built-in class
2. An error (whitespace from the previous input) in the input buffer was preventing the input of yes/no for renaming a file whose name has been automatically detected.
  • Loading branch information
SaptarshiSarkar12 committed Jul 26, 2023
1 parent 40c65e4 commit 833328c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/main/java/Backend/FileDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -305,12 +305,13 @@ public void run() {
dir = dir + System.getProperty("file.separator");
}
try {
boolean isInstagramLink = Drifty_CLI.getIsInstagramLink();
boolean isInstagramImage = false;
if (isInstagramLink(link)) {
if (isInstagramLink) {
isInstagramImage = Drifty_CLI.getIsInstagramImage();
}
// If link is of an YouTube or Instagram video, then the following block of code will execute.
if (isYoutubeLink(link) || !isInstagramImage) {
if (isYoutubeLink(link) || (!isInstagramImage && isInstagramLink)) {
try {
String directoryOfYt_dlp = "./src/main/resources/";
messageBroker.sendMessage("Checking for component (yt-dlp) update ...", LOGGER_INFO, "download");
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/CLI/Drifty_CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,13 @@ private static void takeFileNameInputIfNull() {
}
} else {
System.out.print(RENAME_FILE);
SC.nextLine(); // To remove whitespace from the input buffer
String choiceString = SC.nextLine().toLowerCase();
boolean choice = utility.yesNoValidation(choiceString, ENTER_FILE_NAME_WITH_EXTENSION);
if (choice) {
System.out.print(ENTER_FILE_NAME_WITH_EXTENSION);
fileName = SC.nextLine();
}
}
}
}
Expand All @@ -275,4 +282,13 @@ private static void takeFileNameInputIfNull() {
public static boolean getIsInstagramImage() {
return isInstagramImage;
}

/**
* This method returns true if the given link is of Instagram
* @return True if the given link is of Instagram else false
* @since v2.0.0
*/
public static boolean getIsInstagramLink() {
return isInstagramLink;
}
}

1 comment on commit 833328c

@vercel
Copy link

@vercel vercel bot commented on 833328c Jul 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.