aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authorPinapelz <yukais@pinapelz.com>2025-10-15 17:02:17 -0700
committerPinapelz <yukais@pinapelz.com>2025-10-15 17:02:17 -0700
commit5f0c90afdd30f97a2f941053e62527c362babd60 (patch)
tree01c628c22d0a03ced35913454e66e3d5b84a0f22 /src/main
parent32c50bcc4d77e72f2b4af5f0778574fdd9b19dfd (diff)
fix: regular full video download (youtube block), added cookie extraction from browser
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/Configuration.java9
-rw-r--r--src/main/java/Downloader.java9
-rw-r--r--src/main/java/Main.java16
-rw-r--r--src/main/java/UI/Modal.java24
4 files changed, 49 insertions, 9 deletions
diff --git a/src/main/java/Configuration.java b/src/main/java/Configuration.java
index 90b30fd..6e01e82 100644
--- a/src/main/java/Configuration.java
+++ b/src/main/java/Configuration.java
@@ -45,6 +45,7 @@ public class Configuration {
configurationData.put("lastFile","" );
configurationData.put("outputPath", "completed");
configurationData.put("blacklistFile", "");
+ configurationData.put("browser", "");
try (FileWriter file = new FileWriter(configFile)) {
file.write(configurationData.toString(4));
System.out.println("Successfully created a stub config file");
@@ -62,8 +63,12 @@ public class Configuration {
JSONObject jsonObject = new JSONObject(tokener);
if (!jsonObject.has(key)) {
- System.out.println("Key does not exist in the configuration.");
- return false;
+ System.out.println("Key does not exist, creating new key...");
+ jsonObject.put(key, newValue);
+ try (FileWriter writer = new FileWriter(configFile)) {
+ writer.write(jsonObject.toString(4));
+ }
+ return true;
}
jsonObject.put(key, newValue);
diff --git a/src/main/java/Downloader.java b/src/main/java/Downloader.java
index 828d276..6442605 100644
--- a/src/main/java/Downloader.java
+++ b/src/main/java/Downloader.java
@@ -83,7 +83,7 @@ public class Downloader {
/*
Download a part of a video
*/
- public boolean download(String url, String stamp){
+ public boolean download(String url, String stamp, String browser){
ArrayList<String> times = new ArrayList<>(Arrays.asList(stamp.split("-")));
String startTime = times.get(0);
String endTime = times.get(1);
@@ -92,7 +92,7 @@ public class Downloader {
try {
ProcessBuilder builder = new ProcessBuilder(
"yt-dlp",
- "-vU","--force-keyframes",
+ "--force-keyframes",
"-f", "bestaudio[ext=webm]",
"--download-sections","*"+startSec+"-"+endSec,
"-o", "%(title)s[%(id)s].%(ext)s",
@@ -167,10 +167,11 @@ public class Downloader {
return true;
}
- public boolean download(String url){
+ public boolean download(String url, String browser){
String ytDlpExecutable = "yt-dlp" + (System.getProperty("os.name").startsWith("Windows") ? ".exe" : "");
try {
- String[] command = {ytDlpExecutable, "-f", "bestaudio[ext=webm]", "-x", "--audio-format", "mp3", "--write-info-json", url, "-o", "%(title)s[%(id)s].%(ext)s"};
+ String[] command = {ytDlpExecutable, "--min-sleep-interval","2", "--max-sleep-interval", "7","--cookies-from-browser",browser,"-f", "bestaudio[ext=webm]", "-x",
+ "--audio-format", "mp3", "--write-info-json", url, "-o", "%(title)s[%(id)s].%(ext)s"};
ProcessBuilder processBuilder = new ProcessBuilder(command);
processBuilder.directory(new File(System.getProperty("user.dir")));
Process process = processBuilder.start();
diff --git a/src/main/java/Main.java b/src/main/java/Main.java
index aa41b31..229d752 100644
--- a/src/main/java/Main.java
+++ b/src/main/java/Main.java
@@ -12,6 +12,7 @@ import com.formdev.flatlaf.FlatIntelliJLaf;
import javax.swing.*;
import javax.swing.text.DefaultCaret;
+import static UI.Modal.chooseBrowserType;
import static UI.Modal.showTextFileChooser;
@@ -74,6 +75,7 @@ public class Main extends JFrame {
public void downloadAndTag(){
ArrayList<String> songs = FileUtility.txtToList(textPath);
+ String browser = configuration.get("browser");
int totalSongs = songs.size();
int songsProcessed = 0;
for(String line: songs){
@@ -84,7 +86,7 @@ public class Main extends JFrame {
String stamp = parts[1];
Downloader downloader = new Downloader(completedDir, outputArea);
try{
- if(!downloader.download(url, stamp)){
+ if(!downloader.download(url, stamp, browser)){
UI.Modal.showError("Error downloading song: " + url + " at timestamp: " + stamp);
}
}
@@ -95,9 +97,10 @@ public class Main extends JFrame {
}
else{
+
Downloader downloader = new Downloader(completedDir, outputArea);
try{
- if(!downloader.download(line)){
+ if(!downloader.download(line, browser)){
UI.Modal.showError("Error downloading song: " + line);
}
}
@@ -264,6 +267,15 @@ public class Main extends JFrame {
}
} else {
+ if(!configuration.containsKey("browser") || configuration.get("browser").isEmpty()){
+ System.out.println("Browser not set, this is needed to read cookies");
+ String browser = chooseBrowserType();
+ if(browser.isEmpty()){
+ return;
+ }
+ config.modifyConfigurationValue("browser", browser);
+ configuration = config.readConfigurationData();
+ }
outputArea.setText(outputArea.getText() + "\n\n" + "Files will be saved to: " + completedDir);
Runnable runnable = () -> {
outputArea.setText("");
diff --git a/src/main/java/UI/Modal.java b/src/main/java/UI/Modal.java
index ff3c0d1..925f276 100644
--- a/src/main/java/UI/Modal.java
+++ b/src/main/java/UI/Modal.java
@@ -5,6 +5,7 @@ import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
public class Modal {
+ private static final String[] validBrowsers = {"brave", "chrome", "chromium", "edge", "firefox", "opera", "safari", "vivaldi", "whale"};
public static String showTextFileChooser() {
javax.swing.JFileChooser chooser = new javax.swing.JFileChooser();
FileNameExtensionFilter filter = new FileNameExtensionFilter("Text File", "txt", "text");
@@ -60,7 +61,7 @@ public class Modal {
* Show warning message
*/
public static void showWarning(String message) {
- JOptionPane.showMessageDialog(null, message, "JUST YOUR FRIENDLY NEIGHBORLY REMINDER", JOptionPane.WARNING_MESSAGE);
+ JOptionPane.showMessageDialog(null, message, "WARNING/REMINDER", JOptionPane.WARNING_MESSAGE);
}
/**
@@ -84,4 +85,25 @@ public class Modal {
return null;
}
+ public static String chooseBrowserType() {
+ JComboBox<String> dropdown = new JComboBox<>(validBrowsers);
+ JPanel panel = new JPanel(new BorderLayout(5, 5));
+ panel.add(new JLabel("Please select a browser you have used to sign into YouTube with on this device:"), BorderLayout.NORTH);
+ panel.add(dropdown, BorderLayout.CENTER);
+ int result = JOptionPane.showConfirmDialog(
+ null,
+ panel,
+ "Select Browser",
+ JOptionPane.OK_CANCEL_OPTION,
+ JOptionPane.PLAIN_MESSAGE
+ );
+ if (result == JOptionPane.OK_OPTION) {
+ return (String) dropdown.getSelectedItem();
+ } else {
+ return "";
+ }
+ }
+
+
+
}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage