Compare commits
49 Commits
600fde2e71
...
v1.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
5748834af4
|
|||
|
06d2a5ef01
|
|||
|
bdcd77eff1
|
|||
|
4541559f47
|
|||
|
906ef98bd5
|
|||
|
640c952b20
|
|||
|
f30686fd7c
|
|||
|
eceb3b3d76
|
|||
|
23a27217df
|
|||
|
82a6421c88
|
|||
|
c72bc42496
|
|||
|
991a5f376f
|
|||
|
13bd3b82db
|
|||
|
2c99fbf517
|
|||
|
890a0dd5c9
|
|||
|
6fd6160edf
|
|||
|
43c2fa2f91
|
|||
| 81968a6811 | |||
|
7d83fd8518
|
|||
| 7b34919e72 | |||
|
98fec74ac0
|
|||
|
481c8d9bb6
|
|||
|
3cac63ba82
|
|||
|
b3d779374b
|
|||
| 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
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
uses: docker/setup-buildx-action@v4
|
||||
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
|
||||
uses: docker/login-action@v4
|
||||
with:
|
||||
registry: git.dubyatp.xyz
|
||||
username: williamp
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
|
||||
# Build and push the Docker image
|
||||
- name: Build and Push Docker Image
|
||||
uses: docker/build-push-action@v6
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: . # Build context (current directory)
|
||||
file: ./Dockerfile # Path to Dockerfile
|
||||
@@ -75,8 +75,13 @@ jobs:
|
||||
git config --local user.signingkey ~/.ssh/id_ed25519
|
||||
git config --local gpg.format ssh
|
||||
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
|
||||
uses: ad-m/github-push-action@v1.0.0
|
||||
with:
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
name: Build only (for PRs)
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
build-only:
|
||||
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'
|
||||
|
||||
# Build the Docker image
|
||||
- name: Build Docker Image
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
context: . # Build context (current directory)
|
||||
file: ./Dockerfile # Path to Dockerfile
|
||||
platforms: "linux/amd64,linux/arm64"
|
||||
+91
-6
@@ -1,6 +1,91 @@
|
||||
FROM python:3.14.2-alpine3.22
|
||||
COPY ./app /app
|
||||
WORKDIR /app
|
||||
RUN apk add ffmpeg deno
|
||||
RUN pip install -r requirements.txt
|
||||
CMD ["python", "/app/main.py"]
|
||||
# Portions of this Dockerfile are sourced from GPLv3 licensed `yt-dlp slim` by Henrique Almeida (https://github.com/h3nc4/yt-dlp-slim)
|
||||
# Derivations to this Dockerfile in this repository following March 3, 2026 should be considered licensed under this project's MIT license (see ../LICENSE) unless otherwise stated
|
||||
|
||||
########################################
|
||||
# Versions
|
||||
ARG YT_DLP_VERSION="2026.03.03"
|
||||
|
||||
################################################################################
|
||||
# Deno builder stage
|
||||
FROM denoland/deno:bin-2.6.6@sha256:9f18d20207f2699595ea26d14e0b7e123cd0cd01100a577bc11f8ca5906c2d81 AS deno-builder
|
||||
|
||||
################################################################################
|
||||
# YT-DLP builder stage
|
||||
FROM alpine:3.23@sha256:25109184c71bdad752c8312a8623239686a9a2071e8825f20acb8f2198c3f659 AS yt-dlp-builder
|
||||
ARG YT_DLP_VERSION
|
||||
ARG TARGETARCH
|
||||
|
||||
RUN mkdir -p /rootfs/target /rootfs/tmp /rootfs/bin
|
||||
|
||||
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://keyserver.ubuntu.com/pks/lookup?op=get&search=0xAC0CBBE6848D6A873464AF4E57CF65933B5A7581" "/yt-dlp_pubkey.asc"
|
||||
|
||||
RUN apk add --no-cache gnupg && \
|
||||
gpg --import /yt-dlp_pubkey.asc && \
|
||||
gpg --verify /SHA2-256SUMS.sig /SHA2-256SUMS
|
||||
|
||||
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 1777 /rootfs/tmp
|
||||
|
||||
################################################################################
|
||||
# FFmpeg builder stage
|
||||
FROM debian:13-slim@sha256:1d3c811171a08a5adaa4a163fbafd96b61b87aa871bbc7aa15431ac275d3d430 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
|
||||
FROM golang:1.25.8-trixie@sha256:bc16125656839ffe56154c675f7a9662bec2ef7d4060177239914e7c6d2fd8a8 AS app-builder
|
||||
|
||||
COPY app/ /opt/app
|
||||
WORKDIR /opt/app
|
||||
|
||||
RUN go get && go build -o out/yt-dlp-bot
|
||||
|
||||
################################################################################
|
||||
# Final squashed image
|
||||
FROM scratch AS final
|
||||
|
||||
# Copy deno, yt-dlp, and ffmpeg binaries
|
||||
COPY --from=deno-builder /deno /bin/deno
|
||||
COPY --from=yt-dlp-builder /rootfs /
|
||||
COPY --from=ffmpeg-builder /rootfs/ /
|
||||
|
||||
# Copy yt-dlp-bot app binary
|
||||
COPY --from=app-builder /opt/app/out/yt-dlp-bot /bin/
|
||||
|
||||
# Copy SSL CA's (needed for Discord)
|
||||
COPY --from=app-builder /etc/ssl/certs /etc/ssl/certs
|
||||
|
||||
WORKDIR /target
|
||||
ENV XDG_CACHE_HOME=/tmp/.cache
|
||||
|
||||
ENV YTDLP_BIN=/bin/yt-dlp
|
||||
|
||||
ENTRYPOINT ["/bin/yt-dlp-bot"]
|
||||
|
||||
LABEL org.opencontainers.image.title="yt-dlp bot" \
|
||||
org.opencontainers.image.description="A totally overengineered Discord bot to locally download YouTube videos for private use" \
|
||||
org.opencontainers.image.authors="William Peebles <me@williamtpeebles.com>" \
|
||||
org.opencontainers.image.vendor="William Peebles" \
|
||||
org.opencontainers.image.licenses="MIT" \
|
||||
org.opencontainers.image.source="https://git.dubyatp.xyz/williamp/yt-dlp-bot"
|
||||
+22
-18
@@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
// startAsyncDownload initiates a download in a goroutine and handles progress updates
|
||||
func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, url, videoFormatID, audioFormatID, outputDir, tempDir string) {
|
||||
func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, requester, url, videoFormatID, videoFormatName, audioFormatID, audioFormatName, outputDir, tempDir string) {
|
||||
progressChan := make(chan ProgressUpdate, 1)
|
||||
resultChan := make(chan DownloadResult, 1)
|
||||
|
||||
@@ -20,7 +20,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, ur
|
||||
// Handle panic from DownloadVideo
|
||||
resultChan <- DownloadResult{
|
||||
Success: false,
|
||||
Message: fmt.Sprintf("Download failed: %v", r),
|
||||
Message: fmt.Sprintf("❌ **Download Failed**: %v", r),
|
||||
URL: url,
|
||||
Format: fmt.Sprintf("video: %s, audio: %s", videoFormatID, audioFormatID),
|
||||
Error: fmt.Errorf("%v", r),
|
||||
@@ -39,7 +39,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, ur
|
||||
// If we reach here, download was successful
|
||||
resultChan <- DownloadResult{
|
||||
Success: true,
|
||||
Message: "Video Downloaded Successfully!",
|
||||
Message: "✅ **Successfully Downloaded**",
|
||||
URL: url,
|
||||
Format: fmt.Sprintf("video: %s, audio: %s", videoFormatID, audioFormatID),
|
||||
Error: nil,
|
||||
@@ -48,9 +48,8 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, ur
|
||||
|
||||
// Handle progress and results asynchronously
|
||||
go func() {
|
||||
// First update the original ephemeral message with "Processing..."
|
||||
_, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
||||
Content: ptr(fmt.Sprintf("🔄 Processing download...\nURL: %s\nVideo: %s\nAudio: %s", url, videoFormatID, audioFormatID)),
|
||||
Content: ptr(fmt.Sprintf("%s **Starting Download**", loading_emoji)),
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("Error updating interaction: %v", err)
|
||||
@@ -63,36 +62,41 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, ur
|
||||
progressChan = nil
|
||||
continue
|
||||
}
|
||||
// Update message w/ phase and real time progress
|
||||
phaseEmoji := "⏬"
|
||||
|
||||
var content string
|
||||
if prog.Phase == "post-processing" {
|
||||
phaseEmoji = "⚙️"
|
||||
content = fmt.Sprintf("%s **Post Processing**", loading_emoji)
|
||||
} else {
|
||||
var progressStr string
|
||||
if prog.DownloadedBytes > 0 {
|
||||
progressStr = formatBytes(prog.DownloadedBytes) + " downloaded"
|
||||
} else {
|
||||
progressStr = "starting..."
|
||||
}
|
||||
content = fmt.Sprintf("%s **Downloading Video**: %s", loading_emoji, progressStr)
|
||||
}
|
||||
content := fmt.Sprintf("%s %s\n%s @ %s [eta: %s]\n📄 %s",
|
||||
phaseEmoji,
|
||||
prog.Phase,
|
||||
prog.Status,
|
||||
prog.Percent,
|
||||
prog.ETA,
|
||||
prog.Filename)
|
||||
|
||||
_, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
||||
Content: ptr(content),
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("Error updating progress: %v", err)
|
||||
}
|
||||
|
||||
case result := <-resultChan:
|
||||
// Handle completion
|
||||
if result.Success {
|
||||
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
||||
Content: ptr("✅ **Successfully Downloaded**"),
|
||||
})
|
||||
_, err = s.FollowupMessageCreate(i.Interaction, false, &discordgo.WebhookParams{
|
||||
Content: "📥 Video downloaded: " + result.URL,
|
||||
Content: fmt.Sprintf("## Video Downloaded \n**URL**: %s \n**Quality**: %s + %s \n**Requested By**: <@%s> \n", result.URL, videoFormatName, audioFormatName, requester),
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("Error updating interaction: %v", err)
|
||||
}
|
||||
} else {
|
||||
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
||||
Content: ptr("❌ Download failed: " + result.Message),
|
||||
Content: ptr("❌ **Download Failed**: " + result.Message),
|
||||
})
|
||||
if err != nil {
|
||||
log.Printf("Error updating interaction: %v", err)
|
||||
|
||||
+34
-9
@@ -13,7 +13,6 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
out_dir := os.Getenv("OUT_PATH")
|
||||
temp_dir := os.Getenv("TEMP_PATH")
|
||||
bot_token := os.Getenv("DISCORD_TOKEN")
|
||||
@@ -93,6 +92,9 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
// Get requester user ID
|
||||
state.Requester = i.User.ID
|
||||
|
||||
// Get selected video format
|
||||
selectedValues := i.MessageComponentData().Values
|
||||
if len(selectedValues) == 0 {
|
||||
@@ -106,8 +108,19 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
// Store selected video format ID
|
||||
// Store selected video format ID and name
|
||||
state.VideoFormatID = selectedValues[0]
|
||||
for _, vOpt := range state.FormatOptions.VideoOptions {
|
||||
if vOpt.FormatID == selectedValues[0] {
|
||||
label := fmt.Sprintf("%s (%s", vOpt.Resolution, vOpt.Ext)
|
||||
if vOpt.TBR != nil {
|
||||
label += fmt.Sprintf(", %.0fkbps", *vOpt.TBR)
|
||||
}
|
||||
label += ")"
|
||||
state.VideoFormatName = label
|
||||
break
|
||||
}
|
||||
}
|
||||
setInteractionState(i.Interaction.Token, state)
|
||||
|
||||
// Build audio format options
|
||||
@@ -224,7 +237,7 @@ func main() {
|
||||
}
|
||||
if state == nil {
|
||||
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Type: discordgo.InteractionResponseUpdateMessage,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "Error: No video URL found. Please start over with /download.",
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
@@ -240,20 +253,32 @@ func main() {
|
||||
audioFormatID = selectedValues[0]
|
||||
}
|
||||
|
||||
// Store selected audio format ID
|
||||
// Store selected audio format ID and name
|
||||
state.AudioFormatID = audioFormatID
|
||||
for _, aOpt := range state.FormatOptions.AudioOptions {
|
||||
if aOpt.FormatID == audioFormatID {
|
||||
label := aOpt.Format
|
||||
if aOpt.Language != nil {
|
||||
label += fmt.Sprintf(" [%s]", *aOpt.Language)
|
||||
}
|
||||
if aOpt.TBR != nil {
|
||||
label += fmt.Sprintf(" (%.0fkbps)", *aOpt.TBR)
|
||||
}
|
||||
state.AudioFormatName = label
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
response := ""
|
||||
if state.URL != "" {
|
||||
// Respond immediately to prevent timeout
|
||||
response = fmt.Sprintf("🚀 Starting download...\nURL: %s\nVideo: %s\nAudio: %s\n\nYou'll receive an update when the download completes!",
|
||||
state.URL, state.VideoFormatID, state.AudioFormatID)
|
||||
response = fmt.Sprintf("%s **Starting download**", loading_emoji)
|
||||
|
||||
// Start async download after responding
|
||||
go func() {
|
||||
// Small delay to ensure response is sent first
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
startAsyncDownload(s, i, state.URL, state.VideoFormatID, state.AudioFormatID, out_dir, temp_dir)
|
||||
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
|
||||
@@ -262,7 +287,7 @@ func main() {
|
||||
response = "I don't see a video here :("
|
||||
}
|
||||
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Type: discordgo.InteractionResponseUpdateMessage,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: response,
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
@@ -300,7 +325,7 @@ func main() {
|
||||
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
|
||||
Type: discordgo.InteractionResponseChannelMessageWithSource,
|
||||
Data: &discordgo.InteractionResponseData{
|
||||
Content: "🔍 Fetching available formats...",
|
||||
Content: fmt.Sprintf("%s Fetching available formats...", loading_emoji),
|
||||
Flags: discordgo.MessageFlagsEphemeral,
|
||||
},
|
||||
})
|
||||
|
||||
+20
@@ -1,6 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
var loading_emoji = os.Getenv("LOADING_EMOJI")
|
||||
|
||||
// Helper function to create string pointer
|
||||
func ptr(s string) *string {
|
||||
return &s
|
||||
}
|
||||
|
||||
func formatBytes(b int) string {
|
||||
switch {
|
||||
case b >= 1<<30:
|
||||
return fmt.Sprintf("%.1f GB", float64(b)/float64(1<<30))
|
||||
case b >= 1<<20:
|
||||
return fmt.Sprintf("%.1f MB", float64(b)/float64(1<<20))
|
||||
case b >= 1<<10:
|
||||
return fmt.Sprintf("%.1f KB", float64(b)/float64(1<<10))
|
||||
default:
|
||||
return fmt.Sprintf("%d B", b)
|
||||
}
|
||||
}
|
||||
|
||||
+10
-15
@@ -1,11 +1,5 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/lrstanley/go-ytdlp"
|
||||
)
|
||||
|
||||
type DownloadOptions struct {
|
||||
EmbedThumbnail bool
|
||||
IncludeSubtitles bool
|
||||
@@ -35,19 +29,20 @@ type FormatOptions struct {
|
||||
}
|
||||
|
||||
type ProgressUpdate struct {
|
||||
Status ytdlp.ProgressStatus
|
||||
Percent string
|
||||
ETA time.Duration
|
||||
Filename string
|
||||
Phase string
|
||||
Phase string
|
||||
DownloadedBytes int
|
||||
Filename string
|
||||
}
|
||||
|
||||
// InteractionState holds the state for a specific interaction
|
||||
type InteractionState struct {
|
||||
URL string
|
||||
FormatOptions *FormatOptions
|
||||
VideoFormatID string
|
||||
AudioFormatID string
|
||||
Requester string
|
||||
URL string
|
||||
FormatOptions *FormatOptions
|
||||
VideoFormatID string
|
||||
VideoFormatName string
|
||||
AudioFormatID string
|
||||
AudioFormatName string
|
||||
}
|
||||
|
||||
// DownloadResult represents the result of an async download operation
|
||||
|
||||
+61
-21
@@ -4,6 +4,8 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lrstanley/go-ytdlp"
|
||||
@@ -95,41 +97,79 @@ func GetFormats(url string) (*FormatOptions, error) {
|
||||
return formatOpts, nil
|
||||
}
|
||||
|
||||
func dirSize(path string) int {
|
||||
var total int64
|
||||
filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
|
||||
if err == nil && !info.IsDir() {
|
||||
total += info.Size()
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return int(total)
|
||||
}
|
||||
|
||||
func DownloadVideo(out_dir, temp_dir, url string, opts DownloadOptions, progressChan chan<- ProgressUpdate) {
|
||||
defer close(progressChan)
|
||||
var mu sync.Mutex
|
||||
currentPhase := "downloading"
|
||||
currentFilename := ""
|
||||
|
||||
// Poll the temp directory for actual bytes-on-disk progress.
|
||||
// The yt-dlp progress callback only tracks phase/filename since
|
||||
// DownloadedBytes from the callback is unreliable for DASH streams.
|
||||
var wg sync.WaitGroup
|
||||
wg.Add(1)
|
||||
stopPoll := make(chan struct{})
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
ticker := time.NewTicker(500 * time.Millisecond)
|
||||
defer ticker.Stop()
|
||||
for {
|
||||
select {
|
||||
case <-stopPoll:
|
||||
return
|
||||
case <-ticker.C:
|
||||
mu.Lock()
|
||||
phase := currentPhase
|
||||
filename := currentFilename
|
||||
mu.Unlock()
|
||||
progressChan <- ProgressUpdate{
|
||||
Phase: phase,
|
||||
DownloadedBytes: dirSize(temp_dir),
|
||||
Filename: filename,
|
||||
}
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
defer func() {
|
||||
close(stopPoll)
|
||||
wg.Wait()
|
||||
close(progressChan)
|
||||
}()
|
||||
|
||||
homePath := "home:" + out_dir
|
||||
tempPath := "temp:" + temp_dir
|
||||
|
||||
var lastPhase string
|
||||
|
||||
dl := ytdlp.New().
|
||||
SetExecutable(ytdlpBinary).
|
||||
Paths(homePath).
|
||||
Paths(tempPath).
|
||||
RecodeVideo("mp4").
|
||||
ProgressFunc(100*time.Millisecond, func(prog ytdlp.ProgressUpdate) {
|
||||
// Detect phase transition -- differentiate "downloading" as the main download
|
||||
// and "post processing" when the file name changes, preventing it from appearing "reset"
|
||||
if prog.Status == ytdlp.ProgressStatusFinished ||
|
||||
prog.Status == ytdlp.ProgressStatusStarting ||
|
||||
prog.Status == ytdlp.ProgressStatusError {
|
||||
return
|
||||
}
|
||||
|
||||
phase := "downloading"
|
||||
if prog.Status == ytdlp.ProgressStatusDownloading && prog.Percent() == 0.0 {
|
||||
// If we already had progress, it's likely post-processing
|
||||
if lastPhase == "downloading" {
|
||||
phase = "post-processing"
|
||||
}
|
||||
} else if prog.Status != ytdlp.ProgressStatusDownloading {
|
||||
if prog.Status == ytdlp.ProgressStatusPostProcessing {
|
||||
phase = "post-processing"
|
||||
}
|
||||
|
||||
lastPhase = phase
|
||||
|
||||
progressChan <- ProgressUpdate{
|
||||
Status: prog.Status,
|
||||
Percent: prog.PercentString(),
|
||||
ETA: prog.ETA(),
|
||||
Filename: prog.Filename,
|
||||
Phase: phase,
|
||||
}
|
||||
mu.Lock()
|
||||
currentPhase = phase
|
||||
currentFilename = prog.Filename
|
||||
mu.Unlock()
|
||||
}).
|
||||
Output("%(title)s.%(ext)s")
|
||||
|
||||
|
||||
Generated
+3
-3
@@ -2,11 +2,11 @@
|
||||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1770537093,
|
||||
"narHash": "sha256-pF1quXG5wsgtyuPOHcLfYg/ft/QMr8NnX0i6tW2187s=",
|
||||
"lastModified": 1772674223,
|
||||
"narHash": "sha256-/suKbHSaSmuC9UY7G0VRQ3aO+QKqxAQPQ19wG7QNkF8=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "fef9403a3e4d31b0a23f0bacebbec52c248fbb51",
|
||||
"rev": "66d9241e3dc2296726dc522e62dbfe89c7b449f3",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
||||
@@ -46,8 +46,11 @@
|
||||
.venv/bin/pip install -r ./app/requirements.txt
|
||||
source .venv/bin/activate
|
||||
fi
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
|
||||
export YTDLP_BIN=${pkgs.lib.getExe pkgs.yt-dlp}
|
||||
>>>>>>> v1-refactor
|
||||
'';
|
||||
};
|
||||
});
|
||||
|
||||
+17
-2
@@ -1,3 +1,18 @@
|
||||
{
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json"
|
||||
}
|
||||
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
|
||||
"customManagers": [
|
||||
{
|
||||
"description": "Update yt-dlp version in Dockerfiles",
|
||||
"customType": "regex",
|
||||
"managerFilePatterns": [
|
||||
"/^Dockerfile$/"
|
||||
],
|
||||
"matchStrings": [
|
||||
"ARG YT_DLP_VERSION=\"(?<currentValue>.*?)\""
|
||||
],
|
||||
"datasourceTemplate": "github-tags",
|
||||
"depNameTemplate": "yt-dlp/yt-dlp",
|
||||
"versioningTemplate": "regex:^(?<major>\\d{4})\\.(?<minor>\\d{2})\\.(?<patch>\\d{2})$"
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user