Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Jul 19, 2023. It is now read-only.

jim60105/docker-youtube-dl

Open more actions menu

Repository files navigation

youtube-dl Services on docker & Auto clean up

本專案從屬於 jim60105/docker-ReverseProxy
本專案logging經過調整,可搭配jim60105/docker-Seq使用

請參考 琳的備忘手札 Youtube直播錄影伺服器建置

本專案希望建置起能永久自動運作的Youtube直播備份機
此專案目標定位為「錄影備份」,在發生直播主事後砍檔時,我才會到伺服器尋找備份
是故,本專案不著重在錄影後的檔案處理,而是在磁碟滿時做自動刪檔

架構

WWW

nginx Server (Reverse Proxy) (SSL證書申請、Renew)
├ Jobber (Cron) (定時檢查磁碟使用率,在高於設定之百分比時,自動由舊起刪除錄影)
├ live-dl (直播監控錄影機)
└ youtube-dl-server (WebUI下載器)

說明

  • 錄影和下載會儲存在主機的 ../YoutubeRecordings/ 之下,可以在 docker-compose.yml修改
  • 可以在錄影完成後執行callback bash script
  • Jobber會在每日的01:00 UTC檢查磁碟使用率,並由舊檔案刪起,直到磁碟使用率降到設定值(或直到沒有檔案)

部屬

本專案有submodule
如果想要build docker image,請用git pull --recurse-submodules

  • 請參考 .env_sample 建立 .env
    • LETSENCRYPT_EMAIL=你的email
    • HOST=WebUI網址
    • DelPercentage=要執行刪除功能的磁碟使用百分比
    • LOGSERVER=GELF log server位置,詳細請參照後文
  • 請編輯 config_live-dl.yml 在map處建立名稱表,此表用於自動錄播時的資料夾建立
    - name: 久遠たま
      youtube: https://www.youtube.com/channel/UCBC7vYFNQoGPupe5NxPG4Bw
  • 請參考 Monitor/tama.sh 建立要自動錄播的頻道,所有Monitor下的檔案都會被執行
nohup /bin/bash live-dl {{Youtube URL}} &>/youtube-dl/logs/live-dl-{{Channel Name}}.$(date +%d%b%y-%H%M%S).log &
  • 給*.sh執行權限 find ./ -type f -iname "*.sh" -exec chmod +x {} \;
  • 正式發佈前移除 .env 中的 LETSENCRYPT_TEST=true
    此設定為SSL測試證書
    正式版有申請次數上限,務必在測試正常、最後上線前再移除

下載會員限定影片

youtube-dl支援以cookie的方式登入,可以下載會限影片

youtube-dl的帳密功能目前確定是壞的,只能以cookies方式登入
此cookies file包含了你的Youtube登入授權,請務必妥善保管

  • 安裝瀏覧器擴充功能,以匯出Netscape HTTP Cookie File
  • 瀏覧至Youtube網頁,登入你的帳號
  • 以擴充功能匯出youtube.com網域的所有cookie
  • 將匯出之cookie檔案重命名為cookies.txt
  • 取代專案根目錄下的cookies.txt檔,或用於docker run時的volume bind

錄影完成Callback

如果需要在下載完成後回呼,請修改docker-compose.yml,將回呼腳本bind至livedl之下的/usr/src/app/callback.sh

本專案提供的 download_again.sh ,能在下載完成後等待一分鐘,再下載第二次
由於串流中錄影容易有漏秒,這功能用於「直播結束後至Youtube版權砲前」再下載一次

callback.sh傳入之參數:

__info "Calling callback function..."
local cmd=( "$CALLBACK_EXEC" "${OUTPUT_PATH}.mp4" "$BASE_DIR/" "$VIDEO_ID" "$FULLTITLE" "$UPLOADER" "$UPLOAD_DATE" )
nohup "${cmd[@]}" &>> "$OUTPUT_PATH.log" &

bash參數

  1. 產出檔案的完整路徑
  2. 產出檔案之所在資料夾
  3. 影片id
  4. 影片標題
  5. 影片上傳者
  6. 上傳日期

Logging相關設定

本專案logging經過調整,可搭配Seq Log Server使用 (或是任何支援GELF http post的log server)\

  • 參考這個repo部屬Seq: https://github.com/jim60105/docker-Seq
  • .env正確設置LOGSERVER路徑,格式為IP:埠號
  • Monitor/*.sh註解掉File logging,改用「STDOUT logging (with log tag)」方式呼叫
  • download_again.sh註解掉File logging,改用「Docker logs logging (with log tag)」方式呼叫
  • 啟動指令改用docker-compose -f docker-compose.yml -f docker-compose.log-server.yml up -d
    或是將docker-compose.log-server.yml重命名為docker-compose.override.yml,使docker-compose up -d可以自動應用override檔

LICENSE: AGPL-3.0 License

本專案使用AGPL-3.0,遵循自 sparanoid/live-dl

Morty Proxy This is a proxified and sanitized view of the page, visit original site.