alexta69 / metube

Self-hosted YouTube downloader (web UI for youtube-dl / yt-dlp)
GNU Affero General Public License v3.0
6.68k stars 415 forks source link

[Help] How to configure cookies? #529

Open janusn opened 4 days ago

janusn commented 4 days ago

I have installed metube via docker compose using the following content as compose.yaml

---
services:
  metube:
    image: "ghcr.io/alexta69/metube"
    container_name: metube
    environment:
      CUSTOM_DIRS: true
      STATE_DIR: "/config"
      TEMP_DIR: "/tmp"
      YTDL_OPTIONS: '{"cookiefile":"/cookies/cookies.txt"}'
    deploy:
      resources:
        limits:
          memory: 4G
    volumes:
      - "./config:/config:rw"
      - "./cookies:/cookies:rw"
      - "/mnt/download:/downloads:rw"
      - type: tmpfs # Optional: 4GB of memory, reduces SSD/SD Card wear
        target: /tmp
        tmpfs:
          size: 4294967296
    ports:
      - "8081:8081"
    restart: unless-stopped

When I initiated download from the web UI, it failed. The docker logged the following messages:

INFO:aiohttp.access:10.27.0.40 [18/Oct/2024:20:26:05 +0000] "POST /delete HTTP/1.1" 200 287 "https://metube.home.arpa/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
INFO:ytdl:adding https://www.youtube.com/watch?v=OWcJwXmUhuk: quality='best' format='any' already=None folder=None custom_name_prefix='' playlist_strict_mode=False playlist_item_limit=0
WARNING: [youtube] Sign in to confirm your age. This video may be inappropriate for some users.
WARNING: No video formats found!
WARNING: Requested format is not available
DEBUG:ytdl:Processing as a video
INFO:ytdl:downloading Getting a Heart Transplant at Yale
INFO:aiohttp.access:10.27.0.40 [18/Oct/2024:20:26:06 +0000] "POST /add HTTP/1.1" 200 287 "https://metube.home.arpa/" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36"
WARNING: [youtube] Sign in to confirm your age. This video may be inappropriate for some users.
WARNING: No video formats found!
WARNING: Requested format is not available
ERROR: [youtube] OWcJwXmUhuk: No video formats found!
INFO:ytdl:waiting for item to download

However, when I called yt-dlp directly inside the container, it downloaded successfully as illustrated below:

# docker exec -it metube sh
/app # cd /downloads/
/downloads # yt-dlp --cookies '/cookies/cookies.txt' https://www.youtube.com/watch?v=OWcJwXmUhuk
[youtube] Extracting URL: https://www.youtube.com/watch?v=OWcJwXmUhuk
[youtube] OWcJwXmUhuk: Downloading webpage
[youtube] OWcJwXmUhuk: Downloading ios player API JSON
[youtube] OWcJwXmUhuk: Downloading mweb player API JSON
[youtube] OWcJwXmUhuk: Downloading player e627e516
[youtube] OWcJwXmUhuk: Downloading m3u8 information
[info] OWcJwXmUhuk: Downloading 1 format(s): 248+251
[download] Destination: Getting a Heart Transplant at Yale [OWcJwXmUhuk].f248.webm
[download] 100% of   57.10MiB in 00:00:01 at 35.56MiB/s
[download] Destination: Getting a Heart Transplant at Yale [OWcJwXmUhuk].f251.webm
[download] 100% of    6.30MiB in 00:00:00 at 41.37MiB/s
[Merger] Merging formats into "Getting a Heart Transplant at Yale [OWcJwXmUhuk].webm"
Deleting original file Getting a Heart Transplant at Yale [OWcJwXmUhuk].f251.webm (pass -k to keep)
Deleting original file Getting a Heart Transplant at Yale [OWcJwXmUhuk].f248.webm (pass -k to keep)

Could somebody tell me how to fix it? Many thanks!

PikuZheng commented 4 days ago

write /cookies/cookies.txt with Netscape format:

# Netscape HTTP Cookie File
www.youtube.com TRUE    /   FALSE   0   LOGIN_INFO  AFmm..........
...................
janusn commented 3 days ago

The cookies.txt file was written by a Chrome extension Get cookies.txt LOCALLY.

And I checked the content. It should be Netscape format:

# Netscape HTTP Cookie File
# This file is generated by yt-dlp.  Do not edit.

accounts.google.com FALSE   /   TRUE    1   OTZ 7…
accounts.google.com FALSE   /   TRUE    2   ACCOUNT_CHOOSER AFx_…
…

It should be correct as calling yt-dlp inside the container works as illustrated above.

janusn commented 15 hours ago

Instead of using the environment variable YTDL_OPTIONS, I work around by mapping a file on host to /etc/yt-dlp/config/yt-dlp.conf with the following content and it works. 😕

--cookies /cookies/cookies.txt