Compare commits
86 Commits
f30686fd7c
..
master
| Author | SHA1 | Date | |
|---|---|---|---|
| fb0746e29e | |||
| b987f4775f | |||
|
8ff5caaede
|
|||
| 163a2af84b | |||
|
88ced43981
|
|||
| f3cd0d0a89 | |||
|
9ae57862a0
|
|||
| 25eafe3959 | |||
| a250bb7c9b | |||
|
8768ea181c
|
|||
|
7e0fd89e11
|
|||
| 445e10fa16 | |||
|
0b621acdfb
|
|||
| 5465bd4c77 | |||
| bdfd612fa0 | |||
| de6e50179a | |||
|
38691be66b
|
|||
|
46bbecb280
|
|||
| 772993a596 | |||
|
f809b08c37
|
|||
| 4f3b30885e | |||
| 6c0316ac28 | |||
|
52cc00190b
|
|||
|
a7765f90d9
|
|||
| a0e511b4aa | |||
| 7b4d25d484 | |||
|
b392048ca1
|
|||
| b0cb606afe | |||
|
f303eb3eb8
|
|||
| e641e1d2a5 | |||
|
a6dc4e27b9
|
|||
| 509dab5395 | |||
|
6b9934a221
|
|||
| adefe2f177 | |||
|
084b7ed979
|
|||
| 51e1cc5e85 | |||
|
d3e6ddebcd
|
|||
|
558f95ad9d
|
|||
| e0de621e41 | |||
|
451333860f
|
|||
|
e3b5542b78
|
|||
|
aaf3338797
|
|||
|
8f2bda0b52
|
|||
|
91f2eb39cb
|
|||
| 82b867ae9c | |||
| ebb6c11d49 | |||
|
d4beb62fdd
|
|||
|
13d65ef6ce
|
|||
|
8b1cead3ea
|
|||
|
4347bf733c
|
|||
|
5748834af4
|
|||
|
06d2a5ef01
|
|||
|
bdcd77eff1
|
|||
|
4541559f47
|
|||
|
906ef98bd5
|
|||
|
640c952b20
|
|||
|
2c99fbf517
|
|||
| 81968a6811 | |||
|
7d83fd8518
|
|||
| 7b34919e72 | |||
|
98fec74ac0
|
|||
| 2269104805 | |||
| 4bea5e020f | |||
| 60803961b3 | |||
|
197e35314a
|
|||
|
db0c0a3893
|
|||
|
46fec9b85a
|
|||
|
204404b761
|
|||
| 6e7fc73420 | |||
|
67c85aebf9
|
|||
| b9088d932c | |||
|
8c1d044f79
|
|||
| f688ee035f | |||
|
7fd5d93b6d
|
|||
|
d7ad90a1d5
|
|||
| ac5abffd74 | |||
|
1c43c62523
|
|||
| bef0a4d593 | |||
|
bf7739228f
|
|||
| 270934613f | |||
|
5cea64626c
|
|||
| 70d72759ce | |||
|
c537874adb
|
|||
|
b496d14cf7
|
|||
|
c2de1abfd2
|
|||
|
635d5d5113
|
@@ -23,14 +23,14 @@ jobs:
|
|||||||
|
|
||||||
# Set up Docker Buildx for building the image
|
# Set up Docker Buildx for building the image
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
driver: remote
|
driver: remote
|
||||||
endpoint: 'tcp://buildkitd:1234'
|
endpoint: 'tcp://buildkitd.gitea-runner.svc.cluster.local:1234'
|
||||||
|
|
||||||
# Log in to the Gitea container registry
|
# Log in to the Gitea container registry
|
||||||
- name: Log in to Gitea Container Registry
|
- name: Log in to Gitea Container Registry
|
||||||
uses: docker/login-action@v3
|
uses: docker/login-action@v4
|
||||||
with:
|
with:
|
||||||
registry: git.dubyatp.xyz
|
registry: git.dubyatp.xyz
|
||||||
username: williamp
|
username: williamp
|
||||||
@@ -38,7 +38,7 @@ jobs:
|
|||||||
|
|
||||||
# Build and push the Docker image
|
# Build and push the Docker image
|
||||||
- name: Build and Push Docker Image
|
- name: Build and Push Docker Image
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v7
|
||||||
with:
|
with:
|
||||||
context: . # Build context (current directory)
|
context: . # Build context (current directory)
|
||||||
file: ./Dockerfile # Path to Dockerfile
|
file: ./Dockerfile # Path to Dockerfile
|
||||||
@@ -75,10 +75,15 @@ jobs:
|
|||||||
git config --local user.signingkey ~/.ssh/id_ed25519
|
git config --local user.signingkey ~/.ssh/id_ed25519
|
||||||
git config --local gpg.format ssh
|
git config --local gpg.format ssh
|
||||||
git config --local commit.gpgsign true
|
git config --local commit.gpgsign true
|
||||||
git commit -a -m "yt-dlp-bot: deploy update to ${{ needs.build-and-push.outputs.sha_short }}"
|
|
||||||
|
if [ -n "$(git status --porcelain)" ]; then
|
||||||
|
git commit -a -m "yt-dlp-bot: deploy update to ${{ needs.build-and-push.outputs.sha_short }}"
|
||||||
|
else
|
||||||
|
echo "No changes to commit, skipping..."
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
- name: Push changes
|
- name: Push changes
|
||||||
uses: ad-m/github-push-action@v1.0.0
|
uses: ad-m/github-push-action@v1.1.0
|
||||||
with:
|
with:
|
||||||
github_token: ${{ secrets.ACTIONS_TOKEN }}
|
github_token: ${{ secrets.ACTIONS_TOKEN }}
|
||||||
repository: infrastructure/core-apps
|
repository: infrastructure/core-apps
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
name: Build only (for PRs)
|
name: Build only (for PRs)
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
pull_request:
|
||||||
branches:
|
|
||||||
- v1-refactor # after this has been merged
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-only:
|
build-only:
|
||||||
@@ -23,14 +21,14 @@ jobs:
|
|||||||
|
|
||||||
# Set up Docker Buildx for building the image
|
# Set up Docker Buildx for building the image
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@v4
|
||||||
with:
|
with:
|
||||||
driver: remote
|
driver: remote
|
||||||
endpoint: 'tcp://buildkitd:1234'
|
endpoint: 'tcp://buildkitd.gitea-runner.svc.cluster.local:1234'
|
||||||
|
|
||||||
# Build the Docker image
|
# Build the Docker image
|
||||||
- name: Build Docker Image
|
- name: Build Docker Image
|
||||||
uses: docker/build-push-action@v6
|
uses: docker/build-push-action@v7
|
||||||
with:
|
with:
|
||||||
context: . # Build context (current directory)
|
context: . # Build context (current directory)
|
||||||
file: ./Dockerfile # Path to Dockerfile
|
file: ./Dockerfile # Path to Dockerfile
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
name: Build and Push Docker Image
|
|
||||||
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- v1-refactor # Trigger on push to the main branch; adjust as needed
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build-and-push:
|
|
||||||
runs-on: ubuntu-latest # Use a runner with Docker support
|
|
||||||
container: ghcr.io/catthehacker/ubuntu:act-latest # Image with Docker pre-installed
|
|
||||||
outputs:
|
|
||||||
sha_short: ${{ steps.vars.outputs.sha_short }}
|
|
||||||
steps:
|
|
||||||
# Checkout the repository code
|
|
||||||
- name: Checkout repository
|
|
||||||
uses: actions/checkout@v6
|
|
||||||
|
|
||||||
- name: Set outputs
|
|
||||||
id: vars
|
|
||||||
run: |
|
|
||||||
echo "sha_short=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
# Set up Docker Buildx for building the image
|
|
||||||
- name: Set up Docker Buildx
|
|
||||||
uses: docker/setup-buildx-action@v3
|
|
||||||
with:
|
|
||||||
driver: remote
|
|
||||||
endpoint: 'tcp://buildkitd:1234'
|
|
||||||
|
|
||||||
# Log in to the Gitea container registry
|
|
||||||
- name: Log in to Gitea Container Registry
|
|
||||||
uses: docker/login-action@v3
|
|
||||||
with:
|
|
||||||
registry: git.dubyatp.xyz
|
|
||||||
username: williamp
|
|
||||||
password: ${{ secrets.ACTIONS_TOKEN }} # Personal Access Token for authentication
|
|
||||||
|
|
||||||
# Build and push the Docker image
|
|
||||||
- name: Build and Push Docker Image
|
|
||||||
uses: docker/build-push-action@v6
|
|
||||||
with:
|
|
||||||
context: . # Build context (current directory)
|
|
||||||
file: ./Dockerfile # Path to Dockerfile
|
|
||||||
platforms: "linux/amd64,linux/arm64"
|
|
||||||
push: true # Push to registry after building
|
|
||||||
tags: |
|
|
||||||
git.dubyatp.xyz/williamp/yt-dlp-bot:refactor-test-${{steps.vars.outputs.sha_short }}
|
|
||||||
# Tags the image with 'latest' and the commit SHA
|
|
||||||
+29
-17
@@ -3,46 +3,58 @@
|
|||||||
|
|
||||||
########################################
|
########################################
|
||||||
# Versions
|
# Versions
|
||||||
ARG YT_DLP_VERSION="2026.03.03"
|
ARG YT_DLP_VERSION="2026.03.17"
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# Deno builder stage
|
# Deno builder stage
|
||||||
FROM denoland/deno:bin-2.6.6@sha256:9f18d20207f2699595ea26d14e0b7e123cd0cd01100a577bc11f8ca5906c2d81 AS deno-builder
|
FROM denoland/deno:bin-2.6.6@sha256:9f18d20207f2699595ea26d14e0b7e123cd0cd01100a577bc11f8ca5906c2d81 AS deno-builder
|
||||||
|
|
||||||
################################################################################
|
|
||||||
# FFmpeg builder stage
|
|
||||||
FROM debian:13-slim@sha256:1d3c811171a08a5adaa4a163fbafd96b61b87aa871bbc7aa15431ac275d3d430 AS ffmpeg-builder
|
|
||||||
RUN apt-get update && \
|
|
||||||
apt-get install -y --no-install-recommends ffmpeg
|
|
||||||
RUN mkdir -p /rootfs/bin && \
|
|
||||||
cp /usr/bin/ffmpeg /usr/bin/ffprobe /rootfs/bin/ && \
|
|
||||||
ldd /usr/bin/ffmpeg | awk '{print $3}' | grep "^/" | xargs -I '{}' cp --parents '{}' /rootfs && \
|
|
||||||
ldd /usr/bin/ffmpeg | awk 'NF==2 {print $1}' | grep "^/" | xargs -I '{}' cp --parents '{}' /rootfs
|
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# YT-DLP builder stage
|
# YT-DLP builder stage
|
||||||
FROM alpine:3.23@sha256:25109184c71bdad752c8312a8623239686a9a2071e8825f20acb8f2198c3f659 AS yt-dlp-builder
|
FROM alpine:3.23@sha256:25109184c71bdad752c8312a8623239686a9a2071e8825f20acb8f2198c3f659 AS yt-dlp-builder
|
||||||
ARG YT_DLP_VERSION
|
ARG YT_DLP_VERSION
|
||||||
|
ARG TARGETARCH
|
||||||
|
|
||||||
RUN mkdir -p /rootfs/target /rootfs/tmp /rootfs/bin
|
RUN mkdir -p /rootfs/target /rootfs/tmp /rootfs/bin
|
||||||
|
|
||||||
ADD "https://github.com/yt-dlp/yt-dlp/releases/download/${YT_DLP_VERSION}/yt-dlp_linux" /yt-dlp_linux
|
|
||||||
ADD "https://github.com/yt-dlp/yt-dlp/releases/download/${YT_DLP_VERSION}/SHA2-256SUMS" /SHA2-256SUMS
|
ADD "https://github.com/yt-dlp/yt-dlp/releases/download/${YT_DLP_VERSION}/SHA2-256SUMS" /SHA2-256SUMS
|
||||||
ADD "https://github.com/yt-dlp/yt-dlp/releases/download/${YT_DLP_VERSION}/SHA2-256SUMS.sig" /SHA2-256SUMS.sig
|
ADD "https://github.com/yt-dlp/yt-dlp/releases/download/${YT_DLP_VERSION}/SHA2-256SUMS.sig" /SHA2-256SUMS.sig
|
||||||
ADD "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xAC0CBBE6848D6A873464AF4E57CF65933B5A7581" "/yt-dlp_pubkey.asc"
|
ADD "https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xAC0CBBE6848D6A873464AF4E57CF65933B5A7581" "/yt-dlp_pubkey.asc"
|
||||||
|
|
||||||
RUN apk add --no-cache gnupg && \
|
RUN apk add --no-cache gnupg && \
|
||||||
gpg --import /yt-dlp_pubkey.asc && \
|
gpg --import /yt-dlp_pubkey.asc && \
|
||||||
gpg --verify /SHA2-256SUMS.sig /SHA2-256SUMS && \
|
gpg --verify /SHA2-256SUMS.sig /SHA2-256SUMS
|
||||||
grep " yt-dlp_linux$" /SHA2-256SUMS | sha256sum -c -
|
|
||||||
|
|
||||||
RUN mv /yt-dlp_linux /rootfs/bin/yt-dlp && \
|
RUN case "$TARGETARCH" in \
|
||||||
|
amd64) YT_DLP_FILE="yt-dlp_linux" ;; \
|
||||||
|
arm64) YT_DLP_FILE="yt-dlp_linux_aarch64" ;; \
|
||||||
|
*) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; \
|
||||||
|
esac && \
|
||||||
|
wget -qO "/${YT_DLP_FILE}" "https://github.com/yt-dlp/yt-dlp/releases/download/${YT_DLP_VERSION}/${YT_DLP_FILE}" && \
|
||||||
|
grep " ${YT_DLP_FILE}$" /SHA2-256SUMS | sha256sum -c - && \
|
||||||
|
mv "/${YT_DLP_FILE}" /rootfs/bin/yt-dlp && \
|
||||||
chmod 755 /rootfs/bin/yt-dlp && \
|
chmod 755 /rootfs/bin/yt-dlp && \
|
||||||
chmod 1777 /rootfs/tmp
|
chmod 1777 /rootfs/tmp
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# FFmpeg builder stage
|
||||||
|
FROM debian:13-slim@sha256:4ffb3a1511099754cddc70eb1b12e50ffdb67619aa0ab6c13fcd800a78ef7c7a AS ffmpeg-builder
|
||||||
|
RUN apt-get update && \
|
||||||
|
apt-get install -y --no-install-recommends ffmpeg
|
||||||
|
COPY --from=yt-dlp-builder /rootfs/bin/yt-dlp /yt-dlp
|
||||||
|
RUN mkdir -p /rootfs/bin && \
|
||||||
|
cp /usr/bin/ffmpeg /usr/bin/ffprobe /rootfs/bin/ && \
|
||||||
|
{ ldd /usr/bin/ffmpeg; ldd /yt-dlp; } 2>/dev/null | \
|
||||||
|
grep -o '/[^ ]*' | sort -u | \
|
||||||
|
xargs -I '{}' cp --parents '{}' /rootfs && \
|
||||||
|
LIBDIR=$(dirname "$(find /rootfs -name 'libc.so.6' | head -1)") && \
|
||||||
|
for stub in libutil.so.1 libdl.so.2 libpthread.so.0 librt.so.1; do \
|
||||||
|
[ -f "${LIBDIR}/${stub}" ] || ln -sf libc.so.6 "${LIBDIR}/${stub}"; \
|
||||||
|
done
|
||||||
|
|
||||||
################################################################################
|
################################################################################
|
||||||
# App builder stage
|
# App builder stage
|
||||||
FROM golang:1.25.8-trixie@sha256:bc16125656839ffe56154c675f7a9662bec2ef7d4060177239914e7c6d2fd8a8 AS app-builder
|
FROM golang:1.26.2-trixie@sha256:da3943074756e8d6f109ce7a84be16e98bffa39e9d369a0447f016b56db84e8f AS app-builder
|
||||||
|
|
||||||
COPY app/ /opt/app
|
COPY app/ /opt/app
|
||||||
WORKDIR /opt/app
|
WORKDIR /opt/app
|
||||||
@@ -76,4 +88,4 @@ LABEL org.opencontainers.image.title="yt-dlp bot" \
|
|||||||
org.opencontainers.image.authors="William Peebles <me@williamtpeebles.com>" \
|
org.opencontainers.image.authors="William Peebles <me@williamtpeebles.com>" \
|
||||||
org.opencontainers.image.vendor="William Peebles" \
|
org.opencontainers.image.vendor="William Peebles" \
|
||||||
org.opencontainers.image.licenses="MIT" \
|
org.opencontainers.image.licenses="MIT" \
|
||||||
org.opencontainers.image.source="https://git.dubyatp.xyz/williamp/yt-dlp-bot"
|
org.opencontainers.image.source="https://git.dubyatp.xyz/williamp/yt-dlp-bot"
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 23 KiB |
+5
-9
@@ -2,20 +2,16 @@ module git.dubyatp.xyz/williamp/yt-dlp-bot
|
|||||||
|
|
||||||
go 1.25.2
|
go 1.25.2
|
||||||
|
|
||||||
//replace github.com/lrstanley/go-ytdlp => /home/williamp/go-ytdlp
|
|
||||||
|
|
||||||
replace github.com/lrstanley/go-ytdlp => github.com/dubyatp/go-ytdlp v0.0.0-20260213041320-010f95f0f1d3
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/bwmarrin/discordgo v0.29.0
|
github.com/bwmarrin/discordgo v0.29.0
|
||||||
github.com/lrstanley/go-ytdlp v1.2.7
|
github.com/lrstanley/go-ytdlp v1.3.5
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/ProtonMail/go-crypto v1.3.0 // indirect
|
github.com/ProtonMail/go-crypto v1.3.0 // indirect
|
||||||
github.com/cloudflare/circl v1.6.1 // indirect
|
github.com/cloudflare/circl v1.6.3 // indirect
|
||||||
github.com/gorilla/websocket v1.4.2 // indirect
|
github.com/gorilla/websocket v1.4.2 // indirect
|
||||||
github.com/ulikunitz/xz v0.5.13 // indirect
|
github.com/ulikunitz/xz v0.5.15 // indirect
|
||||||
golang.org/x/crypto v0.41.0 // indirect
|
golang.org/x/crypto v0.48.0 // indirect
|
||||||
golang.org/x/sys v0.35.0 // indirect
|
golang.org/x/sys v0.41.0 // indirect
|
||||||
)
|
)
|
||||||
|
|||||||
+16
@@ -4,25 +4,41 @@ github.com/bwmarrin/discordgo v0.29.0 h1:FmWeXFaKUwrcL3Cx65c20bTRW+vOb6k8AnaP+Eg
|
|||||||
github.com/bwmarrin/discordgo v0.29.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
github.com/bwmarrin/discordgo v0.29.0/go.mod h1:NJZpH+1AfhIcyQsPeuBKsUtYrRnjkyu0kIVMCHkZtRY=
|
||||||
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
|
github.com/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
|
||||||
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
|
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
|
||||||
|
github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg8=
|
||||||
|
github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dubyatp/go-ytdlp v0.0.0-20260213041320-010f95f0f1d3 h1:tGzvzV6fSzybhIpwU+wjvjOSq8RBNtHENm+G03E+mgo=
|
github.com/dubyatp/go-ytdlp v0.0.0-20260213041320-010f95f0f1d3 h1:tGzvzV6fSzybhIpwU+wjvjOSq8RBNtHENm+G03E+mgo=
|
||||||
github.com/dubyatp/go-ytdlp v0.0.0-20260213041320-010f95f0f1d3/go.mod h1:38IL64XM6gULrWtKTiR0+TTNCVbxesNSbTyaFG2CGTI=
|
github.com/dubyatp/go-ytdlp v0.0.0-20260213041320-010f95f0f1d3/go.mod h1:38IL64XM6gULrWtKTiR0+TTNCVbxesNSbTyaFG2CGTI=
|
||||||
|
github.com/dubyatp/go-ytdlp v0.0.0-20260308044557-db32b29c1590 h1:27d1UwjlfuF/kwHj98B6UP30D1d7mvk/bmnDQ0xKX1s=
|
||||||
|
github.com/dubyatp/go-ytdlp v0.0.0-20260308044557-db32b29c1590/go.mod h1:VgjnTrvkTf+23JuySjyPq1iQ8ijSovBtTPpXH5XrLtI=
|
||||||
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
|
||||||
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
|
||||||
|
github.com/lrstanley/go-ytdlp v1.3.3 h1:Y9kJcdTwskPWDiwONMIl501Dhi+OrTF7HHY6J6+Lbco=
|
||||||
|
github.com/lrstanley/go-ytdlp v1.3.3/go.mod h1:VgjnTrvkTf+23JuySjyPq1iQ8ijSovBtTPpXH5XrLtI=
|
||||||
|
github.com/lrstanley/go-ytdlp v1.3.4 h1:x3ppgdeN3FbguT5ifc6ISrgjYN10+dVUAbprA7/dYrk=
|
||||||
|
github.com/lrstanley/go-ytdlp v1.3.4/go.mod h1:VgjnTrvkTf+23JuySjyPq1iQ8ijSovBtTPpXH5XrLtI=
|
||||||
|
github.com/lrstanley/go-ytdlp v1.3.5 h1:eT+29mK3Lp+XPMQOH25+jVerrrjifYW1o3IkTYJ9SMs=
|
||||||
|
github.com/lrstanley/go-ytdlp v1.3.5/go.mod h1:VgjnTrvkTf+23JuySjyPq1iQ8ijSovBtTPpXH5XrLtI=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/ulikunitz/xz v0.5.13 h1:ar98gWrjf4H1ev05fYP/o29PDZw9DrI3niHtnEqyuXA=
|
github.com/ulikunitz/xz v0.5.13 h1:ar98gWrjf4H1ev05fYP/o29PDZw9DrI3niHtnEqyuXA=
|
||||||
github.com/ulikunitz/xz v0.5.13/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
github.com/ulikunitz/xz v0.5.13/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||||
|
github.com/ulikunitz/xz v0.5.15 h1:9DNdB5s+SgV3bQ2ApL10xRc35ck0DuIX/isZvIk+ubY=
|
||||||
|
github.com/ulikunitz/xz v0.5.15/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
|
||||||
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
|
||||||
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
|
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
|
||||||
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
|
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
|
||||||
|
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
|
||||||
|
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
|
||||||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
||||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
||||||
|
golang.org/x/sys v0.41.0 h1:Ivj+2Cp/ylzLiEU89QhWblYnOE9zerudt9Ftecq2C6k=
|
||||||
|
golang.org/x/sys v0.41.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||||
|
|||||||
+242
-204
@@ -6,8 +6,8 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"sort"
|
"sort"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/bwmarrin/discordgo"
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
@@ -53,6 +53,24 @@ func main() {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "version",
|
||||||
|
Description: "Show application version",
|
||||||
|
DefaultMemberPermissions: &defaultMemberPermissions,
|
||||||
|
Contexts: &[]discordgo.InteractionContextType{interactionPrivateChannel},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "download video",
|
||||||
|
Type: discordgo.MessageApplicationCommand,
|
||||||
|
IntegrationTypes: &[]discordgo.ApplicationIntegrationType{
|
||||||
|
discordgo.ApplicationIntegrationUserInstall,
|
||||||
|
},
|
||||||
|
|
||||||
|
Contexts: &[]discordgo.InteractionContextType{
|
||||||
|
discordgo.InteractionContextBotDM,
|
||||||
|
discordgo.InteractionContextPrivateChannel,
|
||||||
|
},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
var componentHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
|
var componentHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
|
||||||
@@ -124,54 +142,10 @@ func main() {
|
|||||||
setInteractionState(i.Interaction.Token, state)
|
setInteractionState(i.Interaction.Token, state)
|
||||||
|
|
||||||
// Build audio format options
|
// Build audio format options
|
||||||
audioMenuOptions := []discordgo.SelectMenuOption{}
|
audioMenuOptions := buildAudioMenuOptions(state.FormatOptions.AudioOptions)
|
||||||
for _, aOpt := range state.FormatOptions.AudioOptions {
|
|
||||||
label := aOpt.Format
|
|
||||||
if aOpt.Language != nil {
|
|
||||||
label += fmt.Sprintf(" [%s]", *aOpt.Language)
|
|
||||||
}
|
|
||||||
if aOpt.TBR != nil {
|
|
||||||
label += fmt.Sprintf(" (%.0fkbps)", *aOpt.TBR)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Discord has a 100 char limit on labels
|
|
||||||
if len(label) > 100 {
|
|
||||||
label = label[:97] + "..."
|
|
||||||
}
|
|
||||||
|
|
||||||
audioMenuOptions = append(audioMenuOptions, discordgo.SelectMenuOption{
|
|
||||||
Label: label,
|
|
||||||
Value: aOpt.FormatID,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Discord has a limit of 25 options per select menu
|
|
||||||
if len(audioMenuOptions) >= 25 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build video format options (to keep them visible but disabled)
|
// Build video format options (to keep them visible but disabled)
|
||||||
videoMenuOptions := []discordgo.SelectMenuOption{}
|
videoMenuOptions := buildVideoMenuOptions(state.FormatOptions.VideoOptions)
|
||||||
for _, vOpt := range state.FormatOptions.VideoOptions {
|
|
||||||
label := fmt.Sprintf("%s (%s", vOpt.Resolution, vOpt.Ext)
|
|
||||||
if vOpt.TBR != nil {
|
|
||||||
label += fmt.Sprintf(", %.0fkbps", *vOpt.TBR)
|
|
||||||
}
|
|
||||||
label += ")"
|
|
||||||
|
|
||||||
if len(label) > 100 {
|
|
||||||
label = label[:97] + "..."
|
|
||||||
}
|
|
||||||
|
|
||||||
videoMenuOptions = append(videoMenuOptions, discordgo.SelectMenuOption{
|
|
||||||
Label: label,
|
|
||||||
Value: vOpt.FormatID,
|
|
||||||
})
|
|
||||||
|
|
||||||
if len(videoMenuOptions) >= 25 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update components - disable video select, enable audio select
|
// Update components - disable video select, enable audio select
|
||||||
updatedComponents := []discordgo.MessageComponent{
|
updatedComponents := []discordgo.MessageComponent{
|
||||||
@@ -274,14 +248,7 @@ func main() {
|
|||||||
// Respond immediately to prevent timeout
|
// Respond immediately to prevent timeout
|
||||||
response = fmt.Sprintf("%s **Starting download**", loading_emoji)
|
response = fmt.Sprintf("%s **Starting download**", loading_emoji)
|
||||||
|
|
||||||
// Start async download after responding
|
// Clean up state before responding
|
||||||
go func() {
|
|
||||||
// Small delay to ensure response is sent first
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
startAsyncDownload(s, i, state.Requester, state.URL, state.VideoFormatID, state.VideoFormatName, state.AudioFormatID, state.AudioFormatName, out_dir, temp_dir)
|
|
||||||
}()
|
|
||||||
|
|
||||||
// Clean up state after starting download
|
|
||||||
deleteInteractionState(i.Interaction.Token)
|
deleteInteractionState(i.Interaction.Token)
|
||||||
} else {
|
} else {
|
||||||
response = "I don't see a video here :("
|
response = "I don't see a video here :("
|
||||||
@@ -296,6 +263,9 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error: %v", err)
|
log.Printf("Error: %v", err)
|
||||||
}
|
}
|
||||||
|
if state.URL != "" {
|
||||||
|
go startAsyncDownload(s, i, state.Requester, state.URL, state.VideoFormatID, state.VideoFormatName, state.AudioFormatID, state.AudioFormatName, out_dir, temp_dir)
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -335,150 +305,57 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fetch formats asynchronously
|
// Fetch formats asynchronously
|
||||||
go func() {
|
go fetchAndShowFormats(s, i, url)
|
||||||
formatOptions, err := GetFormats(url)
|
},
|
||||||
if err != nil {
|
"download video": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
data := i.ApplicationCommandData()
|
||||||
Content: ptr("❌ Error fetching formats: " + err.Error()),
|
targetMsg, ok := data.Resolved.Messages[data.TargetID]
|
||||||
})
|
if !ok || targetMsg == nil {
|
||||||
if err != nil {
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
log.Printf("Error updating interaction: %v", err)
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
}
|
Data: &discordgo.InteractionResponseData{
|
||||||
return
|
Content: "Error: Could not find the target message",
|
||||||
}
|
Flags: discordgo.MessageFlagsEphemeral,
|
||||||
|
|
||||||
// Sort video formats: highest resolution first, then by bitrate
|
|
||||||
sort.Slice(formatOptions.VideoOptions, func(i, j int) bool {
|
|
||||||
// Compare by height (descending)
|
|
||||||
heightI := 0
|
|
||||||
if formatOptions.VideoOptions[i].Height != nil {
|
|
||||||
heightI = *formatOptions.VideoOptions[i].Height
|
|
||||||
}
|
|
||||||
heightJ := 0
|
|
||||||
if formatOptions.VideoOptions[j].Height != nil {
|
|
||||||
heightJ = *formatOptions.VideoOptions[j].Height
|
|
||||||
}
|
|
||||||
|
|
||||||
if heightI != heightJ {
|
|
||||||
return heightI > heightJ
|
|
||||||
}
|
|
||||||
|
|
||||||
// If heights are equal, compare by TBR (descending)
|
|
||||||
tbrI := 0.0
|
|
||||||
if formatOptions.VideoOptions[i].TBR != nil {
|
|
||||||
tbrI = *formatOptions.VideoOptions[i].TBR
|
|
||||||
}
|
|
||||||
tbrJ := 0.0
|
|
||||||
if formatOptions.VideoOptions[j].TBR != nil {
|
|
||||||
tbrJ = *formatOptions.VideoOptions[j].TBR
|
|
||||||
}
|
|
||||||
|
|
||||||
return tbrI > tbrJ
|
|
||||||
})
|
|
||||||
|
|
||||||
// Sort audio formats: highest bitrate first
|
|
||||||
sort.Slice(formatOptions.AudioOptions, func(i, j int) bool {
|
|
||||||
tbrI := 0.0
|
|
||||||
if formatOptions.AudioOptions[i].TBR != nil {
|
|
||||||
tbrI = *formatOptions.AudioOptions[i].TBR
|
|
||||||
}
|
|
||||||
tbrJ := 0.0
|
|
||||||
if formatOptions.AudioOptions[j].TBR != nil {
|
|
||||||
tbrJ = *formatOptions.AudioOptions[j].TBR
|
|
||||||
}
|
|
||||||
|
|
||||||
return tbrI > tbrJ
|
|
||||||
})
|
|
||||||
|
|
||||||
// Build video format options for Discord select menu
|
|
||||||
videoMenuOptions := []discordgo.SelectMenuOption{}
|
|
||||||
for _, vOpt := range formatOptions.VideoOptions {
|
|
||||||
label := fmt.Sprintf("%s (%s", vOpt.Resolution, vOpt.Ext)
|
|
||||||
if vOpt.TBR != nil {
|
|
||||||
label += fmt.Sprintf(", %.0fkbps", *vOpt.TBR)
|
|
||||||
}
|
|
||||||
label += ")"
|
|
||||||
|
|
||||||
// Discord has a 100 char limit on labels
|
|
||||||
if len(label) > 100 {
|
|
||||||
label = label[:97] + "..."
|
|
||||||
}
|
|
||||||
|
|
||||||
videoMenuOptions = append(videoMenuOptions, discordgo.SelectMenuOption{
|
|
||||||
Label: label,
|
|
||||||
Value: vOpt.FormatID,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Discord has a limit of 25 options per select menu
|
|
||||||
if len(videoMenuOptions) >= 25 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Build audio format options for Discord select menu
|
|
||||||
audioMenuOptions := []discordgo.SelectMenuOption{}
|
|
||||||
for _, aOpt := range formatOptions.AudioOptions {
|
|
||||||
label := aOpt.Format
|
|
||||||
if aOpt.Language != nil {
|
|
||||||
label += fmt.Sprintf(" [%s]", *aOpt.Language)
|
|
||||||
}
|
|
||||||
if aOpt.TBR != nil {
|
|
||||||
label += fmt.Sprintf(" (%.0fkbps)", *aOpt.TBR)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Discord has a 100 char limit on labels
|
|
||||||
if len(label) > 100 {
|
|
||||||
label = label[:97] + "..."
|
|
||||||
}
|
|
||||||
|
|
||||||
audioMenuOptions = append(audioMenuOptions, discordgo.SelectMenuOption{
|
|
||||||
Label: label,
|
|
||||||
Value: aOpt.FormatID,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Discord has a limit of 25 options per select menu
|
|
||||||
if len(audioMenuOptions) >= 25 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store format options in interaction state
|
|
||||||
setInteractionState(i.Interaction.Token, &InteractionState{
|
|
||||||
URL: url,
|
|
||||||
FormatOptions: formatOptions,
|
|
||||||
})
|
|
||||||
|
|
||||||
// Update message with format selection menus
|
|
||||||
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
|
||||||
Content: ptr("Select a video format:"),
|
|
||||||
Components: &[]discordgo.MessageComponent{
|
|
||||||
discordgo.ActionsRow{
|
|
||||||
Components: []discordgo.MessageComponent{
|
|
||||||
discordgo.SelectMenu{
|
|
||||||
CustomID: "video_select",
|
|
||||||
Placeholder: "Choose a video format...",
|
|
||||||
MaxValues: 1,
|
|
||||||
Options: videoMenuOptions,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
discordgo.ActionsRow{
|
|
||||||
Components: []discordgo.MessageComponent{
|
|
||||||
discordgo.SelectMenu{
|
|
||||||
CustomID: "audio_select",
|
|
||||||
Placeholder: "Choose an audio format...",
|
|
||||||
MaxValues: 1,
|
|
||||||
Disabled: true,
|
|
||||||
Options: audioMenuOptions,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
if err != nil {
|
return
|
||||||
log.Printf("Error updating interaction: %v", err)
|
}
|
||||||
}
|
url := extractURLFromString(targetMsg.Content)
|
||||||
}()
|
if url == "" {
|
||||||
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
Content: "Error: No URL provided",
|
||||||
|
Flags: discordgo.MessageFlagsEphemeral,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send initial "fetching formats" response
|
||||||
|
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
Content: fmt.Sprintf("%s Fetching available formats...", loading_emoji),
|
||||||
|
Flags: discordgo.MessageFlagsEphemeral,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch formats asynchronously
|
||||||
|
go fetchAndShowFormats(s, i, url)
|
||||||
|
},
|
||||||
|
"version": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
|
||||||
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
Content: "[yt-dlp-bot](https://git.dubyatp.xyz/williamp/yt-dlp-bot) by dubyatp",
|
||||||
|
Flags: discordgo.MessageFlagsEphemeral,
|
||||||
|
},
|
||||||
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -488,19 +365,29 @@ func main() {
|
|||||||
if h, ok := commandHandlers[i.ApplicationCommandData().Name]; ok {
|
if h, ok := commandHandlers[i.ApplicationCommandData().Name]; ok {
|
||||||
h(s, i)
|
h(s, i)
|
||||||
}
|
}
|
||||||
if h, ok := componentHandlers[i.ApplicationCommandData().Name]; ok {
|
|
||||||
h(s, i)
|
|
||||||
}
|
|
||||||
case discordgo.InteractionMessageComponent:
|
case discordgo.InteractionMessageComponent:
|
||||||
if h, ok := commandHandlers[i.MessageComponentData().CustomID]; ok {
|
customID := i.MessageComponentData().CustomID
|
||||||
h(s, i)
|
if h, ok := componentHandlers[customID]; ok {
|
||||||
}
|
|
||||||
if h, ok := componentHandlers[i.MessageComponentData().CustomID]; ok {
|
|
||||||
h(s, i)
|
h(s, i)
|
||||||
|
} else if strings.HasPrefix(customID, "retry:") {
|
||||||
|
url := strings.TrimPrefix(customID, "retry:")
|
||||||
|
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||||
|
Type: discordgo.InteractionResponseUpdateMessage,
|
||||||
|
Data: &discordgo.InteractionResponseData{
|
||||||
|
Content: fmt.Sprintf("%s Fetching available formats...", loading_emoji),
|
||||||
|
Components: []discordgo.MessageComponent{},
|
||||||
|
Flags: discordgo.MessageFlagsEphemeral,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
go fetchAndShowFormats(s, i, url)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
log.Println("Initialize loading emoji")
|
||||||
|
initLoadingEmoji(s)
|
||||||
|
|
||||||
|
|
||||||
log.Println("Adding commands")
|
log.Println("Adding commands")
|
||||||
registeredCommands := make([]*discordgo.ApplicationCommand, len(commands))
|
registeredCommands := make([]*discordgo.ApplicationCommand, len(commands))
|
||||||
for i, v := range commands {
|
for i, v := range commands {
|
||||||
@@ -518,3 +405,154 @@ func main() {
|
|||||||
|
|
||||||
s.Close()
|
s.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func buildVideoMenuOptions(videoOptions []VideoOption) []discordgo.SelectMenuOption {
|
||||||
|
opts := make([]discordgo.SelectMenuOption, 0, 25)
|
||||||
|
for _, vOpt := range videoOptions {
|
||||||
|
label := fmt.Sprintf("%s (%s", vOpt.Resolution, vOpt.Ext)
|
||||||
|
if vOpt.TBR != nil {
|
||||||
|
label += fmt.Sprintf(", %.0fkbps", *vOpt.TBR)
|
||||||
|
}
|
||||||
|
label += ")"
|
||||||
|
if len(label) > 100 {
|
||||||
|
label = label[:97] + "..."
|
||||||
|
}
|
||||||
|
opts = append(opts, discordgo.SelectMenuOption{
|
||||||
|
Label: label,
|
||||||
|
Value: vOpt.FormatID,
|
||||||
|
})
|
||||||
|
if len(opts) >= 25 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return opts
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildAudioMenuOptions(audioOptions []AudioOption) []discordgo.SelectMenuOption {
|
||||||
|
opts := make([]discordgo.SelectMenuOption, 0, 25)
|
||||||
|
for _, aOpt := range audioOptions {
|
||||||
|
label := aOpt.Format
|
||||||
|
if aOpt.Language != nil {
|
||||||
|
label += fmt.Sprintf(" [%s]", *aOpt.Language)
|
||||||
|
}
|
||||||
|
if aOpt.TBR != nil {
|
||||||
|
label += fmt.Sprintf(" (%.0fkbps)", *aOpt.TBR)
|
||||||
|
}
|
||||||
|
if len(label) > 100 {
|
||||||
|
label = label[:97] + "..."
|
||||||
|
}
|
||||||
|
opts = append(opts, discordgo.SelectMenuOption{
|
||||||
|
Label: label,
|
||||||
|
Value: aOpt.FormatID,
|
||||||
|
})
|
||||||
|
if len(opts) >= 25 {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return opts
|
||||||
|
}
|
||||||
|
|
||||||
|
func fetchAndShowFormats(s *discordgo.Session, i *discordgo.InteractionCreate, url string) {
|
||||||
|
formatOptions, err := GetFormats(url)
|
||||||
|
if err != nil {
|
||||||
|
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
||||||
|
Content: ptr("❌ Error fetching formats: " + err.Error()),
|
||||||
|
Components: &[]discordgo.MessageComponent{
|
||||||
|
&discordgo.ActionsRow{
|
||||||
|
Components: []discordgo.MessageComponent{
|
||||||
|
discordgo.Button{
|
||||||
|
Label: "Retry",
|
||||||
|
CustomID: fmt.Sprintf("retry:%s", url),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error updating interaction: %v", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sort video formats: highest resolution first, then by bitrate
|
||||||
|
sort.Slice(formatOptions.VideoOptions, func(x, y int) bool {
|
||||||
|
heightX, heightY := 0, 0
|
||||||
|
if formatOptions.VideoOptions[x].Height != nil {
|
||||||
|
heightX = *formatOptions.VideoOptions[x].Height
|
||||||
|
}
|
||||||
|
if formatOptions.VideoOptions[y].Height != nil {
|
||||||
|
heightY = *formatOptions.VideoOptions[y].Height
|
||||||
|
}
|
||||||
|
if heightX != heightY {
|
||||||
|
return heightX > heightY
|
||||||
|
}
|
||||||
|
tbrX, tbrY := 0.0, 0.0
|
||||||
|
if formatOptions.VideoOptions[x].TBR != nil {
|
||||||
|
tbrX = *formatOptions.VideoOptions[x].TBR
|
||||||
|
}
|
||||||
|
if formatOptions.VideoOptions[y].TBR != nil {
|
||||||
|
tbrY = *formatOptions.VideoOptions[y].TBR
|
||||||
|
}
|
||||||
|
return tbrX > tbrY
|
||||||
|
})
|
||||||
|
|
||||||
|
// Sort audio formats: highest bitrate first
|
||||||
|
sort.Slice(formatOptions.AudioOptions, func(x, y int) bool {
|
||||||
|
tbrX, tbrY := 0.0, 0.0
|
||||||
|
if formatOptions.AudioOptions[x].TBR != nil {
|
||||||
|
tbrX = *formatOptions.AudioOptions[x].TBR
|
||||||
|
}
|
||||||
|
if formatOptions.AudioOptions[y].TBR != nil {
|
||||||
|
tbrY = *formatOptions.AudioOptions[y].TBR
|
||||||
|
}
|
||||||
|
return tbrX > tbrY
|
||||||
|
})
|
||||||
|
|
||||||
|
videoMenuOptions := buildVideoMenuOptions(formatOptions.VideoOptions)
|
||||||
|
audioMenuOptions := buildAudioMenuOptions(formatOptions.AudioOptions)
|
||||||
|
|
||||||
|
if len(videoMenuOptions) == 0 || len(audioMenuOptions) == 0 {
|
||||||
|
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
||||||
|
Content: ptr("❌ No separate video/audio streams found for this URL. The source may only provide combined formats."),
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error updating interaction: %v", err)
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
setInteractionState(i.Interaction.Token, &InteractionState{
|
||||||
|
URL: url,
|
||||||
|
FormatOptions: formatOptions,
|
||||||
|
})
|
||||||
|
|
||||||
|
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
||||||
|
Content: ptr("Select a video format:"),
|
||||||
|
Components: &[]discordgo.MessageComponent{
|
||||||
|
discordgo.ActionsRow{
|
||||||
|
Components: []discordgo.MessageComponent{
|
||||||
|
discordgo.SelectMenu{
|
||||||
|
CustomID: "video_select",
|
||||||
|
Placeholder: "Choose a video format...",
|
||||||
|
MaxValues: 1,
|
||||||
|
Options: videoMenuOptions,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
discordgo.ActionsRow{
|
||||||
|
Components: []discordgo.MessageComponent{
|
||||||
|
discordgo.SelectMenu{
|
||||||
|
CustomID: "audio_select",
|
||||||
|
Placeholder: "Choose an audio format...",
|
||||||
|
MaxValues: 1,
|
||||||
|
Disabled: true,
|
||||||
|
Options: audioMenuOptions,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Error updating interaction: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
+43
-2
@@ -2,10 +2,51 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"log"
|
||||||
|
"regexp"
|
||||||
|
_ "embed"
|
||||||
|
"encoding/base64"
|
||||||
|
|
||||||
|
"github.com/bwmarrin/discordgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
var loading_emoji = os.Getenv("LOADING_EMOJI")
|
var loading_emoji string
|
||||||
|
|
||||||
|
//go:embed assets/loading.webp
|
||||||
|
var rawLoadingEmoji []byte
|
||||||
|
|
||||||
|
var loadingEmojiBase64 = func() string {
|
||||||
|
s := "data:image/webp;base64," + base64.StdEncoding.EncodeToString(rawLoadingEmoji)
|
||||||
|
rawLoadingEmoji = nil
|
||||||
|
return s
|
||||||
|
}()
|
||||||
|
|
||||||
|
func initLoadingEmoji(s *discordgo.Session) {
|
||||||
|
emojis, err := s.ApplicationEmojis(s.State.User.ID)
|
||||||
|
if err != nil {
|
||||||
|
log.Panic("Cannot get emojis")
|
||||||
|
}
|
||||||
|
for _, e := range emojis {
|
||||||
|
if e.Name == "loading" {
|
||||||
|
loading_emoji = fmt.Sprintf("<a:%s:%s>", e.Name, e.ID)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e, err := s.ApplicationEmojiCreate(s.State.User.ID, &discordgo.EmojiParams{
|
||||||
|
Name: "loading",
|
||||||
|
Image: loadingEmojiBase64,
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
log.Panicf("Cannot create loading emoji: %s", err)
|
||||||
|
}
|
||||||
|
loading_emoji = fmt.Sprintf("<a:%s:%s>", e.Name, e.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
var urlPattern = regexp.MustCompile(`https?://\S+`)
|
||||||
|
|
||||||
|
func extractURLFromString(in_url string) string {
|
||||||
|
return string(urlPattern.Find([]byte(in_url)))
|
||||||
|
}
|
||||||
|
|
||||||
// Helper function to create string pointer
|
// Helper function to create string pointer
|
||||||
func ptr(s string) *string {
|
func ptr(s string) *string {
|
||||||
|
|||||||
+3
-2
@@ -19,7 +19,9 @@ func GetFormats(url string) (*FormatOptions, error) {
|
|||||||
SkipDownload().
|
SkipDownload().
|
||||||
DumpJSON()
|
DumpJSON()
|
||||||
|
|
||||||
result, err := dl.Run(context.TODO(), url)
|
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
|
||||||
|
defer cancel()
|
||||||
|
result, err := dl.Run(ctx, url)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -154,7 +156,6 @@ func DownloadVideo(out_dir, temp_dir, url string, opts DownloadOptions, progress
|
|||||||
SetExecutable(ytdlpBinary).
|
SetExecutable(ytdlpBinary).
|
||||||
Paths(homePath).
|
Paths(homePath).
|
||||||
Paths(tempPath).
|
Paths(tempPath).
|
||||||
RecodeVideo("mp4").
|
|
||||||
ProgressFunc(100*time.Millisecond, func(prog ytdlp.ProgressUpdate) {
|
ProgressFunc(100*time.Millisecond, func(prog ytdlp.ProgressUpdate) {
|
||||||
if prog.Status == ytdlp.ProgressStatusFinished ||
|
if prog.Status == ytdlp.ProgressStatusFinished ||
|
||||||
prog.Status == ytdlp.ProgressStatusStarting ||
|
prog.Status == ytdlp.ProgressStatusStarting ||
|
||||||
|
|||||||
Reference in New Issue
Block a user