format final video download message
This commit is contained in:
@@ -8,7 +8,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// startAsyncDownload initiates a download in a goroutine and handles progress updates
|
// 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)
|
progressChan := make(chan ProgressUpdate, 1)
|
||||||
resultChan := make(chan DownloadResult, 1)
|
resultChan := make(chan DownloadResult, 1)
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, ur
|
|||||||
Content: ptr("✅ Success"),
|
Content: ptr("✅ Success"),
|
||||||
})
|
})
|
||||||
_, err = s.FollowupMessageCreate(i.Interaction, false, &discordgo.WebhookParams{
|
_, 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 {
|
if err != nil {
|
||||||
log.Printf("Error updating interaction: %v", err)
|
log.Printf("Error updating interaction: %v", err)
|
||||||
|
|||||||
33
app/main.go
33
app/main.go
@@ -93,6 +93,9 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get requester user ID
|
||||||
|
state.Requester = i.User.ID
|
||||||
|
|
||||||
// Get selected video format
|
// Get selected video format
|
||||||
selectedValues := i.MessageComponentData().Values
|
selectedValues := i.MessageComponentData().Values
|
||||||
if len(selectedValues) == 0 {
|
if len(selectedValues) == 0 {
|
||||||
@@ -106,8 +109,19 @@ func main() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store selected video format ID
|
// Store selected video format ID and name
|
||||||
state.VideoFormatID = selectedValues[0]
|
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)
|
setInteractionState(i.Interaction.Token, state)
|
||||||
|
|
||||||
// Build audio format options
|
// Build audio format options
|
||||||
@@ -240,8 +254,21 @@ func main() {
|
|||||||
audioFormatID = selectedValues[0]
|
audioFormatID = selectedValues[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store selected audio format ID
|
// Store selected audio format ID and name
|
||||||
state.AudioFormatID = audioFormatID
|
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 := ""
|
response := ""
|
||||||
if state.URL != "" {
|
if state.URL != "" {
|
||||||
@@ -253,7 +280,7 @@ func main() {
|
|||||||
go func() {
|
go func() {
|
||||||
// Small delay to ensure response is sent first
|
// Small delay to ensure response is sent first
|
||||||
time.Sleep(100 * time.Millisecond)
|
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
|
// Clean up state after starting download
|
||||||
|
|||||||
11
app/types.go
11
app/types.go
@@ -36,10 +36,13 @@ type ProgressUpdate struct {
|
|||||||
|
|
||||||
// InteractionState holds the state for a specific interaction
|
// InteractionState holds the state for a specific interaction
|
||||||
type InteractionState struct {
|
type InteractionState struct {
|
||||||
URL string
|
Requester string
|
||||||
FormatOptions *FormatOptions
|
URL string
|
||||||
VideoFormatID string
|
FormatOptions *FormatOptions
|
||||||
AudioFormatID string
|
VideoFormatID string
|
||||||
|
VideoFormatName string
|
||||||
|
AudioFormatID string
|
||||||
|
AudioFormatName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadResult represents the result of an async download operation
|
// DownloadResult represents the result of an async download operation
|
||||||
|
|||||||
Reference in New Issue
Block a user