You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

gallery-dl-server

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gallery-dl-server

Web UI for downloading media with gallery-dl and yt-dlp.

0.8.1
pipPyPI
Maintainers
1

GitHub Release PyPI - Version Docker Image Version Docker Pulls GitHub Actions Workflow Status Commits License

screenshot

Web UI for gallery-dl with support for downloading videos via yt-dlp.

Running

Docker

Docker Run

This example uses the docker run command to create the container to run the app.

docker run -d \
  --name gallery-dl \
  -p "9080:9080" \
  -e "UID=1000" \
  -e "GID=1000" \
  -v "/path/to/config:/config" \
  -v "/path/to/downloads:/gallery-dl" \
  --restart on-failure \
  qx6ghqkz/gallery-dl-server:latest

Docker Compose

This is an example of a docker-compose.yaml service definition which can be used to start a running container with the docker compose up -d command.

services:
  gallery-dl:
    image: qx6ghqkz/gallery-dl-server:latest
    container_name: gallery-dl
    ports:
      - "9080:9080"
    environment:
      - "UID=1000"
      - "GID=1000"
    volumes:
      - "/path/to/config:/config"
      - "/path/to/downloads:/gallery-dl"
    restart: on-failure

This is another example which uses a VPN client container for its networking.

services:
  gallery-dl:
    image: qx6ghqkz/gallery-dl-server:latest
    container_name: gallery-dl
    network_mode: container:vpn
    environment:
      - "UID=1000"
      - "GID=1000"
    volumes:
      - "/path/to/config:/config"
      - "/path/to/downloads:/gallery-dl"
    restart: on-failure

Gluetun is recommended for VPN usage. See docs/docker-compose.yaml for an example.

Port Mapping

By default, this service listens on port 9080. Any value can be used for the host port, but the CONTAINER_PORT environment variable must be set to change the internal container port. This can be done using the -e flag with docker run or in a Docker Compose file.

For example, to run multiple instances of gallery-dl-server using a single Gluetun instance for the networking (each instance must use a different internal port), a different container port can be set for one of the containers.

services:
  instance-1:
    image: qx6ghqkz/gallery-dl-server:latest
    container_name: day
    depends_on:
      - gluetun
    network_mode: service:gluetun
    # More settings here...

  instance-2:
    image: qx6ghqkz/gallery-dl-server:latest
    container_name: night
    environment:
      - "CONTAINER_PORT=9090"
    depends_on:
      - gluetun
    network_mode: service:gluetun
    # More settings here...

  gluetun:
    image: qmcgaw/gluetun:latest
    container_name: vpn
    ports:
      # instance-1
      - "9080:9080"
      # instance-2
      - "9090:9090"
    # More settings here...

Important Notes

  • Make sure to mount the directory containing the configuration file rather than the file itself. This ensures changes to the configuration file are propagated to the running Docker container and it will not need to be restarted for changes to take effect. More information on this issue here.

  • The output download directory depends on the base-directory in your gallery-dl configuration file. Make sure it is the absolute path /gallery-dl/ instead of the relative path ./gallery-dl/ or else the download directory will need to be mounted to /usr/src/app/gallery-dl instead (not recommended).

  • The environment variables UID and GID can be used to change the user ID and group ID of the user running the server process. This is important because downloaded files will be owned by that user. Make sure the IDs match those of the user on the host system. The default UID:GID is 1000:1000 when left unspecified.

Python

If Python 3.10 or later (3.12 is recommended) is installed and on the PATH, the server can simply be run from the command line.

Run from Source

Clone this repository and install the dependencies located in requirements.txt in a virtual environment, then run the command below in the root folder while inside the virtual environment. On Windows, replace python3 with python.

python3 -m gallery_dl_server --host "0.0.0.0" --port "9080"

The command-line arguments are optional. By default, the server will run on host 0.0.0.0 and an available port will be selected if one is not provided.

To view the full list of command-line arguments, perform python3 -m gallery_dl_server --help. These arguments can also be provided as environment variables.

Installation

Installation allows running directly from the command line via the command gallery-dl-server. Using a virtual environment is recommended to avoid dependency conflicts.

From PyPI:

pip install gallery-dl-server

With optional dependencies:

pip install gallery-dl-server[full]

From source code (perform command in the root of the repository):

pip install .

With optional dependencies:

pip install .[full]

Once installed, perform gallery-dl-server --help to view the list of command-line options.

When installed, the log file is created directly in the home directory of the user, unless the package is found in the current working directory, in which case it is created in a logs folder in the same directory.

Run Programmatically

import gallery_dl_server as server

server.run(host="0.0.0.0", port=9080, log_level="info")

The run() method needs to be guarded with an if __name__ == "__main__" block on Windows due to how multiprocessing works.

Run with Uvicorn

python3 -m uvicorn gallery_dl_server.server:app --host "0.0.0.0" --port "9080" --log-level "info" --no-access-log

Standalone Executable

On Windows, the program can be run using the prebuilt .exe file, which includes a Python interpreter and the required Python packages. Prebuilt executables for each release can be found in Releases.

