Skip to content

Commit

Permalink
fix: Fixed merge conflicts and broken support for Spotify filename de…
Browse files Browse the repository at this point in the history
…tection in Drifty CLI
  • Loading branch information
SaptarshiSarkar12 committed Oct 21, 2023
1 parent 16a877b commit 86799c1
Show file tree
Hide file tree
Showing 15 changed files with 169 additions and 349 deletions.
7 changes: 2 additions & 5 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 1 addition & 5 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions Documents

This file was deleted.

1 change: 0 additions & 1 deletion Documents.pub

This file was deleted.

5 changes: 1 addition & 4 deletions src/main/java/Backend/CopyExecutables.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,5 @@ public void copyExecutables(String[] executableNames) throws IOException {
}
}
}
if (Files.exists(Program.getExecutablesPath(executableNames[0]))) {
Files.exists(Program.getExecutablesPath(executableNames[1]));
}
}
}
}
48 changes: 5 additions & 43 deletions src/main/java/Backend/FileDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.List;
import java.util.Objects;

import static Enums.Program.SPOTDL;
import static Enums.Program.YT_DLP;
import static Utils.DriftyConstants.*;
import static Utils.Utility.*;
Expand Down Expand Up @@ -198,24 +197,21 @@ public void run() {
boolean isSpotifyLink = isSpotify(link);
try {
// If the link is of a YouTube or Instagram video, then the following block of code will execute.
if (isYouTubeLink || isInstagramLink || isSpotifyLink) {
if (isYouTubeLink || isInstagramLink) {
try {
if (isYouTubeLink) {
downloadFromYouTube();
} else if(isSpotifyLink){
downloadFromSpotify();
}
else{
} else {
downloadFromInstagram();
}
} catch (InterruptedException e) {
M.msgDownloadError(USER_INTERRUPTION);
} catch (Exception e) {
if (isYouTubeLink) {
M.msgDownloadError(YOUTUBE_DOWNLOAD_FAILED);
}else if(isSpotifyLink){
} else if (isSpotifyLink) {
M.msgDownloadError(SPOTIFY_DOWNLOAD_FAILED);
}else {
} else {
M.msgDownloadError(INSTAGRAM_DOWNLOAD_FAILED);
}
String msg = e.getMessage();
Expand Down Expand Up @@ -273,38 +269,4 @@ private void downloadFromInstagram() throws InterruptedException, IOException {
M.msgDownloadError(String.format(FAILED_TO_DOWNLOAD_F, fileDownloadMessage));
}
}

public void downloadFromSpotify() throws InterruptedException, IOException{
String outputFileName = Objects.requireNonNullElse(fileName, DEFAULT_FILENAME);
String fileDownloadMessage;
if (outputFileName.equals(DEFAULT_FILENAME)) {
fileDownloadMessage = "the Spotify File";
} else {
fileDownloadMessage = outputFileName;
}
M.msgDownloadInfo("Trying to download \"" + fileDownloadMessage + "\" ...");

String[] fullCommand = new String[]{Program.getSpotdl(SPOTDL), "download", link};
ProcessBuilder processBuilder = new ProcessBuilder(fullCommand);
processBuilder.inheritIO();

M.msgDownloadInfo(String.format(DOWNLOADING_F, fileDownloadMessage));
int exitValueOfSpotdl = -1;
try {
Process spotdlProcess = processBuilder.start();
spotdlProcess.waitFor();
exitValueOfSpotdl = spotdlProcess.exitValue();
} catch (IOException e) {
M.msgDownloadError("An I/O error occurred while initializing Spotify downloader! " + e.getMessage());
} catch (InterruptedException e) {
M.msgDownloadError("The Spotify download process was interrupted by the user! " + e.getMessage());
}

if (exitValueOfSpotdl == 0) {
M.msgDownloadInfo(String.format(SUCCESSFULLY_DOWNLOADED_F, fileDownloadMessage));
} else {
M.msgDownloadError(String.format(FAILED_TO_DOWNLOAD_F, fileDownloadMessage));
}
}

}
}
17 changes: 10 additions & 7 deletions src/main/java/CLI/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public class Main {
private static boolean batchDownloading;
private static String batchDownloadingFile;
private static final String msg_FileExists_NoHistory = "\"%s\" exists in \"%s\" folder. It will be renamed to \"%s\".";
private static final String msg_FileExists_HasHistory = "You have previously downloaded \"%s\" and it exists in \"%s\" folder. Do you want to download it again? ";
private static final String msg_FileExists_HasHistory = "You have previously downloaded \"%s\" and it exists in \"%s\" folder.\nDo you want to download it again? ";

public static void main(String[] args) {
logger.log(MessageType.INFO, CLI_APPLICATION_STARTED);
Expand Down Expand Up @@ -77,7 +77,6 @@ public static void main(String[] args) {
} else {
if (isURL(args[i])) {
link = args[i];

} else {
messageBroker.msgInitError("Invalid argument(s) passed!");
System.exit(1);
Expand All @@ -89,15 +88,11 @@ public static void main(String[] args) {
boolean isUrlValid;
if (Utility.isURL(link)) {
isUrlValid = Utility.isLinkValid(link);

} else {
isUrlValid = false;
messageBroker.msgLinkError("Link is invalid!");
}
if (isUrlValid) {
// isYoutubeURL = isYoutube(link);
// isInstagramLink = isInstagram(link);
// isSpotifyLink = isSpotify(link);
if (name == null) {
if (fileName == null || fileName.isEmpty()) {
messageBroker.msgFilenameInfo("Retrieving filename from link...");
Expand Down Expand Up @@ -344,19 +339,24 @@ private static void checkHistoryAddJobsAndDownload(Job job) {
fileName = Utility.renameFile(fileName, downloadsFolder);
System.out.printf(msg_FileExists_NoHistory + "\n", job.getFilename(), job.getDir(), fileName);
renameFilenameIfRequired(true);
if (isSpotifyLink) {
link = Utility.getSpotifyDownloadLink(link);
}
job = new Job(link, downloadsFolder, fileName, false);
jobHistory.addJob(job,true);
FileDownloader downloader = new FileDownloader(link, fileName, downloadsFolder);
downloader.run();
} else if (fileExists_HasHistory) {
System.out.printf(msg_FileExists_HasHistory, job.getFilename(), job.getDir());
SC.nextLine(); // to remove whitespace from input buffer
String choiceString = SC.nextLine().toLowerCase();
boolean choice = utility.yesNoValidation(choiceString, String.format(msg_FileExists_HasHistory, job.getFilename(), job.getDir()));
if (choice) {
fileName = Utility.renameFile(fileName, downloadsFolder);
System.out.println("New file name : " + fileName);
renameFilenameIfRequired(false);
if (isSpotifyLink) {
link = Utility.getSpotifyDownloadLink(link);
}
job = new Job(link, downloadsFolder, fileName, false);
jobHistory.addJob(job,true);
FileDownloader downloader = new FileDownloader(link, fileName, downloadsFolder);
Expand All @@ -365,6 +365,9 @@ private static void checkHistoryAddJobsAndDownload(Job job) {
} else {
jobHistory.addJob(job, true);
renameFilenameIfRequired(true);
if (isSpotifyLink) {
link = Utility.getSpotifyDownloadLink(link);
}
FileDownloader downloader = new FileDownloader(link, fileName, downloadsFolder);
downloader.run();
}
Expand Down
28 changes: 10 additions & 18 deletions src/main/java/Enums/Program.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

import java.nio.file.Path;
import java.nio.file.Paths;

public enum Program {
EXECUTABLE_NAME, YT_DLP, DRIFTY_PATH, JOB_HISTORY_FILE, JOB_FILE, SPOTDL;
YT_DLP_EXECUTABLE_NAME, SPOTDL_EXECUTABLE_NAME, YT_DLP, DRIFTY_PATH, JOB_HISTORY_FILE, JOB_FILE, SPOTDL;

private static String ytDLP;
private static String driftyPath;
private static String spotdl;

public static void setExecutableName(String name) {
public static void setYt_DlpExecutableName(String name) {
Program.ytDLP = name;
}
public static void setSpotdlExecutableName(String name) {
Expand All @@ -20,34 +21,25 @@ public static void setSpotdlExecutableName(String name) {

public static String get(Program program) {
return switch (program) {
case EXECUTABLE_NAME -> ytDLP;
case YT_DLP_EXECUTABLE_NAME -> ytDLP;
case SPOTDL_EXECUTABLE_NAME -> spotdl;
case DRIFTY_PATH -> driftyPath;
case YT_DLP -> Paths.get(driftyPath, ytDLP).toAbsolutePath().toString();
case SPOTDL -> Paths.get(driftyPath, spotdl).toAbsolutePath().toString();
case JOB_HISTORY_FILE -> Paths.get(driftyPath, "JobHistory.json").toAbsolutePath().toString();
case JOB_FILE -> Paths.get(driftyPath, "Jobs.json").toAbsolutePath().toString();
case SPOTDL -> Paths.get(driftyPath, spotdl).toAbsolutePath().toString();
};
}
public static String getSpotdl(Program program) {
return switch (program) {
case EXECUTABLE_NAME -> spotdl;
case DRIFTY_PATH -> driftyPath;
case YT_DLP -> Paths.get(driftyPath, ytDLP).toAbsolutePath().toString();
case JOB_HISTORY_FILE -> Paths.get(driftyPath, "JobHistory.json").toAbsolutePath().toString();
case JOB_FILE -> Paths.get(driftyPath, "Jobs.json").toAbsolutePath().toString();
case SPOTDL -> Paths.get(driftyPath, spotdl).toAbsolutePath().toString();
};
}

public static Path getYtDLPFullPath() {
return Paths.get(driftyPath, ytDLP);
public static Path getExecutablesPath(String executableName) {
return Paths.get(driftyPath, executableName).toAbsolutePath();
}

public static Path getSpotdlFullPath(){ return Paths.get(driftyPath,spotdl); }
public static Path getJsonDataPath() {
return Paths.get(driftyPath, "JsonData");
}

public static Path getSpotdlDataPath() {
return Paths.get(driftyPath, "JsonData/metafile.spotdl");
}
}
}
4 changes: 2 additions & 2 deletions src/main/java/GUI/Forms/AskYesNo.java
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ private void createControls() {
vbox = new VBox(30, text);
vbox.setAlignment(Pos.CENTER);
vbox.setPadding(new Insets(20));
if(state.equals(FILENAME)) {
if (state.equals(FILENAME)) {
vbox.getChildren().add(tfFilename);
}
switch(state) {
switch (state) {
case OK -> hbox.getChildren().add(btnOk);
case YES_NO, FILENAME -> hbox.getChildren().addAll(btnYes, btnNo);
}
Expand Down
Loading

0 comments on commit 86799c1

Please sign in to comment.