From 890a0dd5c99df6427126dea8ceff1f62e5ec69dd Mon Sep 17 00:00:00 2001 From: William P Date: Thu, 5 Mar 2026 19:35:13 -0500 Subject: [PATCH] format final video download message --- app/download.go | 4 ++-- app/main.go | 33 ++++++++++++++++++++++++++++++--- app/types.go | 11 +++++++---- 3 files changed, 39 insertions(+), 9 deletions(-) diff --git a/app/download.go b/app/download.go index e0468e9..ea6c206 100644 --- a/app/download.go +++ b/app/download.go @@ -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) @@ -89,7 +89,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, ur Content: ptr("✅ Success"), }) _, 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) diff --git a/app/main.go b/app/main.go index 1dc96a7..69fe5ca 100644 --- a/app/main.go +++ b/app/main.go @@ -93,6 +93,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 +109,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 @@ -240,8 +254,21 @@ 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 != "" { @@ -253,7 +280,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, 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 diff --git a/app/types.go b/app/types.go index 7b1ce2b..9c3151d 100644 --- a/app/types.go +++ b/app/types.go @@ -36,10 +36,13 @@ type ProgressUpdate struct { // 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