Skip to content

Commit

Permalink
Add option to include cookiefile
Browse files Browse the repository at this point in the history
This allows users to download age-restricted videos from
the web interface.
  • Loading branch information
cameronkinsella committed Jan 10, 2023
1 parent cdeaf3b commit bc44e54
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@ docker run -d --net="host" --name youtube-dl -v /home/core/youtube-dl:/youtube-d

### 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.
This is an example service definition that could be put in `docker-compose.yml`.
This service uses a VPN client container for its networking and has a cookie file for downloading age-restricted videos.

```yml
youtube-dl:
image: "kmb32123/youtube-dl-server"
network_mode: "service:vpn"
environment:
- YDL_COOKIE_FILE=youtube.com_cookies.txt
volumes:
- /home/core/youtube-dl:/youtube-dl
restart: always
Expand Down
6 changes: 5 additions & 1 deletion youtube-dl-server.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,18 @@ def get_ydl_options(request_options):
}
)

return {
options = {
"format": ydl_vars["YDL_FORMAT"],
"postprocessors": postprocessors,
"outtmpl": ydl_vars["YDL_OUTPUT_TEMPLATE"],
"download_archive": ydl_vars["YDL_ARCHIVE_FILE"],
"updatetime": ydl_vars["YDL_UPDATE_TIME"] == "True",
}

if ydl_vars["YDL_COOKIE_FILE"]:
options["cookiefile"] = f"/youtube-dl/{ydl_vars['YDL_COOKIE_FILE']}"

return options

def download(url, request_options):
with YoutubeDL(get_ydl_options(request_options)) as ydl:
Expand Down

0 comments on commit bc44e54

Please sign in to comment.