9 Commits

Author SHA1 Message Date
williamp e3b5542b78 add /version command
Build and Push Docker Image / build-and-push (push) Successful in 5m5s
Build and Push Docker Image / deploy-on-green (push) Successful in 6s
2026-03-07 21:14:31 -05:00
williamp aaf3338797 re-introduce context menu command 2026-03-07 21:05:23 -05:00
williamp 8f2bda0b52 chore(actions): change buildkitd url
Build and Push Docker Image / build-and-push (push) Successful in 7m19s
Build and Push Docker Image / deploy-on-green (push) Successful in 6s
2026-03-07 18:56:26 -05:00
williamp 91f2eb39cb chore(actions): change buildkitd url
Build and Push Docker Image / build-and-push (push) Failing after 26s
Build and Push Docker Image / deploy-on-green (push) Has been skipped
2026-03-07 18:35:56 -05:00
williamp 82b867ae9c Merge pull request 'chore(deps): update docker/setup-buildx-action action to v4' (#46) from renovate/docker-setup-buildx-action-4.x into master
Build and Push Docker Image / build-and-push (push) Successful in 7m51s
Build and Push Docker Image / deploy-on-green (push) Successful in 1m18s
Reviewed-on: #46
2026-03-07 15:19:11 +00:00
williamp ebb6c11d49 Merge pull request 'chore(deps): update docker/build-push-action action to v7' (#45) from renovate/docker-build-push-action-7.x into master
Build and Push Docker Image / deploy-on-green (push) Has been cancelled
Build and Push Docker Image / build-and-push (push) Has been cancelled
Reviewed-on: #45
2026-03-07 15:19:02 +00:00
renovate-bot d4beb62fdd chore(deps): update docker/setup-buildx-action action to v4
Build only (for PRs) / build-only (pull_request) Successful in 10s
2026-03-07 03:01:29 +00:00
renovate-bot 13d65ef6ce chore(deps): update docker/build-push-action action to v7
Build only (for PRs) / build-only (pull_request) Successful in 10s
2026-03-07 03:01:17 +00:00
williamp 4347bf733c fix flake.nix 2026-03-06 20:32:37 -05:00
5 changed files with 226 additions and 13 deletions
+1 -1
View File
@@ -26,7 +26,7 @@ jobs:
uses: docker/setup-buildx-action@v4 uses: docker/setup-buildx-action@v4
with: with:
driver: remote driver: remote
endpoint: 'tcp://buildkitd:1234' endpoint: 'tcp://buildkitd.gitea-runner.svc.cluster.local:1234'
# Log in to the Gitea container registry # Log in to the Gitea container registry
- name: Log in to Gitea Container Registry - name: Log in to Gitea Container Registry
+3 -3
View File
@@ -21,14 +21,14 @@ jobs:
# Set up Docker Buildx for building the image # Set up Docker Buildx for building the image
- name: Set up Docker Buildx - name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3 uses: docker/setup-buildx-action@v4
with: with:
driver: remote driver: remote
endpoint: 'tcp://buildkitd:1234' endpoint: 'tcp://buildkitd.gitea-runner.svc.cluster.local:1234'
# Build the Docker image # Build the Docker image
- name: Build Docker Image - name: Build Docker Image
uses: docker/build-push-action@v6 uses: docker/build-push-action@v7
with: with:
context: . # Build context (current directory) context: . # Build context (current directory)
file: ./Dockerfile # Path to Dockerfile file: ./Dockerfile # Path to Dockerfile
+214 -6
View File
@@ -53,6 +53,24 @@ func main() {
}, },
}, },
}, },
{
Name: "version",
Description: "Show application version",
DefaultMemberPermissions: &defaultMemberPermissions,
Contexts: &[]discordgo.InteractionContextType{interactionPrivateChannel},
},
{
Name: "download video",
Type: discordgo.MessageApplicationCommand,
IntegrationTypes: &[]discordgo.ApplicationIntegrationType{
discordgo.ApplicationIntegrationUserInstall,
},
Contexts: &[]discordgo.InteractionContextType{
discordgo.InteractionContextBotDM,
discordgo.InteractionContextPrivateChannel,
},
},
} }
var componentHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){ var componentHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
@@ -480,6 +498,202 @@ func main() {
} }
}() }()
}, },
"download video": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
data := i.ApplicationCommandData()
targetMsg, ok := data.Resolved.Messages[data.TargetID]
if !ok || targetMsg == nil {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Error: Could not find the target message",
Flags: discordgo.MessageFlagsEphemeral,
},
})
return
}
messageContent := targetMsg.Content
var url string
url = extractURLFromString(messageContent)
if url == "" {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "Error: No URL provided",
Flags: discordgo.MessageFlagsEphemeral,
},
})
return
}
// Send initial "fetching formats" response
err := s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: fmt.Sprintf("%s Fetching available formats...", loading_emoji),
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
log.Printf("Error: %v", err)
return
}
// Fetch formats asynchronously
go func() {
formatOptions, err := GetFormats(url)
if err != nil {
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: ptr("❌ Error fetching formats: " + err.Error()),
})
if err != nil {
log.Printf("Error updating interaction: %v", err)
}
return
}
// Sort video formats: highest resolution first, then by bitrate
sort.Slice(formatOptions.VideoOptions, func(i, j int) bool {
// Compare by height (descending)
heightI := 0
if formatOptions.VideoOptions[i].Height != nil {
heightI = *formatOptions.VideoOptions[i].Height
}
heightJ := 0
if formatOptions.VideoOptions[j].Height != nil {
heightJ = *formatOptions.VideoOptions[j].Height
}
if heightI != heightJ {
return heightI > heightJ
}
// If heights are equal, compare by TBR (descending)
tbrI := 0.0
if formatOptions.VideoOptions[i].TBR != nil {
tbrI = *formatOptions.VideoOptions[i].TBR
}
tbrJ := 0.0
if formatOptions.VideoOptions[j].TBR != nil {
tbrJ = *formatOptions.VideoOptions[j].TBR
}
return tbrI > tbrJ
})
// Sort audio formats: highest bitrate first
sort.Slice(formatOptions.AudioOptions, func(i, j int) bool {
tbrI := 0.0
if formatOptions.AudioOptions[i].TBR != nil {
tbrI = *formatOptions.AudioOptions[i].TBR
}
tbrJ := 0.0
if formatOptions.AudioOptions[j].TBR != nil {
tbrJ = *formatOptions.AudioOptions[j].TBR
}
return tbrI > tbrJ
})
// Build video format options for Discord select menu
videoMenuOptions := []discordgo.SelectMenuOption{}
for _, vOpt := range formatOptions.VideoOptions {
label := fmt.Sprintf("%s (%s", vOpt.Resolution, vOpt.Ext)
if vOpt.TBR != nil {
label += fmt.Sprintf(", %.0fkbps", *vOpt.TBR)
}
label += ")"
// Discord has a 100 char limit on labels
if len(label) > 100 {
label = label[:97] + "..."
}
videoMenuOptions = append(videoMenuOptions, discordgo.SelectMenuOption{
Label: label,
Value: vOpt.FormatID,
})
// Discord has a limit of 25 options per select menu
if len(videoMenuOptions) >= 25 {
break
}
}
// Build audio format options for Discord select menu
audioMenuOptions := []discordgo.SelectMenuOption{}
for _, aOpt := range formatOptions.AudioOptions {
label := aOpt.Format
if aOpt.Language != nil {
label += fmt.Sprintf(" [%s]", *aOpt.Language)
}
if aOpt.TBR != nil {
label += fmt.Sprintf(" (%.0fkbps)", *aOpt.TBR)
}
// Discord has a 100 char limit on labels
if len(label) > 100 {
label = label[:97] + "..."
}
audioMenuOptions = append(audioMenuOptions, discordgo.SelectMenuOption{
Label: label,
Value: aOpt.FormatID,
})
// Discord has a limit of 25 options per select menu
if len(audioMenuOptions) >= 25 {
break
}
}
// Store format options in interaction state
setInteractionState(i.Interaction.Token, &InteractionState{
URL: url,
FormatOptions: formatOptions,
})
// Update message with format selection menus
_, err = s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{
Content: ptr("Select a video format:"),
Components: &[]discordgo.MessageComponent{
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
discordgo.SelectMenu{
CustomID: "video_select",
Placeholder: "Choose a video format...",
MaxValues: 1,
Options: videoMenuOptions,
},
},
},
discordgo.ActionsRow{
Components: []discordgo.MessageComponent{
discordgo.SelectMenu{
CustomID: "audio_select",
Placeholder: "Choose an audio format...",
MaxValues: 1,
Disabled: true,
Options: audioMenuOptions,
},
},
},
},
})
if err != nil {
log.Printf("Error updating interaction: %v", err)
}
}()
},
"version": func(s *discordgo.Session, i *discordgo.InteractionCreate) {
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: "[yt-dlp-bot](https://git.dubyatp.xyz/williamp/yt-dlp-bot) by dubyatp",
Flags: discordgo.MessageFlagsEphemeral,
},
})
},
} }
s.AddHandler(func(s *discordgo.Session, i *discordgo.InteractionCreate) { s.AddHandler(func(s *discordgo.Session, i *discordgo.InteractionCreate) {
@@ -488,13 +702,7 @@ func main() {
if h, ok := commandHandlers[i.ApplicationCommandData().Name]; ok { if h, ok := commandHandlers[i.ApplicationCommandData().Name]; ok {
h(s, i) h(s, i)
} }
if h, ok := componentHandlers[i.ApplicationCommandData().Name]; ok {
h(s, i)
}
case discordgo.InteractionMessageComponent: case discordgo.InteractionMessageComponent:
if h, ok := commandHandlers[i.MessageComponentData().CustomID]; ok {
h(s, i)
}
if h, ok := componentHandlers[i.MessageComponentData().CustomID]; ok { if h, ok := componentHandlers[i.MessageComponentData().CustomID]; ok {
h(s, i) h(s, i)
} }
+8
View File
@@ -3,10 +3,18 @@ package main
import ( import (
"fmt" "fmt"
"os" "os"
"regexp"
) )
var loading_emoji = os.Getenv("LOADING_EMOJI") var loading_emoji = os.Getenv("LOADING_EMOJI")
func extractURLFromString(in_url string) string {
url_pattern := regexp.MustCompile(`https?://\S+`)
var match = url_pattern.Find([]byte(in_url))
return string(match)
}
// Helper function to create string pointer // Helper function to create string pointer
func ptr(s string) *string { func ptr(s string) *string {
return &s return &s
-3
View File
@@ -46,11 +46,8 @@
.venv/bin/pip install -r ./app/requirements.txt .venv/bin/pip install -r ./app/requirements.txt
source .venv/bin/activate source .venv/bin/activate
fi fi
<<<<<<< HEAD
=======
export YTDLP_BIN=${pkgs.lib.getExe pkgs.yt-dlp} export YTDLP_BIN=${pkgs.lib.getExe pkgs.yt-dlp}
>>>>>>> v1-refactor
''; '';
}; };
}); });