feat: add in-memory media info cache and YouTube search feature
- Add in-memory LRU cache (200 entries, 30 min TTL) to yt-dlp Client for GetMediaInfo and GetPlaylistInfo results, avoiding redundant yt-dlp calls for the same URL within a session - Add YouTube (/search) and YouTube Music (/music) search with paginated results (5 per page), user selects a result to start the download flow - Add SearchState type, new search.go handler, search results keyboard with < > navigation and New Search button - Add Search button to main menu keyboard - Update help text with new commands
This commit is contained in:
@@ -23,8 +23,9 @@ import (
|
||||
type PendingKind string
|
||||
|
||||
const (
|
||||
PendingURL PendingKind = "url"
|
||||
PendingDRM PendingKind = "drm"
|
||||
PendingURL PendingKind = "url"
|
||||
PendingDRM PendingKind = "drm"
|
||||
PendingSearch PendingKind = "search"
|
||||
)
|
||||
|
||||
type PendingInput struct {
|
||||
@@ -185,6 +186,10 @@ func (h *Handler) routeCommand(ctx context.Context, msg *models.Message, userID
|
||||
h.handleHistory(ctx, msg, userID)
|
||||
case "/download":
|
||||
h.handleDownloadCommand(ctx, msg, userID)
|
||||
case "/search":
|
||||
h.handleSearchCommand(ctx, msg, userID)
|
||||
case "/music":
|
||||
h.handleMusicSearchCommand(ctx, msg, userID)
|
||||
default:
|
||||
h.sendText(ctx, msg.Chat.ID, "Unknown command")
|
||||
}
|
||||
@@ -226,6 +231,9 @@ func (h *Handler) HandleCallback(ctx context.Context, cb *models.CallbackQuery)
|
||||
case data == "download":
|
||||
h.handleDownloadPrompt(ctx, chatID, msgID, cb.ID, userID)
|
||||
h.answerCb(ctx, cb.ID)
|
||||
case data == "search":
|
||||
h.promptForInput(ctx, chatID, msgID, userID, PendingSearch, "Enter a YouTube search query:", map[string]string{"source": "youtube"})
|
||||
h.answerCb(ctx, cb.ID)
|
||||
case data == "settings":
|
||||
h.settingsCallback(ctx, chatID, msgID, cb.ID, userID)
|
||||
case data == "help":
|
||||
@@ -280,6 +288,8 @@ func (h *Handler) routePrefixedCallback(ctx context.Context, chatID int64, msgID
|
||||
h.handleSettingsSet(ctx, chatID, msgID, userID, data[13:])
|
||||
case strings.HasPrefix(data, "settings_"):
|
||||
h.handleSettingsSelection(ctx, chatID, msgID, userID, data[9:])
|
||||
case strings.HasPrefix(data, "search_"):
|
||||
h.handleSearchCallback(ctx, chatID, msgID, userID, data[7:])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,6 +312,12 @@ func (h *Handler) processPendingInput(ctx context.Context, msg *models.Message,
|
||||
h.handleURLInput(ctx, msg.Chat.ID, text, userID)
|
||||
case PendingDRM:
|
||||
h.handleDRMSearch(ctx, msg.Chat.ID, text, userID)
|
||||
case PendingSearch:
|
||||
source := "youtube"
|
||||
if pi.Data != nil && pi.Data["source"] != "" {
|
||||
source = pi.Data["source"]
|
||||
}
|
||||
h.handleSearchQuery(ctx, msg.Chat.ID, text, userID, source)
|
||||
default:
|
||||
h.sendText(ctx, msg.Chat.ID, "Unknown input type")
|
||||
}
|
||||
@@ -457,6 +473,8 @@ func (h *Handler) handleHelp(ctx context.Context, msg *models.Message) {
|
||||
/settings - Open settings
|
||||
/help - Show this help
|
||||
/history - View download history
|
||||
/search - Search YouTube
|
||||
/music - Search YouTube Music
|
||||
|
||||
Just send me a URL to start downloading.`
|
||||
h.sendText(ctx, msg.Chat.ID, text)
|
||||
|
||||
Reference in New Issue
Block a user