Skip to content

Commit

Permalink
Add instructions for setting-up custom config files
Browse files Browse the repository at this point in the history
  • Loading branch information
hstr0100 committed Nov 21, 2024
1 parent 7ed6764 commit 662624a
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 20 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,46 @@ Download the latest version for your platform from the [releases page](https://g
<img src="screenshot1.png" alt="Screenshot1" width="500"/>
<img src="screenshot2.png" alt="Screenshot2" width="500"/>

## Configurations

### Platform-Specific Configuration File Locations

The configuration files for GDownloader are stored in the following directories:

#### Windows

%USERPROFILE%\AppData\Roaming\GDownloader\

#### MacOS

~/Library/Application Support/GDownloader/

#### Linux

~/.gdownloader/

#### Portable Mode (All Platforms)

<Portable Installation Directory>/Internal/

In these directories, you will find the following configuration files:
- `config.json`: Main GDownloader configuration file in json format.
- `yt-dlp.conf`: Custom user configuration for the yt-dlp downloader. For instructions see [yt-dlp config](https://github.com/yt-dlp/yt-dlp?tab=readme-ov-file#configuration)
- `gallery-dl.conf`: Custom user configuration for the gallery-dl downloader. For instructions see [gallery-dl config](https://github.com/mikf/gallery-dl?tab=readme-ov-file#configuration)


For advanced users, you have the option to manually edit these configuration files to add custom parameters. e.g proxy settings.

Please be aware that some configuration parameters may conflict with GDownloader's internal settings passed to yt-dlp or gallery-dl. It is recommended to edit these files with caution.

### gallery-dl Support

To activate gallery-dl support, navigate to `Settings` > `Download Settings` and check the option `Enable gallery-dl downloader.`

### My Downloads Are Stuck Processing

If you are using a supported media player such as VLC, disabling the option `Convert audio to a widely supported codec (AAC)` under `Download Settings` will result in significant improvements in speed during the final processing step.

## Feedback

We welcome any feedback you may have to improve the user experience.
Expand Down
21 changes: 2 additions & 19 deletions core/src/main/java/net/brlns/gdownloader/GDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
import net.brlns.gdownloader.ui.themes.ThemeProvider;
import net.brlns.gdownloader.updater.*;
import net.brlns.gdownloader.util.*;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MessageFormatter;

import static net.brlns.gdownloader.lang.Language.*;

Expand Down Expand Up @@ -983,23 +981,8 @@ public void setDownloadsPath(File newDir) {
updateConfig();
}

private static final Object _logSync = new Object();

public void logUrl(String format, String file, Object... params) {
FormattingTuple ft = MessageFormatter.arrayFormat(format, params);
String message = ft.getMessage();

synchronized (_logSync) {
try (FileWriter fw = new FileWriter(getOrCreateDownloadsDirectory()
.toPath().resolve(file + ".txt").toFile(), true);
PrintWriter pw = new PrintWriter(fw)) {
for (String str : message.split("\n")) {
pw.println(str);
}
} catch (IOException e) {
log.warn("Cannot log to file", e);
}
}
public void logUrl(String fileName, String text, Object... replacements) {
FileUtils.logToFile(getOrCreateDownloadsDirectory(), fileName, text, replacements);
}

private void printDebugInformation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private void handleClipboardInput(String data, boolean force) {

// Small extra utility
if (main.getConfig().isLogMagnetLinks() && url.startsWith("magnet")) {
main.logUrl(url, "magnets");
main.logUrl("magnets", url);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import lombok.extern.slf4j.Slf4j;
import net.brlns.gdownloader.GDownloader;
import net.brlns.gdownloader.downloader.enums.DownloaderIdEnum;
import net.brlns.gdownloader.util.FileUtils;
import net.brlns.gdownloader.util.Nullable;

/**
Expand Down Expand Up @@ -73,6 +74,19 @@ protected void setExecutablePath(File executablePath) {
main.getDownloadManager().setExecutablePath(DownloaderIdEnum.GALLERY_DL, executablePath);
}

@Override
protected File doDownload(String url, File workDir) throws Exception {
File outputFile = super.doDownload(url, workDir);

File configFile = new File(workDir, "gallery-dl.conf");

if (!configFile.exists()) {
FileUtils.writeResourceToFile("/gallery-dl.conf", configFile);
}

return outputFile;
}

@Override
public String getName() {
return "Gallery-DL";
Expand Down
14 changes: 14 additions & 0 deletions core/src/main/java/net/brlns/gdownloader/updater/YtDlpUpdater.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import lombok.extern.slf4j.Slf4j;
import net.brlns.gdownloader.GDownloader;
import net.brlns.gdownloader.downloader.enums.DownloaderIdEnum;
import net.brlns.gdownloader.util.FileUtils;
import net.brlns.gdownloader.util.Nullable;

/**
Expand Down Expand Up @@ -73,6 +74,19 @@ protected void setExecutablePath(File executablePath) {
main.getDownloadManager().setExecutablePath(DownloaderIdEnum.YT_DLP, executablePath);
}

@Override
protected File doDownload(String url, File workDir) throws Exception {
File outputFile = super.doDownload(url, workDir);

File configFile = new File(workDir, "yt-dlp.conf");

if (!configFile.exists()) {
FileUtils.writeResourceToFile("/yt-dlp.conf", configFile);
}

return outputFile;
}

@Override
public String getName() {
return "YT-DLP";
Expand Down
75 changes: 75 additions & 0 deletions core/src/main/java/net/brlns/gdownloader/util/FileUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Copyright (C) 2024 hstr0100
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package net.brlns.gdownloader.util;

import java.io.*;
import java.nio.file.Files;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.helpers.FormattingTuple;
import org.slf4j.helpers.MessageFormatter;

/**
* @author Gabriel / hstr0100 / vertx010
*/
@Slf4j
public final class FileUtils {

public static void writeResourceToFile(String resourcePath, File destination) {
try {
InputStream inputStream = FileUtils.class.getResourceAsStream(resourcePath);

if (inputStream == null) {
throw new FileNotFoundException("Resource not found: " + resourcePath);
}

Files.createDirectories(destination.toPath().getParent());

try (InputStream in = inputStream;
OutputStream out = new FileOutputStream(destination)) {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
}
}
} catch (IOException e) {
log.error("Unable to write resource to file: {}", resourcePath, e);
}
}

private static final Object _logSync = new Object();

public static void logToFile(File baseDir, String fileName, String text, Object... replacements) {
FormattingTuple ft = MessageFormatter.arrayFormat(text, replacements);
String message = ft.getMessage();

File resolvedFile = baseDir.toPath()
.resolve(fileName + ".txt").toFile();

synchronized (_logSync) {
try (FileWriter fw = new FileWriter(resolvedFile, true);
PrintWriter pw = new PrintWriter(fw)) {
for (String str : message.split("\n")) {
pw.println(str);
}
} catch (IOException e) {
log.warn("Cannot log to file", e);
}
}
}

}
5 changes: 5 additions & 0 deletions core/src/main/resources/gallery-dl.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"#": "Configure your custom gallery-dl settings below.",
"#": "To activate these settings, enable \"Respect gallery-dl settings\" in GDownloader Settings.",
"#": "Note: Certain settings may conflict with GDownloader's internal parameters. Use with caution."
}
3 changes: 3 additions & 0 deletions core/src/main/resources/yt-dlp.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Configure your custom yt-dlp settings below.
# To activate these settings, enable "Respect yt-dlp settings" in GDownloader Settings.
# Note: Certain settings may conflict with GDownloader's internal parameters. Use with caution.

0 comments on commit 662624a

Please sign in to comment.