• Stars
    star
    185
  • Rank 208,271 (Top 5 %)
  • Language
    Go
  • License
    MIT License
  • Created over 8 years ago
  • Updated 3 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

youtube-dl HTTP download and transcode service

youtube-dl HTTP service

HTTP service for yt-dlp that downloads media from requested URL and streams, transmux and transcode to requested format if needed.

It can be used to convert media, create podcasts and audio only versions of media from various site like youtube, vimeo etc.

Docker image uses ffmpeg from wader/static-ffmpeg which can handle most format and codecs. Default configuration can transcode to these format, container and codecs:

Format Container Audio Video Subtitle
alac mp4 alac
flac flac flac
m4a mp4 aac
mp3 mp3 mp3
ogg ogg vorbis, opus
wav wav pcm_s16le
mkv matroska aac, flac, alac, ac3, mp3, vorbis, opus h264, hevc, vp8, vp9, theora, av1 subrip, ass
mp4 mp4 aac, mp3, vorbis, flac, alac h264, hevc, av1 mov_text
mxf mxf pcm_s16le mpeg2video
ts mpegts aac, mp3, ac3 h264, hevc
webm webm vorbis, opus vp8, vp9, av1 webvtt
rss mp3 mp3

The rss format transforms a playlist into a RSS audio podcast.

See ydls.json for more details.

Usage

Run with docker

Pull mwader/ydls or build image using the Dockerfile. Run a container and publish TCP port 8080 somehow.

docker run -p 8080:8080 mwader/ydls

Build and install yourself

Run go get github.com/wader/ydls/cmd/ydls to install ydls. Make sure you have ffmpeg, yt-dlp, rtmpdump and mplayer installed and in PATH.

Copy and edit ydls.json to match your ffmpeg builds supported formats and codecs.

Start with ydls -server -config /path/to/ydls.json and it default will listen on port 8080.

Endpoints

Download and make sure media is in specified format:
GET /<format>[+option+option...]/<URL-not-encoded>
GET /?format=<format>&url=<URL>[&codec=...&codec=...&retranscode=...]

Download in best format:
GET /<URL-not-encoded>
GET /?url=<URL-encoded>

Parameters

format - Format name. See table above and ydls.json
URL - Any URL that yt-dlp can handle
URL-not-encoded - Non-URL-encoded URL. The idea is to be able to simply prepend the download URL with the ydls URL by hand without doing any encoding (for example in the browser location bar)
codec - Codec to use instead of default for format (can be specified one or two times for audio and video codec)
retranscode - Retranscode even if input codec is same as output
time - Only download specificed time range. Ex: 30s, 20m30s, 1h20s30s will limit duration. 10s-30s will seek 10 seconds and stop at 30 seconds (20 second output duration)
items - If playlist only include this many items

option - Codec name, time range, retranscode or <N>items

Examples

Download and make sure media is in mp3 format:
http://ydls/mp3/https://www.youtube.com/watch?v=cF1zJYkBW4A

Download using query parameters and make sure media is in mp3 format:
http://ydls/?format=mp3&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DcF1zJYkBW4A

Download and make sure media is in webm format:
http://ydls/webm/https://www.youtube.com/watch?v=cF1zJYkBW4A

Download and make sure media is in mkv format using mp3 and h264 codecs:
http://ydls/mkv+mp3+h264/https://www.youtube.com/watch?v=cF1zJYkBW4A

Download and retranscode to mp3 even if input is already mp3:
http://ydls/mp3+retranscode/https://www.youtube.com/watch?v=cF1zJYkBW4A

Download specified time range in mp3:
http://ydls/mp3+10s-30s/https://www.youtube.com/watch?v=cF1zJYkBW4A

Download in best format:
http://ydls/https://www.youtube.com/watch?v=cF1zJYkBW4A

Playlist as audio podcast with 3 latest items:
http://ydls/rss+3items/https://www.youtube.com/watch?list=PLtLJO5JKE5YCYgIdpJPxNzWxpMuUWgbVi

Tricks and known issues

For some formats the transcoded file might have zero length or duration as transcoding is done while streaming. This is usually not a problem for most players.

Download with curl and save to filename provided by response header:

curl -OJ http://ydls-host/mp3/https://www.youtube.com/watch?v=cF1zJYkBW4A

Docker image can download from command line. This will download in mp3 format to current directory:

docker run --rm -v "$PWD:$PWD" -w "$PWD" mwader/ydls https://www.youtube.com/watch?v=cF1zJYkBW4A mp3

yt-dlp URL can point to a plain media file.

If you run the service using some cloud services you might run into geo-restriction issues with some sites like youtube.

Development

When fiddling with ffmpeg and yt-dlp related code I usually do this:

docker build --target ydls-dev -t ydls-dev . && docker run --rm -ti -v "$PWD:/$PWD" -w "$PWD" ydls-dev

Then inside dev container:

# run cli version
go run cmd/ydls/main.go -config ./ydls.json -debug
# run all tests
CONFIG="$PWD/ydls.json" TEST_EXTERNAL=1 go test -v -cover -race ./...