The executable can be run from the command line with the same arguments as the Python package.

gallery-dl-server.exe --host "0.0.0.0" --port "9080"

When run as an executable, the log file will be created in a logs folder in the same directory as the executable.

Configuration files can also be loaded from the same directory as the executable. The bundled releases contain a default configuration file in JSON, YAML and TOML formats.

Options

The server can be configured with numerous command-line arguments and environment variables. Command-line arguments take precedence over their equivalent environment variables.

Use the arguments when running the server directly from the command line, and the environment variables for configuring the server inside running containers.

Command-Line ArgumentEnvironment VariableDocker OnlyTypeExpected ValuesDefault ValueDescription
‑‑hostHOSTstrIP address or hostname0.0.0.0Specify the host address
‑‑portPORTint0–655350Specify the port to run the app
CONTAINER_PORTint0–655359080Set the internal container port
UIDintAny valid user ID1000User ID to run the server process
GIDintAny valid group ID1000Group ID to run the server process
UMASKintAny valid umask value022Set umask for file permissions
‑‑log‑dirLOG_DIRstrAny existing directory~Set the log file directory
‑‑log‑levelLOG_LEVELstrcritical
error
warning
info
debug
infoSet the download log level
‑‑server‑log‑levelSERVER_LOG_LEVELstrcritical
error
warning
info
debug
trace
infoSet the server log level
‑‑access‑logACCESS_LOGbooltrue
false
falseEnable the server access log

Note: CONTAINER_PORT takes precedence over the PORT environment variable in Docker containers to set the port the server will run on internally. This value and HOST should not normally need to be changed from their default values for Docker running.

Dependencies

All required and optional Python and non-Python dependencies are included in the Docker image, however if you are running gallery-dl-server using any of the other methods, some dependencies may need to be installed separately.

In order to run with Python, the dependencies in requirements.txt need to be installed in the running Python environment. These are included in the standalone executable and do not need to be installed.

Installation with pip only installs the required dependencies by default. Install gallery-dl-server[full] for the optional dependencies.

Optional

  • brotli or brotlicffi: Brotli content encoding support
  • mutagen: embed metadata and thumbnails in certain formats
  • pycryptodomex: decrypt AES-128 HLS streams and other forms of data
  • pyyaml: YAML configuration file support
  • toml: TOML configuration file support (<= Python 3.10 only)

Non-Python dependencies must be installed separately. FFmpeg is strongly recommended for video and audio conversion and should be accessible from the command line, i.e. on the PATH.

There is also MKVToolNix, which includes mkvmerge for accurate Ugoira frame timecodes.

Dependencies for gallery-dl and yt-dlp are documented in their respective repositories.

Configuration

Configuration of gallery-dl is as documented in the official documentation. A configuration file is required.

If run outside of Docker, the default locations will be used to search for a configuration file. If run as an executable, the current directory will also be searched for a valid configuration file.

Additionally, YAML and TOML configuration files are supported at any of the pre-defined locations.

When run with Docker, the configuration file must be inside the directory mounted to /config inside the container.

Locations

  • /config/gallery-dl.{conf, toml, yaml, yml}
  • /config/config.{json, toml, yaml, yml}

A default configuration file for use with gallery-dl-server will automatically be placed in the directory mounted to /config if none are found.

For more information on configuration file options, see gallery-dl/docs/configuration.rst.

Any additional locations specified in the configuration file must also exist in the Docker container. For example, if a cookies file is required, ensure it is also mounted inside the Docker container.

It is easiest to place any additional files inside the same directory as the configuration file.

Usage

Downloads can be triggered by supplying the {{url}} of the requested video through the web UI or through the REST interface via curl, etc.

Web UI

Navigate to http://{{host}}:{{port}}/gallery-dl and enter the requested {{url}}.

Curl

curl -X POST --data-urlencode "url={{url}}" http://{{host}}:{{port}}/gallery-dl/q

Fetch

fetch(`http://${host}:${port}/gallery-dl/q`, {
  method: "POST",
  body: new URLSearchParams({
    url: url
  })
});

Bookmarklet

The following bookmarklet can be used from the bookmarks bar to send the current page URL to a gallery-dl-server instance.

javascript:(function(){var url="http://${host}:${port}/gallery-dl/q",newTab=window.open(url,"_blank"),f=newTab.document.createElement("form");f.action=url;f.method="POST";var i=newTab.document.createElement("input");i.name="url";i.type="hidden";i.value=window.location.href;f.appendChild(i);newTab.document.body.appendChild(f);f.submit();})();

Implementation

This service operates using the ASGI web server uvicorn and is built on the starlette ASGI framework.

Downloads are handled by gallery-dl in conjunction with yt-dlp. The integration with gallery-dl uses Python as discussed in this issue. For video downloads, gallery-dl imports and uses yt-dlp.

The Docker image is based on python:3.12-alpine, which in turn is based on alpine.

yt-dlp

Keywords

image

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts