2 Commits

6 changed files with 35 additions and 7 deletions

View File

@@ -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 string) {
func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, url, videoFormatID, audioFormatID, outputDir, tempDir string) {
progressChan := make(chan ProgressUpdate, 1)
resultChan := make(chan DownloadResult, 1)
@@ -29,7 +29,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, ur
}()
// Call DownloadVideo (it panics on error instead of returning error)
DownloadVideo(outputDir, url, DownloadOptions{
DownloadVideo(outputDir, tempDir, url, DownloadOptions{
EmbedThumbnail: true,
IncludeSubtitles: true,
VideoFormatID: videoFormatID,

View File

@@ -2,6 +2,10 @@ module git.dubyatp.xyz/williamp/yt-dlp-bot
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 (
github.com/bwmarrin/discordgo v0.29.0
github.com/lrstanley/go-ytdlp v1.2.7

View File

@@ -4,10 +4,16 @@ 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/cloudflare/circl v1.6.1 h1:zqIqSPIndyBh1bjLVVDHMPpVKqp8Su/V+6MeDzzQBQ0=
github.com/cloudflare/circl v1.6.1/go.mod h1:uddAzsPgqdMAYatqJ0lsjX1oECcQLIlRpzZh3pJrofs=
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/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/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/lrstanley/go-ytdlp v1.2.7 h1:YNDvKkd0OCJSZLZePZvJwcirBCfL8Yw3eCwrTCE5w7Q=
github.com/lrstanley/go-ytdlp v1.2.7/go.mod h1:38IL64XM6gULrWtKTiR0+TTNCVbxesNSbTyaFG2CGTI=
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/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
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/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
golang.org/x/crypto v0.0.0-20210421170649-83a5a9bb288b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4=
@@ -20,3 +26,5 @@ golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
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/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

View File

@@ -15,12 +15,17 @@ import (
func main() {
out_dir := os.Getenv("OUT_PATH")
temp_dir := os.Getenv("TEMP_PATH")
bot_token := os.Getenv("DISCORD_TOKEN")
if out_dir == "" {
panic("No output dir specified")
}
if temp_dir == "" {
panic("No temp dir specified")
}
s, err := discordgo.New("Bot " + bot_token)
if err != nil {
log.Fatalf("Invalid bot parameters: %v", err)
@@ -248,7 +253,7 @@ func main() {
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)
startAsyncDownload(s, i, state.URL, state.VideoFormatID, state.AudioFormatID, out_dir, temp_dir)
}()
// Clean up state after starting download

View File

@@ -3,13 +3,17 @@ package main
import (
"context"
"encoding/json"
"os"
"time"
"github.com/lrstanley/go-ytdlp"
)
var ytdlpBinary = os.Getenv("YTDLP_BIN")
func GetFormats(url string) (*FormatOptions, error) {
dl := ytdlp.New().
SetExecutable(ytdlpBinary).
SkipDownload().
DumpJSON()
@@ -91,13 +95,18 @@ func GetFormats(url string) (*FormatOptions, error) {
return formatOpts, nil
}
func DownloadVideo(out_dir, url string, opts DownloadOptions, progressChan chan<- ProgressUpdate) {
func DownloadVideo(out_dir, temp_dir, url string, opts DownloadOptions, progressChan chan<- ProgressUpdate) {
defer close(progressChan)
homePath := "home:" + out_dir
tempPath := "temp:" + temp_dir
var lastPhase string
dl := ytdlp.New().
SetWorkDir(out_dir).
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

View File

@@ -46,6 +46,8 @@
.venv/bin/pip install -r ./app/requirements.txt
source .venv/bin/activate
fi
export YTDLP_BIN=${pkgs.lib.getExe pkgs.yt-dlp}
'';
};
});