TODO

  • Optional stream for format? example mp4 at least video or audio?
  • Download playlist as zip archive.
  • JSON output?
  • Refactor messy downloadFormat function. Maybe a media interface with audio, video and subtitle implementations that select best format and return reader and mappings? should share a common format picker so formats can be shared and not re-downloaded.
  • Make download part into an interface to support more than yt-dlp.
  • Bitrate factor per codec when sorting formats (prefer aac over mp3 at same bitrate etc)
  • X-Remote IP header?

License

ydls is licensed under the MIT license. See LICENSE for the full license text.

More Repositories

1

fq

jq for binary formats - tool, language and decoders for working with binary and text formats
Go
9,728
star
2

jqjq

jq implementation of jq
jq
674
star
3

static-ffmpeg

Multi-arch docker image with ffmpeg/ffprobe binaries built as hardened static PIE binaries with no external dependencies
Dockerfile
247
star
4

postfix-relay

Postfix SMTP relay docker image
Shell
122
star
5

ansisvg

Convert ANSI to SVG
Go
86
star
6

goutubedl

Go wrapper for youtube-dl and yt-dlp
Go
84
star
7

bump

A generic version tracking and update tool
Go
66
star
8

jq-lsp

jq language server
JSONiq
59
star
9

gormstore

GORM backend for gorilla sessions
Go
57
star
10

catgolf

cat(1) golf
42
star
11

rgen

Resource code generator for iOS inspired by Android resource handling
Objective-C
40
star
12

inkmake

Makefile inspired export from SVG files using Inkscape as backend with some added smartness.
Ruby
24
star
13

php-tftpserver

TFTP server written in PHP
PHP
22
star
14

ffcat

Preview media files in the shell
Go
17
star
15

vscode-jq

jq extension for VSCode
TypeScript
16
star
16

chromesthesia

Find out what song is playing in a Chrome tab
JavaScript
16
star
17

aes-arraybuffer

JavaScript AES and CBC implementation using ArrayBuffer
JavaScript
13
star
18

docker-webdav

WebDAV and web file browser server
Go
12
star
19

flac.tcl

Probably the slowest FLAC decoder in the world
Tcl
11
star
20

disable_sendfile_vbox_linux

Go VirtualBox vboxsf sendfile bug workaround
Go
11
star
21

crxreload

Reload Chrome extension automatically when files are changed
JavaScript
10
star
22

libfa

C automata library to build, determinize, minimize, translate regexp etc
C
10
star
23

ios-misc

Misc iOS related classes
Objective-C
10
star
24

respect

Resource inspector and lint tool to help find issues with resources in Xcode projects
Objective-C
10
star
25

gtktetris

Simple GTK tetris game
C
5
star
26

appsnax

Generate wireless app distribution mainifests for iOS directly from IPA files
PHP
5
star
27

static-gm

Image with graphicsmagick binary built as hardened static PIE binaries with no external dependencies
Dockerfile
5
star
28

filtertransport

Filtering go http transport and proxy handler
Go
4
star
29

static-shaka-packager

Image with shaka-packager binary built as hardened static PIE binaries with no external dependencies
Dockerfile
4
star
30

jq-dash-docset

Tools to generate jq dash docset
HTML
4
star
31

fultracker

Erlang bittorrent tracker experiment (Inactive project)
Erlang
3
star
32

maggie

Maggie, a GNU GameBoy Emulator (Inactive project)
C
3
star
33

textfiend

TCL implementation of the hexfiend binary template API
Tcl
3
star
34

htmx-dash-docset

</> htmx dash docset
HTML
3
star
35

slippy

iOS puzzle game featuring the hungry non-swimmer penguin Slippy that needs your help to catch fish
Objective-C
2
star
36

homebrew-tap

wader homebrew taps
Ruby
2
star
37

gameboy-games

Archive of GameBoy games I wrote many years ago
C
2
star
38

notify

Configurable inotify based file system monitor (Inactive project)
Python
2
star
39

objcheck

an ObjC port of the QuickCheck unit test framework
Objective-C
1
star
40

rails-misc

Misc ruby on rails goodies
Shell
1
star
41

citris

Circular Tetris (Inactive project)
C
1
star
42

fuse-misc

Misc FUSE file systems, ccxfuse, fusememfs, ircfs, pipefs, tagfs and erlfuse (Inactive projects)
C
1
star
43

gae-misc

Misc Google App Engine snippets
Python
1
star
44

chrome-search-spotify

Search Spotify Chrome extension
JavaScript
1
star
45

compose-hook

git hook for running docker-compose
Shell
1
star
46

lurker

Audio silence splitter (Inactive project)
C
1
star
47

vscode-go-debug-test

Test project for custom vscode-go debug command
Go
1
star
48

app-client-macos

Experimental appsocket support for macOS
Go
1
star
49

mo-mw-test

Testing
1
star
50

logutils

Various utils to be used with the go log package etc
Go
1
star
51

osleaktest

Checks for leaked fds, child processes and temp files
Go
1
star
52

firefox-all-spaces

Ugly hack to have a separate Firefox window visible on all Mac OS X spaces (workaround because afloat etc can't be used with Firefox)
Shell
1
star
53

language-jq

jq language support in Atom
1
star
54

hugo-dropbox

Docker image that serves a hugo site from dropbox
Nginx
1
star
55

json5.jq

JSON5 implementation for jq
jq
1
star