Giter VIP home page Giter VIP logo

youtube-dl-server's Introduction

Docker Stars Shield Docker Pulls Shield GitHub license

youtube-dl-server

Very spartan Web and REST interface for downloading YouTube videos onto a server. starlette + yt-dlp.

screenshot

Running

Docker CLI

This example uses the docker run command to create the container to run the app. Here we also use host networking for simplicity. Also note the -v argument. This directory will be used to output the resulting videos.

docker run -d --net="host" --name youtube-dl-server -v /home/core/youtube-dl:/youtube-dl qx6ghqkz/youtube-dl-server:latest

Docker Compose

This is an example service definition that could be put in docker-compose.yml. This service uses a VPN client container for its networking.

  youtube-dl-server:
    image: qx6ghqkz/youtube-dl-server:latest
    network_mode: container:vpn
    volumes:
      - /home/core/youtube-dl:/youtube-dl
    restart: unless-stopped

Python

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

YDL_UPDATE_TIME=False python3 -m uvicorn youtube-dl-server:app --port 8123

In this example, YDL_UPDATE_TIME=False is the same as the command line option --no-mtime.

Environment Variables

Environment variables can be set to change different settings, for example using docker run.

docker run -d \
  --name youtube-dl-server \
  --user 1000:1000 \
  -p 8080:8080 \
  -v /path/to/data:/data \
  --mount type=bind,source=/path/to/videos,target=/youtube-dl \
  -e YDL_FORMAT="bestvideo[ext=mp4]+bestaudio[ext=m4a]/bestvideo+bestaudio/best" \
  -e YDL_MERGE_OUTPUT_FORMAT="mp4/mkv" \
  -e YDL_OUTPUT_TEMPLATE="/youtube-dl/%(title).200s [%(id)s].%(ext)s" \
  -e YDL_NO_PLAYLIST=True \
  -e YDL_ARCHIVE_FILE="/data/archive.txt" \
  -e YDL_COOKIES_FILE="/data/cookies.txt" \
  -e YDL_IGNORE_ERRORS=True \
  -e YDL_WRITE_THUMBNAIL=True \
  -e YDL_THUMBNAIL_FORMAT="png/jpg" \
  -e YDL_WRITE_SUBTITLES=True \
  -e YDL_SUBTITLES_FORMAT="srt/vtt/best" \
  -e YDL_CONVERT_SUBTITLES="srt" \
  -e YDL_SUBTITLES_LANGS="en.*,ja" \
  -e YDL_EMBED_METADATA=True \
  --restart unless-stopped \
  qx6ghqkz/youtube-dl-server:latest

Environment variables can also be placed in a .env file when using docker compose up.

Environment Variable Type Default Value Notes
YDL_FORMAT String "bestvideo+bestaudio/best"
YDL_EXTRACT_AUDIO_FORMAT String None Set via web interface
YDL_EXTRACT_AUDIO_QUALITY String "192"
YDL_RECODE_VIDEO_FORMAT String None Set via web interface
YDL_MERGE_OUTPUT_FORMAT String None
YDL_OUTPUT_TEMPLATE String "/youtube-dl/%(title).200s [%(id)s].%(ext)s"
YDL_NO_PLAYLIST Boolean True Only download video if URL also references playlist
YDL_ARCHIVE_FILE String None Path to download archive, e.g. "/data/archive.txt"
YDL_COOKIES_FILE String None Path to cookie file, e.g. "/data/cookies.txt"
YDL_COOKIES_BROWSER String None Name of browser, e.g. "firefox"
YDL_UPDATE_TIME Boolean True
YDL_IGNORE_ERRORS Boolean/String True True/False/"only_download"
YDL_RESTRICT_FILENAMES Boolean False
YDL_GEO_BYPASS Boolean False
YDL_WRITE_THUMBNAIL Boolean True Thumbnail will be embedded
YDL_THUMBNAIL_FORMAT String None Image format to download and embed, e.g. "png/jpg"
YDL_WRITE_SUBTITLES Boolean False Subtitles will be embedded
YDL_SUBTITLES_FORMAT String None Subtitle format preference, e.g. "srt/vtt/best"
YDL_CONVERT_SUBTITLES String None Convert subtitles to format, e.g. "srt"
YDL_SUBTITLES_LANGS String "all" Can specify multiple, e.g. "en.*,ja"
YDL_EMBED_METADATA Boolean False

For more information on these options, see the yt-dlp docs and YouTubeDL object parameters.

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/youtube-dl and enter the requested {{url}}.

Curl

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

Fetch

fetch(`http://${host}:8080/youtube-dl/q`, {
  method: "POST",
  body: new URLSearchParams({
    url: url,
    format: "bestvideo"
  }),
});

Bookmarklet

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

javascript:!function(){fetch("http://${host}:8080/youtube-dl/q",{body:new URLSearchParams({url:window.location.href,format:"bestvideo"}),method:"POST"})}();

Implementation

The server uses starlette for the web framework and yt-dlp to handle the downloading. The integration with yt-dlp makes use of their Python API.

The Docker image is based on python:alpine and consequently alpine.

youtube-dl-server's People

Contributors

dependabot[bot] avatar manbearwiz avatar qx6ghqkz avatar github-actions[bot] avatar brunoamaral avatar noblekangaroo avatar pikuzheng avatar eleph-hub avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.