Compare commits
3 Commits
481c8d9bb6
...
890a0dd5c9
| Author | SHA1 | Date | |
|---|---|---|---|
|
890a0dd5c9
|
|||
|
6fd6160edf
|
|||
|
43c2fa2f91
|
+8
-5
@@ -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)
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, ur
|
|||||||
// Handle progress and results asynchronously
|
// Handle progress and results asynchronously
|
||||||
go func() {
|
go func() {
|
||||||
_, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
_, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
||||||
Content: ptr("⏬ downloading: starting..."),
|
Content: ptr("<a:loading:1479131733910618153> downloading: starting..."),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Error updating interaction: %v", err)
|
log.Printf("Error updating interaction: %v", err)
|
||||||
@@ -65,7 +65,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, ur
|
|||||||
|
|
||||||
var content string
|
var content string
|
||||||
if prog.Phase == "post-processing" {
|
if prog.Phase == "post-processing" {
|
||||||
content = "⚙️ post-processing"
|
content = "<a:loading:1479131733910618153> post-processing"
|
||||||
} else {
|
} else {
|
||||||
var progressStr string
|
var progressStr string
|
||||||
if prog.DownloadedBytes > 0 {
|
if prog.DownloadedBytes > 0 {
|
||||||
@@ -73,7 +73,7 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, ur
|
|||||||
} else {
|
} else {
|
||||||
progressStr = "starting..."
|
progressStr = "starting..."
|
||||||
}
|
}
|
||||||
content = fmt.Sprintf("Downloading Video: %s", progressStr)
|
content = fmt.Sprintf("<a:loading:1479131733910618153> Downloading Video: %s", progressStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
_, err := s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
||||||
@@ -85,8 +85,11 @@ func startAsyncDownload(s *discordgo.Session, i *discordgo.InteractionCreate, ur
|
|||||||
|
|
||||||
case result := <-resultChan:
|
case result := <-resultChan:
|
||||||
if result.Success {
|
if result.Success {
|
||||||
|
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
|
||||||
|
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)
|
||||||
|
|||||||
+30
-3
@@ -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
|
||||||
|
|||||||
@@ -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 {
|
||||||
|
Requester string
|
||||||
URL string
|
URL string
|
||||||
FormatOptions *FormatOptions
|
FormatOptions *FormatOptions
|
||||||
VideoFormatID string
|
VideoFormatID string
|
||||||
|
VideoFormatName string
|
||||||
AudioFormatID string
|
AudioFormatID string
|
||||||
|
AudioFormatName string
|
||||||
}
|
}
|
||||||
|
|
||||||
// DownloadResult represents the result of an async download operation
|
// DownloadResult represents the result of an async download operation
|
||||||
|
|||||||
Generated
+3
-3
@@ -2,11 +2,11 @@
|
|||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1770537093,
|
"lastModified": 1772674223,
|
||||||
"narHash": "sha256-pF1quXG5wsgtyuPOHcLfYg/ft/QMr8NnX0i6tW2187s=",
|
"narHash": "sha256-/suKbHSaSmuC9UY7G0VRQ3aO+QKqxAQPQ19wG7QNkF8=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "fef9403a3e4d31b0a23f0bacebbec52c248fbb51",
|
"rev": "66d9241e3dc2296726dc522e62dbfe89c7b449f3",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|||||||
Reference in New Issue
Block a user