From b8e9549304761b624e1b92c1245054a960c6297b Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Wed, 12 Nov 2025 19:54:51 -0800 Subject: 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 --- src/main/java/Main.java | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'src/main/java/Main.java') 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 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++) { -- cgit v1.2.3