Compare commits
26 Commits
32ed9bc81b
...
refactor/r
| Author | SHA1 | Date | |
|---|---|---|---|
| 2beb54f219 | |||
| f546c9fbb7 | |||
| 667b06fe4a | |||
| 033d9dd167 | |||
| 7a97e1f23d | |||
| a399a91ab0 | |||
| ec72c5657b | |||
| f8f625f0bf | |||
| 22fb495e0d | |||
| 33d5de6a77 | |||
| d539915486 | |||
| f173c64b70 | |||
| 750dc265ca | |||
| 846d07f099 | |||
| adca108376 | |||
| 748e3fb22a | |||
| 0968aa84b8 | |||
| b74f70c42e | |||
| 07cdae823a | |||
| 81619074d7 | |||
| 690f97ed82 | |||
| b772383d14 | |||
| 53fbcc5a8a | |||
| 713f316679 | |||
| 08bcc3d3bd | |||
| 0abf3a5adb |
1
.gitattributes
vendored
Normal file
1
.gitattributes
vendored
Normal file
@@ -0,0 +1 @@
|
||||
*.sh text eol=lf
|
||||
@@ -1,70 +1,72 @@
|
||||
name: build + push containers to gitea (every) and docker (daily)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "master" ]
|
||||
schedule:
|
||||
- cron: '0 0 * * 0' # weekly check
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
dockerhub:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Get current version
|
||||
id: current
|
||||
run: |
|
||||
CURRENT=$(cat version.txt || echo "none")
|
||||
echo "version=$CURRENT" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: check latest yt-dlp release
|
||||
id: latest
|
||||
run: |
|
||||
LATEST=$(curl -s https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest | jq -r .tag_name || echo "error")
|
||||
if [ "$LATEST" == "error" ]; then
|
||||
echo "failed to fetch latest version" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "yt-dlp version=$LATEST" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Update version file if changed
|
||||
run: echo ${{ steps.latest.outputs.version }} > version.txt
|
||||
if: ${{ steps.current.outputs.version != steps.latest.outputs.version }}
|
||||
|
||||
- name: Login to Dockerhub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Build and push to Dockerhub
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
push: true
|
||||
tags: |
|
||||
eulaly/youdis:latest
|
||||
eulaly/youdis:${{ steps.latest.outputs.version }}
|
||||
if: ${{ steps.current.outputs.version != steps.latest.outputs.version }}
|
||||
|
||||
gitea:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Login to Gitea (local)
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
registry: git.hgsky.me
|
||||
username: ${{ secrets.GITEA_USERNAME }}
|
||||
password: ${{ secrets.GITEA_TOKEN }}
|
||||
|
||||
- name: Build and push to Gitea (all pushes)
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
push: true
|
||||
tags: |
|
||||
git.hgsky.me/eulaly/youdis:latest
|
||||
git.hgsky.me/eulaly/youdis:dev-${{ github.sha }}
|
||||
|
||||
name: push new builds to gitea, dockerhub
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: ["master"]
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Get youdis version
|
||||
id: youdis
|
||||
run: |
|
||||
YOUDIS_VER=$(cat youdis-version.txt)
|
||||
if [ -z "$YOUDIS_VER" ]; then
|
||||
echo "youdis version empty" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "youdis-version=$YOUDIS_VER" >> $GITHUB_OUTPUT
|
||||
echo "shortsha=${GITHUB_SHA::5}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Decide if build needed
|
||||
id: check_build
|
||||
run: |
|
||||
SHOULD_BUILD=false
|
||||
if [ "${{ steps.youdis.outputs.youdis-version }}" != "$(docker inspect --format='{{ index .Config.Labels "YOUDIS_VERSION" }}' eulaly/youdis:latest || echo none)" ]; then
|
||||
SHOULD_BUILD=true
|
||||
fi
|
||||
echo "should_build=$SHOULD_BUILD" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Login to Dockerhub
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Build and push to Dockerhub
|
||||
if: ${{ steps.check_build.outputs.should_build == 'true' }}
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
push: true
|
||||
tags: |
|
||||
eulaly/youdis:latest
|
||||
eulaly/youdis:${{ steps.youdis.outputs.shortsha }}
|
||||
labels: |
|
||||
YOUDIS_VERSION=${{ steps.youdis.outputs.youdis-version }}
|
||||
|
||||
- name: Login to Gitea
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: git.hgsky.me
|
||||
username: ${{ secrets.USERNAME }}
|
||||
password: ${{ secrets.YOUDIS_PASSWORD }}
|
||||
|
||||
- name: Build and push to Gitea
|
||||
if: ${{ steps.check_build.outputs.should_build == 'true' }}
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
push: true
|
||||
tags: |
|
||||
git.hgsky.me/ben/youdis:latest
|
||||
git.hgsky.me/ben/youdis:${{ steps.youdis.outputs.shortsha }}
|
||||
labels: |
|
||||
YOUDIS_VERSION=${{ steps.youdis.outputs.youdis-version }}
|
||||
|
||||
- name: link container in gitea
|
||||
run: |
|
||||
curl -X POST -H "Authorization: token ${{ secrets.SUPER }}" https://git.hgsky.me/api/v1/packages/ben/container/youdis/-/link/youdis
|
||||
|
||||
|
||||
44
.github/workflows/docker-build.yaml
vendored
44
.github/workflows/docker-build.yaml
vendored
@@ -1,44 +0,0 @@
|
||||
name: Check yt-dlp and rebuild if new
|
||||
on:
|
||||
schedule:
|
||||
- cron: '0 0 * * 0'
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Get current version
|
||||
id: current
|
||||
run: |
|
||||
CURRENT=$(cat version.txt || echo "none")
|
||||
echo "version=$CURRENT" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Check latest version
|
||||
id: latest
|
||||
run: |
|
||||
LATEST=$(curl -s https://api.github.com/repos/yt-dlp/yt-dlp/releases/latest | jq -r .tag_name || echo "error")
|
||||
if [ "$LATEST" == "error" ]; then
|
||||
echo "failed to fetch latest version" >&2
|
||||
exit 1
|
||||
fi
|
||||
echo "version=$LATEST" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Update version file if changed
|
||||
run: echo ${{ steps.latest.outputs.version }} > version.txt
|
||||
if: ${{ steps.current.outputs.version != steps.latest.outputs.version }}
|
||||
|
||||
- name: Login to Dockerhub
|
||||
uses: docker/login-action@v2
|
||||
with:
|
||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||
|
||||
- name: Build and push docker image
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
push: true
|
||||
tags: eulaly/youdis:latest,eulaly/youdis:${{ steps.latest.outputs.version }}
|
||||
if: ${{ steps.current.outputs.version != steps.latest.outputs.version }}
|
||||
47
.gitignore
vendored
47
.gitignore
vendored
@@ -1,13 +1,34 @@
|
||||
*.pyc
|
||||
*.org
|
||||
*.ps1
|
||||
.env
|
||||
#*
|
||||
.#*
|
||||
__pycache__/
|
||||
venv/
|
||||
archive/
|
||||
config/
|
||||
downloads/
|
||||
data.json
|
||||
|
||||
# --- python bytecode ---
|
||||
__pycache__/
|
||||
*.py[cod]
|
||||
*$py.class
|
||||
|
||||
# --- virtual environments ---
|
||||
.venv/
|
||||
venv/
|
||||
env/
|
||||
|
||||
# --- environment files ---
|
||||
.env
|
||||
.env.*
|
||||
*.local
|
||||
|
||||
# --- emacs ---
|
||||
*~
|
||||
\#*\#
|
||||
.\#*
|
||||
*.elc
|
||||
|
||||
# --- project private data ---
|
||||
/private/
|
||||
archive/
|
||||
downloads/
|
||||
data.json
|
||||
|
||||
# --- django ---
|
||||
db.sqlite3
|
||||
staticfiles/
|
||||
media/
|
||||
|
||||
# --- misc ---
|
||||
.DS_Store
|
||||
48
LICENSE
48
LICENSE
@@ -1,24 +1,24 @@
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <https://unlicense.org>
|
||||
This is free and unencumbered software released into the public domain.
|
||||
|
||||
Anyone is free to copy, modify, publish, use, compile, sell, or
|
||||
distribute this software, either in source code form or as a compiled
|
||||
binary, for any purpose, commercial or non-commercial, and by any
|
||||
means.
|
||||
|
||||
In jurisdictions that recognize copyright laws, the author or authors
|
||||
of this software dedicate any and all copyright interest in the
|
||||
software to the public domain. We make this dedication for the benefit
|
||||
of the public at large and to the detriment of our heirs and
|
||||
successors. We intend this dedication to be an overt act of
|
||||
relinquishment in perpetuity of all present and future rights to this
|
||||
software under copyright law.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||
IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
||||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
||||
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
For more information, please refer to <https://unlicense.org>
|
||||
|
||||
16
README.md
16
README.md
@@ -1,8 +1,8 @@
|
||||
build and run the docker container
|
||||
```
|
||||
api_token = [discord bot token]
|
||||
-v [downloads]:/downloads
|
||||
-v [config]:/config
|
||||
```
|
||||
config contains data to persist across container updates, i.e., unraid appdata,
|
||||
such as users.json (authorized users) and yt-dlp's archive.txt
|
||||
build and run the docker container
|
||||
```
|
||||
api_token = [discord bot token]
|
||||
-v [downloads]:/downloads
|
||||
-v [config]:/config
|
||||
```
|
||||
config contains data to persist across container updates, i.e., unraid appdata,
|
||||
such as users.json (authorized users) and yt-dlp's archive.txt
|
||||
|
||||
60
banner.svg
60
banner.svg
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 24 KiB After Width: | Height: | Size: 24 KiB |
@@ -1,8 +0,0 @@
|
||||
#!/bin/sh
|
||||
#copy yt-dlp.conf if missing
|
||||
mkdir -p /config
|
||||
if [ ! -f /config/yt-dlp.conf ]; then
|
||||
cp /app/default-yt-dlp.conf /config/yt-dlp.conf
|
||||
fi
|
||||
|
||||
exec "$@"
|
||||
@@ -1,11 +1,11 @@
|
||||
# yt-dlp config file (yt-dlp.conf or .config/yt-dlp/config)
|
||||
--simulate
|
||||
-f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"
|
||||
--embed-chapters
|
||||
--embed-info-json
|
||||
--write-playlist-metafiles
|
||||
#--paths "{"home":"./downloads"}"
|
||||
--download-archive "/config/archive.txt"
|
||||
--restrict-filenames
|
||||
--output "/downloads/%(uploader)s/%(playlist_title)s/%(playlist_index)s%(playlist_index& - )s%(title)s.%(ext)s"
|
||||
# yt-dlp config file (yt-dlp.conf or .config/yt-dlp/config)
|
||||
--simulate
|
||||
-f "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best"
|
||||
--embed-chapters
|
||||
--embed-info-json
|
||||
--write-playlist-metafiles
|
||||
#--paths "{"home":"./downloads"}"
|
||||
--download-archive "/config/archive.txt"
|
||||
--restrict-filenames
|
||||
--output "/downloads/%(uploader)s/%(playlist_title)s/%(playlist_index)s%(playlist_index& - )s%(title)s.%(ext)s"
|
||||
# --split-chapters
|
||||
30
dockerfile
30
dockerfile
@@ -1,14 +1,16 @@
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM python:3.12.1-alpine3.18
|
||||
WORKDIR /app
|
||||
RUN apk update && \
|
||||
apk add --no-cache build-base ffmpeg && \
|
||||
rm -rf /var/cache/apk/*
|
||||
COPY requirements.txt requirements.txt
|
||||
RUN python3 -m pip install --no-cache-dir -r requirements.txt
|
||||
COPY youdis.py youdis.py
|
||||
COPY default-yt-dlp.conf /app/default-yt-dlp.conf
|
||||
COPY create-ytdlp-config.sh /app/create-ytdlp-config.sh
|
||||
RUN chmod 755 /app/create-ytdlp-config.sh
|
||||
ENTRYPOINT ["/app/create-ytdlp-config.sh"]
|
||||
CMD ["python3", "youdis.py"]
|
||||
# syntax=docker/dockerfile:1
|
||||
FROM python:3.12.1-alpine3.18
|
||||
WORKDIR /app
|
||||
RUN apk update && \
|
||||
apk add --no-cache build-base ffmpeg && \
|
||||
rm -rf /var/cache/apk/*
|
||||
COPY requirements.txt .
|
||||
RUN python3 -m pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY youdis.py default-yt-dlp.conf update-ytdlp.sh run-youdis.sh /app/
|
||||
RUN chmod +x /app/update-ytdlp.sh /app/run-youdis.sh
|
||||
|
||||
COPY weekly-restart /etc/cron.d/
|
||||
RUN chmod 0644 /etc/cron.d/weekly-restart
|
||||
|
||||
ENTRYPOINT ["/app/run-youdis.sh"]
|
||||
|
||||
21
pm/task-sample.org
Normal file
21
pm/task-sample.org
Normal file
@@ -0,0 +1,21 @@
|
||||
#+title: Task Log
|
||||
#+updated: [2026-03-31 Tue 16:03]
|
||||
|
||||
Use the template below, which should be a top-level org-mode header.
|
||||
|
||||
* [ ] M.m.m: Task Title (# commits)
|
||||
description of the task
|
||||
** pm notes: amplifying information
|
||||
|
||||
** Acceptance Criteria
|
||||
1. Criterion
|
||||
- expanded data
|
||||
2. Criterion
|
||||
|
||||
** evidence
|
||||
- commit: abc123, bcd234
|
||||
- tests:
|
||||
- datetime: [2026-03-18 Wed 14:15]
|
||||
|
||||
** notes
|
||||
- explanation of work done, decisions made, reasoning
|
||||
123
pm/tasks.org
Normal file
123
pm/tasks.org
Normal file
@@ -0,0 +1,123 @@
|
||||
#+title: Youdis Task Log
|
||||
#+updated: [2026-03-31 Tue 08:00]
|
||||
|
||||
* [X] 1.1.1: stabilize youdis core bot behavior (estimate 3 commits)
|
||||
refactor the current `youdis.py` flow so authorization, download execution, and user feedback are correct and predictable without changing the product shape. keep this narrowly scoped to correctness and maintainability; do not redesign into a queueing platform yet. preserve archive-first behavior and dm status updates; do not add new infrastructure dependencies and prefer boring explicit state over clever concurrency.
|
||||
|
||||
** acceptance criteria
|
||||
1. initialize and load `/config/users.json` safely in all cases
|
||||
- create parent dirs before touch/open
|
||||
- ensure `authorized_users` always has a valid default
|
||||
- normalize stored ids to a single type
|
||||
2. fix command-path correctness for `/youtube`, `/adduser`, and `/removeuser`
|
||||
- authorized users can successfully invoke downloads
|
||||
- add/remove user commands persist changes correctly
|
||||
- remove broken/incomplete code paths
|
||||
3. duplicate prevention relies on archive.txt
|
||||
|
||||
** pm notes
|
||||
|
||||
** evidence
|
||||
- commit: 033d9dd
|
||||
- tests: ~python3 -m py_compile ./youdis.py~
|
||||
- datetime: [2026-03-31 Tue 13:28]
|
||||
|
||||
** notes
|
||||
- store Discord user ids as strings in `users.json`
|
||||
- duplicate prevention should continue to rely on `archive.txt`, not inferred hook errors
|
||||
|
||||
* [X] 1.1.2: remove global mutable download state and define single-job semantics (estimate 2 commits)
|
||||
eliminate shared mutable hook state and make concurrent behavior explicit, even if the initial policy is just "one active job at a time." don't build a scheduler; ok if simplest outcome is single active job with clear busy message. cancellation can be coarse if yt-dlp/process boundaries make graceful stop annoying
|
||||
|
||||
** acceptance criteria
|
||||
1. improve runtime handling for downloads
|
||||
- replace brittle thread/join pattern with a simpler async-safe execution path
|
||||
- catch and report real yt-dlp failures
|
||||
- avoid misleading "already exists" error assumptions
|
||||
2. progress reporting is isolated per request
|
||||
- no module-level mutable title state shared across jobs
|
||||
- hooks derive state from request-local context
|
||||
3. active-job behavior is explicit
|
||||
- either reject a second request while busy or implement a minimal tracked active job
|
||||
- user-facing response explains current behavior
|
||||
4. `/interrupt` is either implemented minimally or downgraded honestly
|
||||
- no fake command implying cancellation works when it does not
|
||||
- command behavior matches implementation
|
||||
|
||||
** evidence
|
||||
- commit: 667b06f
|
||||
- tests: ~python3 -m py_compile /home/user/proj/youdis/youdis.py~
|
||||
- datetime: [2026-03-31 Tue 14:00]
|
||||
|
||||
** notes
|
||||
- verify slash-command response patterns against the `interactions` library while touching runtime flow
|
||||
|
||||
* [ ] 1.1.3: move static yt-dlp behavior into config and shrink python surface area (estimate 2 commits)
|
||||
shift stable downloader options into `default-yt-dlp.conf` so the bot code only handles dynamic inputs and orchestration. optimize for inspectability and low-friction manual ops. keep output naming durable enough for plex/plain-file use. avoid duplicating config values across code and conf.
|
||||
|
||||
** acceptance criteria
|
||||
1. separate static vs dynamic yt-dlp options cleanly
|
||||
- stable defaults live in `default-yt-dlp.conf`
|
||||
- python injects only request-specific/runtime values
|
||||
2. preserve archive and output behavior
|
||||
- `archive.txt` remains the duplicate-prevention mechanism
|
||||
- output paths remain stable and browseable
|
||||
3. document config ownership
|
||||
- clarify which settings belong in config vs code
|
||||
- make future yt-dlp tuning possible without major python edits
|
||||
|
||||
** evidence
|
||||
- commit:
|
||||
- tests:
|
||||
- datetime:
|
||||
|
||||
** notes
|
||||
|
||||
* [ ] 1.1.4: simplify image/build/update workflow around manual ops (estimate 3 commits)
|
||||
reduce repo cruft from the gitea-runner/nightly-update experiment and replace it with explicit manual update/rebuild mechanics.
|
||||
|
||||
** acceptance criteria
|
||||
1. define a manual update path for yt-dlp and app image lifecycle
|
||||
- document or script manual `git pull`, rebuild, and redeploy
|
||||
- remove or quarantine brittle auto-update assumptions
|
||||
2. review and simplify `update-ytdlp.sh`, workflow yaml, and weekly restart artifacts
|
||||
- keep only artifacts that serve the current manual-ops model
|
||||
- delete or mark deprecated anything tied to abandoned automation paths
|
||||
3. retain unraid deployment viability
|
||||
- container can still be rebuilt and redeployed cleanly on jeeves
|
||||
- resulting flow is understandable without rereading old ci experiments
|
||||
|
||||
- pm note: weekly restart is presumed suspect until proven necessary
|
||||
|
||||
** evidence
|
||||
- commit:
|
||||
- tests:
|
||||
- datetime:
|
||||
|
||||
** notes
|
||||
- do not let runner/workflow complexity dominate a small bot
|
||||
- prefer explicit version pinning or manual binary refresh over magical nightlies
|
||||
|
||||
* [ ] 1.1.5: clean up packaging/deployment artifacts for unraid consumption (estimate 2 commits)
|
||||
make the dockerfile, run script, and unraid-ca template consistent with the refactored app so deployment is less of a ritual ordeal.
|
||||
|
||||
** acceptance criteria
|
||||
1. align docker/runtime assumptions
|
||||
- paths like `/config` and `/downloads` are consistent across code, scripts, and container metadata
|
||||
- env vars are documented and validated
|
||||
2. review deployment artifacts for drift
|
||||
- `dockerfile`, `run-youdis.sh`, and `unraid-ca-template.xml` reflect current behavior
|
||||
- remove stale references and dead assumptions
|
||||
3. make fresh deployment understandable
|
||||
- a new deploy on unraid is possible without reconstructing tribal knowledge from old files
|
||||
|
||||
- pm note: this is packaging polish after core correctness, not before
|
||||
|
||||
** evidence
|
||||
- commit:
|
||||
- tests:
|
||||
- datetime:
|
||||
|
||||
** notes
|
||||
- keep container surface area small
|
||||
- optimize for “future me can redeploy this without cursing past me too hard”
|
||||
21
run-youdis.sh
Normal file
21
run-youdis.sh
Normal file
@@ -0,0 +1,21 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
#start crond in bg
|
||||
crond -l 2
|
||||
|
||||
echo "checking for /config/yt-dlp.conf"
|
||||
#copy yt-dlp.conf if missing
|
||||
mkdir -p /config
|
||||
if [ ! -f /config/yt-dlp.conf ]; then
|
||||
echo "yt-dlp.conf not found, setting default"
|
||||
cp /app/default-yt-dlp.conf /config/yt-dlp.conf
|
||||
echo "created yt-dlp.conf"
|
||||
fi
|
||||
|
||||
python3 -m pip install --no-cache-dir --upgrade --pre "yt-dlp[default]"
|
||||
VERSION=$(python3 -m pip show yt-dlp 2>/dev/null | awk '/Version:/ {print $2}')
|
||||
echo "updated yt-dlp to $VERSION"
|
||||
|
||||
echo "starting youdis"
|
||||
exec python3 /app/youdis.py
|
||||
@@ -1,18 +1,18 @@
|
||||
<?xml version="1.0"?>
|
||||
<Container version="2">
|
||||
<Name>youdis</Name>
|
||||
<Repository>eulaly/youdis</Repository>
|
||||
<Registry>https://hub.docker.com/r/eulaly/youdis/</Registry>
|
||||
<Network>bridge</Network>
|
||||
<Shell>sh</Shell>
|
||||
<Privileged>false</Privileged>
|
||||
<Support>[Unraid Support Thread]</Support>
|
||||
<Project>https://github.com/eulaly/youdis</Project>
|
||||
<Overview>Discord bot-based wrapper for yt-dlp. Let your friends download videos to your server! Supports playlists, requires a configured Discord bot.</Overview>
|
||||
<Category>Downloaders: Tools:</Category>
|
||||
<TemplateURL>https://raw.githubusercontent.com/eulaly/unraid-templates/refs/heads/master/unraid-ca-template.xml</TemplateURL>
|
||||
<Icon>https://github.com/eulaly/youdis/blob/c978a2326984efa9670678687ed1a1473478d753/yt_dlp.png</Icon>
|
||||
<Config Name="api_token" Target="api_token" Default="" Mode="" Description="Discord bot token" Type="Variable" Display="always" Required="true" Mask="true"/>
|
||||
<Config Name="Downloads" Target="/downloads" Default="" Mode="rw" Description="Video download location" Type="Path" Display="always" Required="false"/>
|
||||
<Config Name="Config" Target="/config" Default="/mnt/user/appdata/youdis/config" Mode="rw" Description="Config location (archive.txt, users.json)" Type="Path" Display="always" Required="false"/>
|
||||
</Container>
|
||||
<?xml version="1.0"?>
|
||||
<Container version="2">
|
||||
<Name>youdis</Name>
|
||||
<Repository>eulaly/youdis</Repository>
|
||||
<Registry>https://hub.docker.com/r/eulaly/youdis/</Registry>
|
||||
<Network>bridge</Network>
|
||||
<Shell>sh</Shell>
|
||||
<Privileged>false</Privileged>
|
||||
<Support>[Unraid Support Thread]</Support>
|
||||
<Project>https://github.com/eulaly/youdis</Project>
|
||||
<Overview>Discord bot-based wrapper for yt-dlp. Let your friends download videos to your server! Supports playlists, requires a configured Discord bot.</Overview>
|
||||
<Category>Downloaders: Tools:</Category>
|
||||
<TemplateURL>https://raw.githubusercontent.com/eulaly/unraid-templates/refs/heads/master/unraid-ca-template.xml</TemplateURL>
|
||||
<Icon>https://github.com/eulaly/youdis/blob/c978a2326984efa9670678687ed1a1473478d753/yt_dlp.png</Icon>
|
||||
<Config Name="api_token" Target="api_token" Default="" Mode="" Description="Discord bot token" Type="Variable" Display="always" Required="true" Mask="true"/>
|
||||
<Config Name="Downloads" Target="/downloads" Default="" Mode="rw" Description="Video download location" Type="Path" Display="always" Required="false"/>
|
||||
<Config Name="Config" Target="/config" Default="/mnt/user/appdata/youdis/config" Mode="rw" Description="Config location (archive.txt, users.json)" Type="Path" Display="always" Required="false"/>
|
||||
</Container>
|
||||
|
||||
12
update-ytdlp.sh
Normal file
12
update-ytdlp.sh
Normal file
@@ -0,0 +1,12 @@
|
||||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
echo "updating yt-dlp"
|
||||
echo "killing youdis"
|
||||
pkill -f youdis.py || true
|
||||
python3 -m pip install --no-cache-dir --upgrade --pre "yt-dlp[default]"
|
||||
VERSION=$(python3 -m pip show yt-dlp 2>/dev/null | awk '/Version:/ {print $2}')
|
||||
|
||||
echo "updated yt-dlp to $VERSION"
|
||||
echo "restarting youdis"
|
||||
python3 /app/youdis.py &
|
||||
@@ -1 +0,0 @@
|
||||
20250823-b37e943
|
||||
1
weekly-restart
Normal file
1
weekly-restart
Normal file
@@ -0,0 +1 @@
|
||||
0 3 * * 0 root /app/update-ytdlp.sh
|
||||
1
youdis-version.txt
Normal file
1
youdis-version.txt
Normal file
@@ -0,0 +1 @@
|
||||
20250829-ec72c56
|
||||
296
youdis.py
296
youdis.py
@@ -1,72 +1,149 @@
|
||||
#!/usr/bin/env python3
|
||||
'''
|
||||
youdis v1.1
|
||||
bot for downloading youtube videos using yt-dlp
|
||||
discord-py-interactions 5.11.0 has new option
|
||||
requires python>=3.9
|
||||
'''
|
||||
# match_filter: info_dict -> Raise utils.DownloadCancelled(msg) ? interrupt
|
||||
|
||||
import interactions
|
||||
from os import getenv
|
||||
from pathlib import Path
|
||||
#!/usr/bin/env python3
|
||||
'''
|
||||
youdis v1.1
|
||||
bot for downloading youtube videos using yt-dlp
|
||||
discord-py-interactions 5.11.0 has new option
|
||||
requires python>=3.9
|
||||
'''
|
||||
# match_filter: info_dict -> Raise utils.DownloadCancelled(msg) ? interrupt
|
||||
|
||||
import interactions
|
||||
from os import getenv
|
||||
from pathlib import Path
|
||||
import yt_dlp
|
||||
import json
|
||||
import asyncio
|
||||
import threading
|
||||
|
||||
userFile = Path('/config/users.json')
|
||||
userFile.touch(exist_ok=True)
|
||||
userFile.parent.mkdir(exist_ok=True, parents=True)
|
||||
|
||||
bot = interactions.Client(intents=interactions.Intents.DEFAULT,default_scope=2147491904)
|
||||
|
||||
userFile.parent.mkdir(exist_ok=True, parents=True)
|
||||
try:
|
||||
with open(userFile, 'x') as f:
|
||||
print(f'users.json not found; saving to {userFile}')
|
||||
except FileExistsError:
|
||||
with open(userFile, 'r') as f:
|
||||
authorized_users = json.load(f).get('authorized_users')
|
||||
def save_authorized_users(authorized_users):
|
||||
with open(userFile, 'w') as f:
|
||||
json.dump({'authorized_users': authorized_users}, f)
|
||||
|
||||
def load_authorized_users():
|
||||
if not userFile.exists():
|
||||
save_authorized_users([])
|
||||
print(f'users.json not found; saving to {userFile}')
|
||||
return []
|
||||
|
||||
try:
|
||||
with open(userFile, 'r') as f:
|
||||
data = json.load(f)
|
||||
except (json.JSONDecodeError, OSError):
|
||||
save_authorized_users([])
|
||||
print(f'users.json invalid; resetting {userFile}')
|
||||
return []
|
||||
|
||||
authorized_users = data.get('authorized_users', [])
|
||||
if not isinstance(authorized_users, list):
|
||||
authorized_users = []
|
||||
|
||||
authorized_users = [str(user_id) for user_id in authorized_users]
|
||||
save_authorized_users(authorized_users)
|
||||
print(f'authorized_users:{authorized_users}')
|
||||
|
||||
title = ''
|
||||
return authorized_users
|
||||
|
||||
authorized_users = load_authorized_users()
|
||||
|
||||
active_job_lock = threading.Lock()
|
||||
active_job = None
|
||||
|
||||
async def send_message(ctx, message):
|
||||
await ctx.author.send(message)
|
||||
|
||||
def claim_active_job(job):
|
||||
global active_job
|
||||
with active_job_lock:
|
||||
if active_job is not None:
|
||||
return active_job
|
||||
active_job = job
|
||||
return None
|
||||
|
||||
def get_active_job():
|
||||
with active_job_lock:
|
||||
return active_job
|
||||
|
||||
def clear_active_job(job):
|
||||
global active_job
|
||||
with active_job_lock:
|
||||
if active_job is job:
|
||||
active_job = None
|
||||
|
||||
def download_video(url, options):
|
||||
with yt_dlp.YoutubeDL(options) as ydl:
|
||||
ydl.download(url)
|
||||
|
||||
def create_hook(ctx,loop):
|
||||
def hook(d):
|
||||
global title
|
||||
status = d.get('status')
|
||||
if status == 'error':
|
||||
msg = f'error; video probably already exists, have you checked archive.txt'
|
||||
asyncio.run_coroutine_threadsafe(send_message(ctx,msg),loop)
|
||||
elif d.get('info_dict').get('title') != title:
|
||||
title = d.get('info_dict').get('title')
|
||||
playlist_index = d.get('info_dict').get('playlist_index')
|
||||
playlist_count = d.get('info_dict').get('playlist_count')
|
||||
filename = d.get('filename')
|
||||
url = d.get('info_dict').get('webpage_url')
|
||||
msg = f'{status} {playlist_index} of {playlist_count}: {filename} <{url}>'
|
||||
asyncio.run_coroutine_threadsafe(send_message(ctx,msg),loop)
|
||||
return hook
|
||||
|
||||
@interactions.slash_command(name="youtube",description="download video from youtube to server")
|
||||
@interactions.slash_option(
|
||||
name='url',
|
||||
opt_type=interactions.OptionType.STRING,
|
||||
required=True,
|
||||
description='url target'
|
||||
)
|
||||
def create_hook(ctx, loop, cancel_event):
|
||||
seen_updates = set()
|
||||
|
||||
def hook(d):
|
||||
if cancel_event.is_set():
|
||||
raise yt_dlp.utils.DownloadCancelled('download canceled by /interrupt')
|
||||
|
||||
status = d.get('status')
|
||||
info = d.get('info_dict') or {}
|
||||
|
||||
if status not in {'downloading', 'finished'}:
|
||||
return
|
||||
|
||||
filename = d.get('filename') or info.get('_filename') or info.get('title')
|
||||
update_key = (status, filename)
|
||||
if update_key in seen_updates:
|
||||
return
|
||||
|
||||
seen_updates.add(update_key)
|
||||
playlist_index = info.get('playlist_index')
|
||||
playlist_count = info.get('playlist_count')
|
||||
url = info.get('webpage_url')
|
||||
|
||||
prefix = status
|
||||
if playlist_index and playlist_count:
|
||||
prefix = f'{status} {playlist_index} of {playlist_count}'
|
||||
|
||||
msg = f'{prefix}: {filename}'
|
||||
if url:
|
||||
msg = f'{msg} <{url}>'
|
||||
|
||||
asyncio.run_coroutine_threadsafe(send_message(ctx, msg), loop)
|
||||
|
||||
return hook
|
||||
|
||||
@interactions.slash_command(name="youtube",description="download video from youtube to server")
|
||||
@interactions.slash_option(
|
||||
name='url',
|
||||
opt_type=interactions.OptionType.STRING,
|
||||
required=True,
|
||||
description='url target'
|
||||
)
|
||||
async def youtube(ctx: interactions.SlashContext, url:str):
|
||||
print(f'{ctx.author.id} requested {url}')
|
||||
# check that user is authorized
|
||||
if str(ctx.author.id) not in authorized_users:
|
||||
if ctx.author.id == 127831327012683776:
|
||||
await ctx.author.send('potato stop')
|
||||
await ctx.author.send('you are not authorized to use this command. message my owner to be added.')
|
||||
return
|
||||
|
||||
loop = asyncio.get_running_loop()
|
||||
hook = create_hook(ctx,loop)
|
||||
msg = ''
|
||||
cancel_event = threading.Event()
|
||||
hook = create_hook(ctx, loop, cancel_event)
|
||||
job = {
|
||||
'requester_id': str(ctx.author.id),
|
||||
'request_url': url,
|
||||
'cancel_event': cancel_event,
|
||||
}
|
||||
existing_job = claim_active_job(job)
|
||||
if existing_job:
|
||||
await ctx.author.send(
|
||||
f'already downloading for <@{existing_job["requester_id"]}>. '
|
||||
'single-job mode is enabled right now; try again after it finishes.'
|
||||
)
|
||||
return
|
||||
|
||||
# use api_to_cli and paste cli options to get the output you need
|
||||
yoptions = {
|
||||
'format':'bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]/best',
|
||||
@@ -82,76 +159,77 @@ async def youtube(ctx: interactions.SlashContext, url:str):
|
||||
'outtmpl': '%(uploader)s/%(playlist_title)s/%(playlist_index)s%(playlist_index& - )s%(title)s.%(ext)s',
|
||||
'outtmpl_na_placeholder':'',
|
||||
}
|
||||
# check that user is authorized
|
||||
if ctx.author.id not in authorized_users:
|
||||
if ctx.author.id == 127831327012683776:
|
||||
await ctx.author.send('potato stop')
|
||||
await ctx.author.send('you are not authorized to use this command. message my owner to be added.')
|
||||
return
|
||||
await ctx.channel.send(f'Downloading from <{url}>. Status updates via DM. Single-job mode is enabled.')
|
||||
|
||||
try:
|
||||
await asyncio.to_thread(download_video, url, yoptions)
|
||||
except yt_dlp.utils.DownloadCancelled as exc:
|
||||
print(f'download canceled: {exc}')
|
||||
await ctx.author.send(f'download canceled: {exc}')
|
||||
except yt_dlp.utils.DownloadError as exc:
|
||||
print(f'download failed: {exc}')
|
||||
await ctx.author.send(f'download failed: {exc}')
|
||||
except Exception as exc:
|
||||
print(f'unexpected download failure: {exc}')
|
||||
await ctx.author.send(f'unexpected download failure: {exc}')
|
||||
else:
|
||||
await ctx.channel.send(f'Downloading from <{url}>. Status updates via DM.')
|
||||
#await ctx.defer() #if you need up to 15m to respond
|
||||
|
||||
# 1/2 - download in separate thread, else progress_hook blocks downstream async ctx.send
|
||||
download_thread = threading.Thread(target=download_video, args=(url,yoptions))
|
||||
download_thread.start()
|
||||
await asyncio.to_thread(download_thread.join)
|
||||
|
||||
# 2/2 - replace the above with this next try:
|
||||
#try:
|
||||
# await asyncio.to_thread(download_video, url, yoptions)
|
||||
#except Exception as e:
|
||||
# print(f"download failed: {e}")
|
||||
# await ctx.author.send(f"download failed: {str(e)}")
|
||||
await ctx.author.send(f'download complete for <{url}>')
|
||||
finally:
|
||||
clear_active_job(job)
|
||||
|
||||
|
||||
@interactions.slash_command(name="interrupt",description="cancel current job")
|
||||
@interactions.check(interactions.is_owner())
|
||||
async def _interrupt(ctx):
|
||||
# interrupt here
|
||||
print('interrupting current job - not implemented')
|
||||
await ctx.author.send('interrupting current job - not implemented')
|
||||
|
||||
@interactions.slash_command(name="adduser",description="authorize target user")
|
||||
@interactions.slash_option(
|
||||
name="user",
|
||||
opt_type=interactions.OptionType.USER,
|
||||
required=True,
|
||||
description='enable this bot for target user',
|
||||
)
|
||||
@interactions.check(interactions.is_owner())
|
||||
job = get_active_job()
|
||||
if not job:
|
||||
await ctx.author.send('no active download to interrupt')
|
||||
return
|
||||
|
||||
job['cancel_event'].set()
|
||||
print(f'interrupt requested for {job["request_url"]}')
|
||||
await ctx.author.send(
|
||||
f'interrupt requested for <{job["request_url"]}>; '
|
||||
'cancellation is coarse and will stop on the next yt-dlp progress update'
|
||||
)
|
||||
|
||||
@interactions.slash_command(name="adduser",description="authorize target user")
|
||||
@interactions.slash_option(
|
||||
name="user",
|
||||
opt_type=interactions.OptionType.USER,
|
||||
required=True,
|
||||
description='enable this bot for target user',
|
||||
)
|
||||
@interactions.check(interactions.is_owner())
|
||||
async def _adduser(ctx: interactions.SlashContext, user:interactions.OptionType.USER):
|
||||
if str(user.id) not in authorized_users:
|
||||
authorized_users.append(str(user.id))
|
||||
with open(userFile,'w') as f: #overwrite file - fix later if other params come up
|
||||
json.dump({'authorized_users':authorized_users})
|
||||
print('react:checkmark')
|
||||
await ctx.message.add_reaction('✅')
|
||||
|
||||
@interactions.slash_command(name="removeuser",description="deauthorize target user")
|
||||
@interactions.slash_option(
|
||||
name="user",
|
||||
opt_type=interactions.OptionType.USER,
|
||||
required=True,
|
||||
description='disable this bot for target user',
|
||||
)
|
||||
@interactions.check(interactions.is_owner())
|
||||
user_id = str(user.id)
|
||||
if user_id not in authorized_users:
|
||||
authorized_users.append(user_id)
|
||||
save_authorized_users(authorized_users)
|
||||
print(f'authorized {user_id}')
|
||||
await ctx.author.send(f'authorized {user.mention}')
|
||||
else:
|
||||
await ctx.author.send(f'{user.mention} is already authorized')
|
||||
|
||||
@interactions.slash_command(name="removeuser",description="deauthorize target user")
|
||||
@interactions.slash_option(
|
||||
name="user",
|
||||
opt_type=interactions.OptionType.USER,
|
||||
required=True,
|
||||
description='disable this bot for target user',
|
||||
)
|
||||
@interactions.check(interactions.is_owner())
|
||||
async def _removeuser(ctx: interactions.SlashContext, user:interactions.OptionType.USER):
|
||||
if str(user.id) in authorized_users:
|
||||
# ? ? ? fix pls
|
||||
i = index(authorized_users(str(user.id)))
|
||||
|
||||
# update list, rewrite json
|
||||
|
||||
print('react:checkmark')
|
||||
await ctx.message.add_reaction('✅')
|
||||
|
||||
async def dl_hook(d):
|
||||
msg = f'{d["status"]} {d["filename"]}'
|
||||
print(msg)
|
||||
await ctx.author.send(msg)
|
||||
user_id = str(user.id)
|
||||
if user_id in authorized_users:
|
||||
authorized_users.remove(user_id)
|
||||
save_authorized_users(authorized_users)
|
||||
print(f'deauthorized {user_id}')
|
||||
await ctx.author.send(f'deauthorized {user.mention}')
|
||||
else:
|
||||
await ctx.author.send(f'{user.mention} is not currently authorized')
|
||||
|
||||
api_token = getenv('api_token')
|
||||
if not api_token:
|
||||
raise ValueError('API token not set. Retrieve from your Discord bot.')
|
||||
bot.start(api_token)
|
||||
bot.start(api_token)
|
||||
|
||||
Reference in New Issue
Block a user