diff options
| author | Pinapelz <yukais@pinapelz.com> | 2024-10-03 13:53:14 -0700 |
|---|---|---|
| committer | Pinapelz <yukais@pinapelz.com> | 2024-10-03 13:53:14 -0700 |
| commit | 532a35925c9d526d1c3961ab40208d39def81a80 (patch) | |
| tree | e35206c4b8681a96495c0b7a537ef6c5d2db9194 /src/main/java | |
| parent | 23bf59749a3018336fe6267e009e23b09fb38024 (diff) | |
add option to import by list of urls into download config pane
- good for youtube playlists
Diffstat (limited to 'src/main/java')
| -rw-r--r-- | src/main/java/DownloadConfigPane.java | 50 | ||||
| -rw-r--r-- | src/main/java/UI/Modal.java | 15 |
2 files changed, 53 insertions, 12 deletions
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); + } + } diff --git a/src/main/java/UI/Modal.java b/src/main/java/UI/Modal.java index c3fd045..ff3c0d1 100644 --- a/src/main/java/UI/Modal.java +++ b/src/main/java/UI/Modal.java @@ -2,6 +2,7 @@ package UI; import javax.swing.*; import javax.swing.filechooser.FileNameExtensionFilter; +import java.awt.*; public class Modal { public static String showTextFileChooser() { @@ -69,4 +70,18 @@ public class Modal { JOptionPane.showMessageDialog(null, message, "ERROR", JOptionPane.ERROR_MESSAGE); } + public static String textAreaDialog(String text, String title) { + JTextArea textArea = new JTextArea(text); + textArea.setColumns(30); + textArea.setRows(10); + textArea.setLineWrap(true); + textArea.setWrapStyleWord(true); + textArea.setSize(textArea.getPreferredSize().width, textArea.getPreferredSize().height); + int ret = JOptionPane.showConfirmDialog(null, new JScrollPane(textArea), title, JOptionPane.OK_OPTION); + if (ret == 0) { + return textArea.getText(); + } + return null; + } + } |
