From 532a35925c9d526d1c3961ab40208d39def81a80 Mon Sep 17 00:00:00 2001 From: Pinapelz Date: Thu, 3 Oct 2024 13:53:14 -0700 Subject: add option to import by list of urls into download config pane - good for youtube playlists --- src/main/java/DownloadConfigPane.java | 50 ++++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 12 deletions(-) (limited to 'src/main/java/DownloadConfigPane.java') diff --git a/src/main/java/DownloadConfigPane.java b/src/main/java/DownloadConfigPane.java index 8de09bb..1e9abb2 100644 --- a/src/main/java/DownloadConfigPane.java +++ b/src/main/java/DownloadConfigPane.java @@ -36,20 +36,31 @@ public class DownloadConfigPane extends JFrame{ loadFromFileButton.addActionListener(e -> loadConfigFromFile()); addButton.addActionListener(e -> { String url = urlField.getText(); - String from = fromField.getText(); - String to = toField.getText(); - if (url.isEmpty()){ - return; - } - if (from.length() != 8){ - from = "00:00:00"; + if(url.contains("youtu.be")){ + String[] split = url.split("/"); + url = "https://www.youtube.com/watch?v=" + split[split.length - 1]; } - if (to.length() != 8){ - to = "00:00:00"; + else if(url.contains("playlist") || url.contains("import")) { + String playlistUrls = + UI.Modal.textAreaDialog("Looks like you're trying to add a playlist or import by plaintext urls\n" + + "please use a tool https://cable.ayra.ch/ytdl/playlist.php to get the individual video URLs\n" + + "Delete all the text here and paste them here!", + "YouTube Playlist Import"); + try { + assert playlistUrls != null; + String[] urls = playlistUrls.split("\n"); + for (String playlistUrl : urls) { + addURLToTable(playlistUrl, "00:00:00", "00:00:00"); + } + } catch (Exception ex) { + JOptionPane.showMessageDialog(null, "Invalid playlist URLs. Make sure" + + "you only have 1 URL on each line in the text area and that they are valid YouTube video URLs"); + } } - Object[] song = new Object[]{url, from, to}; - DefaultTableModel model = (DefaultTableModel) outputTable.getModel(); - model.addRow(song); + String from = fromField.getText(); + String to = toField.getText(); + addURLToTable(url, from, to); + }); removeButton.addActionListener(e -> { int row = outputTable.getSelectedRow(); @@ -201,5 +212,20 @@ public class DownloadConfigPane extends JFrame{ JOptionPane.showConfirmDialog(null, "Saved to " + loadedPath, "Saved", JOptionPane.DEFAULT_OPTION); } + private void addURLToTable(String url, String from, String to){ + if (url.isEmpty()){ + return; + } + if (from.length() != 8){ + from = "00:00:00"; + } + if (to.length() != 8){ + to = "00:00:00"; + } + Object[] song = new Object[]{url, from, to}; + DefaultTableModel model = (DefaultTableModel) outputTable.getModel(); + model.addRow(song); + } + } -- cgit v1.2.3