Files
uptodownbot/internal/handler/keyboard.go
db123 b11b5649a5
All checks were successful
CI / build (push) Successful in 52s
feat: add auto-select from preferences and type picker
- Add MediaTypeAsk (0) as the default, mapping old video_audio to Ask
- Show Video/Audio/Ask type picker when no default media type is set
- Auto-select matching format and skip picker when defaults are configured
- Add autoSelectVideoFormat / autoSelectAudioFormat helpers with closest-match
- Add buildFilteredFormatList for type-filtered format lists
- Add Media Type setting in settings UI (Ask/Video/Audio)
- Add --merge-output-format mp4 for video downloads via yt-dlp
- Fix formatLabelForDisplay to show Height fallback and Extension
- Add cookies volume mount to docker-compose.yml
- Document cookies setup and new features in README
2026-06-28 11:28:53 +03:30

110 lines
3.2 KiB
Go

package handler
import (
"fmt"
"github.com/go-telegram/bot/models"
)
func mainKeyboard() models.InlineKeyboardMarkup {
return models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{
{
{Text: "Download", CallbackData: "download"},
{Text: "Search", CallbackData: "search"},
{Text: "Settings", CallbackData: "settings"},
},
{
{Text: "History", CallbackData: "history"},
{Text: "Help", CallbackData: "help"},
},
},
}
}
func backKeyboard() models.InlineKeyboardMarkup {
return models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{
{{Text: "Back to Menu", CallbackData: "back_menu"}},
},
}
}
func settingsBackKeyboard() models.InlineKeyboardMarkup {
return models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{
{{Text: "Back to Settings", CallbackData: "back_settings"}},
},
}
}
// formatKeyboard builds a 2-column inline keyboard from labels with corresponding callback data values.
// The prefix is prepended to each data value to form the full callback data.
func formatKeyboard(prefix string, labels, data []string) models.InlineKeyboardMarkup {
rows := [][]models.InlineKeyboardButton{}
row := []models.InlineKeyboardButton{}
for i, label := range labels {
cb := prefix + data[i]
row = append(row, models.InlineKeyboardButton{Text: label, CallbackData: cb})
if len(row) == 2 || i == len(labels)-1 {
rows = append(rows, row)
row = nil
}
}
rows = append(rows, []models.InlineKeyboardButton{
{Text: "Back", CallbackData: "back_step"},
{Text: "Cancel", CallbackData: "cancel_dl"},
})
return models.InlineKeyboardMarkup{InlineKeyboard: rows}
}
// languageKeyboard builds a keyboard from available languages.
func languageKeyboard(languages []string) models.InlineKeyboardMarkup {
return formatKeyboard("lang_", languages, languages)
}
// progressKeyboard builds the progress display with a dummy button and cancel.
func progressKeyboard(pct float64, speed, eta string) models.InlineKeyboardMarkup {
progressText := fmt.Sprintf("%.1f%%", pct)
if speed != "" {
progressText += fmt.Sprintf(" | %s", speed)
}
if eta != "" {
progressText += fmt.Sprintf(" | ETA %s", eta)
}
return models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{
{{Text: progressText, CallbackData: "noop"}},
{{Text: "Cancel", CallbackData: "cancel_dl"}},
},
}
}
// mediaTypeKeyboard builds the initial type picker (Video/Audio/Ask).
func mediaTypeKeyboard() models.InlineKeyboardMarkup {
return models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{
{
{Text: "Video", CallbackData: "type_video"},
{Text: "Audio", CallbackData: "type_audio"},
{Text: "Ask", CallbackData: "type_ask"},
},
{
{Text: "Cancel", CallbackData: "cancel_dl"},
},
},
}
}
// deleteConfirmKeyboard builds the confirmation prompt for account deletion.
func deleteConfirmKeyboard(userID int64) models.InlineKeyboardMarkup {
return models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{
{
{Text: "Yes, delete everything", CallbackData: fmt.Sprintf("delaccount_%d", userID), Style: "danger"},
{Text: "Cancel", CallbackData: "back_settings"},
},
},
}
}