aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-11-12 19:54:51 -0800
committerPinapelz <yukais@pinapelz.com>2025-11-12 19:54:51 -0800
commitb8e9549304761b624e1b92c1245054a960c6297b (patch)
tree5947a26bcb113521ee95ad5368e4fabf417c8019 /src/main/java
parent2e37c9643c27710c42b4d265a6c28a19fcec9198 (diff)
add confirmation before downloading for duplicate urls
checks the output dir to see if there is already a file with that videoId if it is, then show a confirmation prompt
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/Downloader.java6
-rw-r--r--src/main/java/FileUtility.java13
-rw-r--r--src/main/java/Main.java30
3 files changed, 47 insertions, 2 deletions
diff --git a/src/main/java/Downloader.java b/src/main/java/Downloader.java
index aed0bb4..c480a85 100644
--- a/src/main/java/Downloader.java
+++ b/src/main/java/Downloader.java
@@ -254,8 +254,6 @@ public class Downloader {
return true;
}
-
-
public static int timestampToSeconds(String timestamp) {
int totalSeconds = 0;
try {
@@ -271,4 +269,8 @@ public class Downloader {
}
return totalSeconds;
}
+
+ public boolean videoIdAlreadyDownloaded(String videoId){
+ return FileUtility.findFileContainingString(this.outputDirectory, videoId);
+ }
}
diff --git a/src/main/java/FileUtility.java b/src/main/java/FileUtility.java
index 1c532e4..936cecd 100644
--- a/src/main/java/FileUtility.java
+++ b/src/main/java/FileUtility.java
@@ -84,6 +84,19 @@ public class FileUtility {
return null;
}
+ public static boolean findFileContainingString(String directory, String searchString){
+ File dir = new File(directory);
+ File[] files = dir.listFiles();
+ assert files != null;
+ for(File file : files){
+ if(file.getName().contains(searchString)){
+ return true;
+ }
+ }
+ return false;
+ }
+
+
public static String findJsonFile(String folderName) {
File folder = new File(folderName);
File[] listOfFiles = folder.listFiles();
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index 474d244..7ab6572 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -6,6 +6,8 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Scanner;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
import com.formdev.flatlaf.FlatIntelliJLaf;
@@ -74,6 +76,21 @@ public class Main extends JFrame {
return (int) (((double) current / (double) total) * 100);
}
+ public static String extractVideoId(String youtubeUrl) {
+ if (youtubeUrl == null || youtubeUrl.isEmpty()) {
+ return null;
+ }
+ String pattern = "(?:youtube\\.com\\/(?:[^\\/]+\\/.+\\/|(?:v|e(?:mbed)?)\\/|.*[?&]v=)|youtu\\.be\\/)([^\"&?\\/ ]{11})";
+ Pattern compiledPattern = Pattern.compile(pattern);
+ Matcher matcher = compiledPattern.matcher(youtubeUrl);
+
+ if (matcher.find()) {
+ return matcher.group(1);
+ }
+
+ return null;
+ }
+
public void downloadAndTag() {
ArrayList<String> songs = FileUtility.txtToList(textPath);
String browser = configuration.get("browser");
@@ -83,6 +100,19 @@ public class Main extends JFrame {
for (String line : songs) {
System.out.println(line);
Downloader downloader = new Downloader(completedDir, outputArea);
+ String videoId = extractVideoId(line);
+ if(downloader.videoIdAlreadyDownloaded(videoId)){
+ int continueConfirm = JOptionPane.showConfirmDialog(
+ null,
+ "A file with the same video ID (" + videoId + ") already exists in the output directoy. Download anyways?",
+ "Potential duplicate detected",
+ JOptionPane.YES_NO_OPTION);
+ if(continueConfirm != JOptionPane.YES_OPTION){
+ System.out.println("Skipping this URL as requested by user");
+ songsProcessed++;
+ continue;
+ }
+ }
boolean success = false;
for (int attempt = 1; attempt <= 3; attempt++) {
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage