Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
SaptarshiSarkar12 authored Oct 18, 2022
2 parents 15c8dfe + f350c86 commit 754927e
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 36 deletions.
5 changes: 3 additions & 2 deletions .github/ISSUE_TEMPLATE/Bug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ body:
id: app-ver
attributes:
label: Application Version
description: Please select the application version (Check it here - https://github.com/SaptarshiSarkar12/Drifty/releases/latest/)
description: Please select the application version (Check it here - https://github.com/SaptarshiSarkar12/Drifty/releases/)
options:
- v1.2.0
- v1.1.0
- v1.0.0
validations:
Expand All @@ -64,4 +65,4 @@ body:
label: Additional information
description: Add any other context about the problem here.
validations:
required: false
required: false
5 changes: 3 additions & 2 deletions .github/ISSUE_TEMPLATE/feature-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ body:
id: app-ver
attributes:
label: Application Version
description: Please select the application version (Check it here - https://github.com/SaptarshiSarkar12/Drifty/releases/latest/)
description: Please select the application version (Check it here - https://github.com/SaptarshiSarkar12/Drifty/releases/)
options:
- v1.2.0
- v1.1.0
- v1.0.0
validations:
Expand All @@ -41,4 +42,4 @@ body:
label: Additional information
description: Add any other context about the feature here.
validations:
required: false
required: false
3 changes: 2 additions & 1 deletion .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ body:
id: app-ver
attributes:
label: Application Version
description: Please select the application version (Check it here - https://github.com/SaptarshiSarkar12/Drifty/releases/latest/)
description: Please select the application version (Check it here - https://github.com/SaptarshiSarkar12/Drifty/releases/)
options:
- v1.2.0
- v1.1.0
- v1.0.0
validations:
Expand Down
1 change: 1 addition & 0 deletions .idea/artifacts/Drifty_CLI_jar.xml

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

12 changes: 6 additions & 6 deletions Drifty.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
<chdir>.</chdir>
<priority>normal</priority>
<downloadUrl>http://java.com/download</downloadUrl>
<supportUrl>https://github.com/SaptarshiSarkar12/Drifty/issues/new/choose</supportUrl>
<supportUrl>https://github.com/SaptarshiSarkar12/Drifty/discussions/</supportUrl>
<stayAlive>false</stayAlive>
<restartOnCrash>true</restartOnCrash>
<restartOnCrash>false</restartOnCrash>
<manifest></manifest>
<icon>D:\Drifty\Drifty.ico</icon>
<jre>
Expand All @@ -24,12 +24,12 @@
<runtimeBits>64/32</runtimeBits>
</jre>
<versionInfo>
<fileVersion>1.1.0.0</fileVersion>
<txtFileVersion>1.0.0.0</txtFileVersion>
<fileVersion>1.2.0.0</fileVersion>
<txtFileVersion>1.1.0.0</txtFileVersion>
<fileDescription>Drifty is an open-source interactive File Downloader system built with java.</fileDescription>
<copyright>Copyright © 2022 - 32 Saptarshi Sarkar</copyright>
<productVersion>1.1.0.0</productVersion>
<txtProductVersion>1.0.0.0</txtProductVersion>
<productVersion>1.2.0.0</productVersion>
<txtProductVersion>1.1.0.0</txtProductVersion>
<productName>Drifty</productName>
<companyName></companyName>
<internalName>Drifty CLI</internalName>
Expand Down
Binary file modified Drifty_CLI.exe
Binary file not shown.
Binary file modified out/artifacts/Drifty_CLI_jar/Drifty.jar
Binary file not shown.
Binary file added out/production/Drifty/Drifty_CLI.class
Binary file not shown.
Binary file modified out/production/Drifty/FileDownloader.class
Binary file not shown.
33 changes: 18 additions & 15 deletions src/Drifty_CLI.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Drifty_CLI {
public static final String ANSI_PURPLE = "\u001B[35m";
private static boolean flag = false;
private static String fName = null;
protected static boolean isYoutubeURL;

/**
* This function is the main method of the whole application.
Expand All @@ -29,7 +30,7 @@ public static void main(String[] args) {
String URL = args[0];
String name = null;
String location = null;
for (int i = 0; i<args.length;i++){
for (int i = 0; i < args.length; i++){
if (Objects.equals(args[i], "-help") || Objects.equals(args[i], "-h")){
help();
System.exit(0);
Expand All @@ -39,12 +40,14 @@ public static void main(String[] args) {
location = args[i+1];
}
}
if (!isURLValid(URL)){
if (!isURLValid(URL)) {
System.out.println("URL is invalid!");
logger.log("ERROR", "URL is invalid!");
System.exit(0);
}
containsFile(URL);
isYoutubeURL = isYoutubeLink(URL);
fName = (name==null) ? fName : name;
if (fName==null && !isYoutubeURL(URL)){
if ((fName==null || !containsFilename(URL)) && (!isYoutubeURL)) {
System.out.print("Enter the filename (with file extension) : ");
fName = SC.nextLine();
}
Expand All @@ -60,24 +63,23 @@ public static void main(String[] args) {
}
}
}
FileDownloader fDownload = new FileDownloader(URL, fName, downloadsFolder);
fDownload.run();
new FileDownloader(URL, fName, downloadsFolder).run();
System.exit(0);
}
while(true) {
fName = null;
System.out.print("Enter the link to the file : ");
String link = SC.next();
while (true) {
if (isYoutubeURL(link)){
System.out.println("YOUTUBE URL DETECTED");
isYoutubeURL = isYoutubeLink(link);
if (isYoutubeURL){
break;
}
if (!isURLValid(link)) {
System.out.println("Invalid URL. Please enter again");
System.out.print("Enter the link to the file : ");
link = SC.next();
} else if (!containsFile(link)) {
} else if (!containsFilename(link)) {
System.out.println("Automatic file name detection failed!");
logger.log("ERROR", "Automatic file name detection failed!");
break;
Expand All @@ -87,7 +89,7 @@ public static void main(String[] args) {
}
SC.nextLine();
while (true){
if (isYoutubeURL(link)){
if (isYoutubeURL){
break;
}
if (fName != null) {
Expand Down Expand Up @@ -124,11 +126,11 @@ public static void main(String[] args) {
}
break;
}
FileDownloader fDownload = new FileDownloader(link, fName, downloadsFolder);
fDownload.run();
new FileDownloader(link, fName, downloadsFolder).run();
System.out.println("Press Q to Quit Or Press any Key to Continue");
String quit = SC.nextLine();
if(quit.equals("Q") || quit.equals("q")){
logger.log("INFO", "Application Terminated!");
break;
}
printBanner();
Expand Down Expand Up @@ -187,7 +189,7 @@ private static boolean isURLValid(String link){
}
}

public static boolean isYoutubeURL(String url) {
public static boolean isYoutubeLink(String url) {
String pattern = "^(http(s)?:\\/\\/)?((w){3}.)?youtu(be|.be)?(\\.com)?\\/.+";
return url.matches(pattern);
}
Expand All @@ -196,8 +198,8 @@ public static boolean isYoutubeURL(String url) {
* @param link Link to the file that the user wants to download
* @return true if the filename is detected and false if the filename is not detected
*/
private static boolean containsFile(String link){
// Check and inform user if the url contains file.
private static boolean containsFilename(String link){
// Check and inform user if the url contains filename.
// Example : "example.com/file.txt" prints "Filename detected: file.txt"
// example.com/file.json -> file.json
String file = link.substring(link.lastIndexOf("/")+1);
Expand All @@ -213,6 +215,7 @@ private static boolean containsFile(String link){
// file.png?width=200 -> file.png
fName = file.split("([?])")[0];
System.out.println("Filename detected : " + fName);
logger.log("INFO", "Filename detected : " + fName);
return true;
}

Expand Down
18 changes: 8 additions & 10 deletions src/FileDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import java.net.SocketTimeoutException;
import java.net.URL;
import java.net.URLConnection;
import java.nio.Buffer;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

Expand Down Expand Up @@ -54,17 +53,14 @@ public void run() {
}
}
try {
//If link is from youtube
if (Drifty_CLI.isYoutubeURL(link)) {
//If link is from YouTube
if (Drifty_CLI.isYoutubeLink(link)) {
//download youtube video
System.out.println("Downloading from youtube....");
System.out.println("Directory: " + dir);
System.out.println("Downloading ...");
Drifty_CLI.logger.log("INFO", "Downloading ...");

try {
Runtime runtime = Runtime.getRuntime();
ProcessBuilder processBuilder = new ProcessBuilder("yt-dlp", "-P", dir, link);
processBuilder.directory(new File(dir));

ProcessBuilder processBuilder = new ProcessBuilder("yt-dlp", "-q", "--progress", "-P", dir, link);
Process yt_dlp = processBuilder.start();

BufferedReader br = new BufferedReader(new InputStreamReader(yt_dlp.getInputStream()));
Expand All @@ -74,8 +70,10 @@ public void run() {
}
} catch (Exception e) {
e.printStackTrace();
Drifty_CLI.logger.log("ERROR", e.getMessage());
}
//System.exit(0);
System.out.println("Successfully downloaded the file.");
Drifty_CLI.logger.log("INFO", "Successfully downloaded the file");
}
else {
url = new URL(link);
Expand Down
Binary file added yt-dlp.exe
Binary file not shown.

0 comments on commit 754927e

Please sign in to comment.