Skip to content

Web / REST interface for downloading youtube videos onto a server.

License

Notifications You must be signed in to change notification settings

nbr23/youtube-dl-server

 
 

Repository files navigation

Docker Stars Shield Docker Pulls Shield GitHub license

youtube-dl-server

Simple Web and REST interface for downloading youtube videos onto a server. starlette + youtube-dl / yt-dlp

Forked from manbearwiz/youtube-dl-server.

screenshot

screenshot

Running

For easier deployment, a docker image is available on dockerhub:

  • nbr23/youtube-dl-server:youtube-dl to use youtube-dl
  • nbr23/youtube-dl-server:yt-dlp to use yt-dlp

Docker CLI

This example uses the docker run command to create the container to run the app. Note the -v argument to specify the volume and its binding on the host. This directory will be used to output the resulting videos.

docker run -d --name youtube-dl -p 8080:8080 -v $HOME/youtube-dl:/youtube-dl nbr23/youtube-dl-server:latest

OR for yt-dlp:

docker run -d --name youtube-dl -p 8080:8080 -v $HOME/youtube-dl:/youtube-dl nbr23/youtube-dl-server:yt-dlp

Docker Compose

This is an example service definition that could be put in docker-compose.yml.

  youtube-dl:
    image: "nbr23/youtube-dl-server:latest"
    volumes:
      - $HOME/youtube-dl:/youtube-dl
      - ./config.yml:/app_config/config.yml:ro # Overwrite the container's config file with your own configuration
    restart: always

Configuration

Configuration is done through the config.yml file at the root of the project.

An alternate configuration path or file path can be forced by setting the environment variable YDL_CONFIG_PATH:

export YDL_CONFIG_PATH=/var/local/youtube-dl-server/config.yml

In the above case, if /var/local/youtube-dl-server/config.yml does not exist, it will be created with the default options.

export YDL_CONFIG_PATH=/var/local/youtube-dl-server/

In the above case, if /var/local/youtube-dl-server/config.yml does not exist, it will be created with the default options as well.

The configuration file must contain at least the following variables:

ydl_server:
  port: 8080
  host: 0.0.0.0
  metadata_db_path: '/youtube-dl/.ydl-metadata.db'

ydl_options:
  output: '/youtube-dl/%(title)s [%(id)s].%(ext)s'
  cache-dir: '/youtube-dl/.cache'

Extra options

Additional youtube-dl parameters can be set in the ydl_options sections. To do this, simply add regular youtube-dl parameters, removing the leading --.

For example, to write subtitles in spanish, the youtube-dl command would be:

youtube-dl --write-sub --sub-lang es URL

Which would translate to the following ydl_options in config.yml:

ydl_options:
  output: '/tmp/youtube-dl/%(title)s [%(id)s].%(ext)s'
  cache-dir: '/tmp/youtube-dl/.cache'
  write-sub: True
  sub-lang: es

Profiles

You can also define profiles. They allow you to define configuration sets that can be selected in the UI.

Sample:

profiles:
  podcast:
      name: 'Audio Podcasts'
      ydl_options:
        output: '/youtube-dl/Podcast/%(title)s [%(id)s].%(ext)s'
        format: bestaudio/best
        write-thumbnail: True
        embed-thumbnail: True
        add-metadata: True
        audio-quality: 0
        extract-audio: True
        audio-format: mp3
  philosophy_lectures:
      name: 'Philosophy Lectures'
      ydl_options:
        output: '/youtube-dl/Lectures/Philosophy/%(title)s [%(id)s].%(ext)s'
        write-thumbnail: True
        embed-thumbnail: True
        add-metadata: True
        verbose: True

screenshot

Python

If you have python ^3.3.0 installed in your PATH you can simply run like this, providing optional environment variable overrides inline.

Install the python dependencies from requirements.txt:

pip install -r requirements.txt

You can run bootstrap.sh to download the required front-end libraries (jquery, bootstrap).

python3 -u ./youtube-dl-server.py

To force a specific youtube-dl version/fork (eg yt-dlp), use the variable YOUTUBE_DL:

YOUTUBE_DL=yt-dlp python3 -u ./youtube-dl-server.py

Usage

Start a download remotely

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

HTML

Just navigate to http://{{host}}:8080/ and enter the requested {{url}}.

Curl

curl -X POST  -H 'Content-Type: application/json' --data-raw '{"url":"{{ URL }}","format":"video/best"}' http://{{host}}:8080/api/downloads

Fetch

fetch(`http://${host}:8080/api/downloads`, {
  method: "POST",
  body: new URLSearchParams({
    url: url,
    format: "bestvideo"
  }),
});

Bookmarklet

Add the following bookmarklet to your bookmark bar so you can conviently send the current page url to your youtube-dl-server instance.

HTTPS

If your youtube-dl-server is served through https (behind a reverse proxy handling https for example), you can use the following bookmarklet:

javascript:fetch("https://${host}/api/downloads",{body:JSON.stringify({url:window.location.href,format:"bestvideo"}),method:"POST",headers:{'Content-Type':'application/json'}});

Plain text

If you are hosting it without HTTPS, the previous bookmarklet will likely be blocked by your browser (as it will generate mixed content when used on HTTPS sites).

Instead, you can use the following bookmarklet:

javascript:(function(){document.body.innerHTML += '<form name="ydl_form" method="POST" action="http://${host}/api/downloads"><input name="url" type="url" value="'+window.location.href+'"/></form>';document.ydl_form.submit()})();

Notes

Support extra formats

ffmpeg is required for format conversion and audio extraction in some scenarios.

Additional references

About

Web / REST interface for downloading youtube videos onto a server.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Vue 48.4%
  • Python 44.8%
  • Dockerfile 2.4%
  • JavaScript 1.9%
  • CSS 1.3%
  • HTML 0.7%
  • Shell 0.5%