3 Commits

Author SHA1 Message Date
ff02993a0a Merge branch 'master' into code-cleanup
All checks were successful
Build only (for PRs) / build-only (pull_request) Successful in 4m52s
2026-03-09 11:05:10 -04:00
52337254b6 bugfix: handle lack of separate audio/video streams
All checks were successful
Build only (for PRs) / build-only (pull_request) Successful in 3m47s
2026-03-09 10:58:56 -04:00
a44bb1bf34 optimize codebase
All checks were successful
Build only (for PRs) / build-only (pull_request) Successful in 3m33s
main.go:
- Eliminated ~160 lines of duplicate code: Extracted 3 new helper functions at the bottom of the file:
buildVideoMenuOptions([]VideoOption) — builds the Discord select menu options for video formats
buildAudioMenuOptions([]AudioOption) — same for audio
fetchAndShowFormats(s, i, url) — fetches formats, sorts them, builds menus, stores state, and edits the interaction; previously duplicated identically in both the download and download video command handlers
- Fixed time.Sleep ordering bug: The startAsyncDownload goroutine was launched before InteractionRespond with a 100ms sleep to compensate. Now the download is launched after InteractionRespond returns — no sleep needed. Removed "time" import.
- Used helpers in video_select handler: The two inline menu-building loops in that handler now call buildAudioMenuOptions / buildVideoMenuOptions

misc.go:
- Moved regexp.MustCompile(...) to a package-level var urlPattern — previously it recompiled the regex on every call to extractURLFromString
- Simplified the function body to a single return line
2026-03-09 10:46:10 -04:00
8 changed files with 10 additions and 77 deletions

View File

@@ -83,7 +83,7 @@ jobs:
fi
exit 0
- name: Push changes
uses: ad-m/github-push-action@v1.1.0
uses: ad-m/github-push-action@v1.0.0
with:
github_token: ${{ secrets.ACTIONS_TOKEN }}
repository: infrastructure/core-apps

View File

@@ -3,7 +3,7 @@
########################################
# Versions
ARG YT_DLP_VERSION="2026.03.17"
ARG YT_DLP_VERSION="2026.03.03"
################################################################################
# Deno builder stage
@@ -11,7 +11,7 @@ FROM denoland/deno:bin-2.6.6@sha256:9f18d20207f2699595ea26d14e0b7e123cd0cd01100a
################################################################################
# YT-DLP builder stage
FROM alpine:3.23@sha256:5b10f432ef3da1b8d4c7eb6c487f2f5a8f096bc91145e68878dd4a5019afde11 AS yt-dlp-builder
FROM alpine:3.23@sha256:25109184c71bdad752c8312a8623239686a9a2071e8825f20acb8f2198c3f659 AS yt-dlp-builder
ARG YT_DLP_VERSION
ARG TARGETARCH
@@ -38,7 +38,7 @@ RUN case "$TARGETARCH" in \
################################################################################
# FFmpeg builder stage
FROM debian:13-slim@sha256:4ffb3a1511099754cddc70eb1b12e50ffdb67619aa0ab6c13fcd800a78ef7c7a AS ffmpeg-builder
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
@@ -54,7 +54,7 @@ RUN mkdir -p /rootfs/bin && \
################################################################################
# App builder stage
FROM golang:1.26.2-trixie@sha256:c0074c718b473f3827043f86532c4c0ff537e3fe7a81b8219b0d1ccfcc2c9a09 AS app-builder
FROM golang:1.26.1-trixie@sha256:ab8c4944b04c6f97c2b5bffce471b7f3d55f2228badc55eae6cce87596d5710b AS app-builder
COPY app/ /opt/app
WORKDIR /opt/app

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

View File

@@ -4,7 +4,7 @@ go 1.25.2
require (
github.com/bwmarrin/discordgo v0.29.0
github.com/lrstanley/go-ytdlp v1.3.5
github.com/lrstanley/go-ytdlp v1.3.3
)
require (

View File

@@ -16,10 +16,6 @@ github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0U
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/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=

View File

@@ -6,7 +6,6 @@ import (
"os"
"os/signal"
"sort"
"strings"
"syscall"
"github.com/bwmarrin/discordgo"
@@ -366,28 +365,12 @@ func main() {
h(s, i)
}
case discordgo.InteractionMessageComponent:
customID := i.MessageComponentData().CustomID
if h, ok := componentHandlers[customID]; ok {
if h, ok := componentHandlers[i.MessageComponentData().CustomID]; ok {
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")
registeredCommands := make([]*discordgo.ApplicationCommand, len(commands))
for i, v := range commands {
@@ -457,16 +440,6 @@ func fetchAndShowFormats(s *discordgo.Session, i *discordgo.InteractionCreate, u
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)

View File

@@ -2,45 +2,11 @@ package main
import (
"fmt"
"log"
"os"
"regexp"
_ "embed"
"encoding/base64"
"github.com/bwmarrin/discordgo"
)
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 loading_emoji = os.Getenv("LOADING_EMOJI")
var urlPattern = regexp.MustCompile(`https?://\S+`)

View File

@@ -19,9 +19,7 @@ func GetFormats(url string) (*FormatOptions, error) {
SkipDownload().
DumpJSON()
ctx, cancel := context.WithTimeout(context.Background(), 2*time.Minute)
defer cancel()
result, err := dl.Run(ctx, url)
result, err := dl.Run(context.TODO(), url)
if err != nil {
return nil, err
}