feat: add DRM search-by-name fallback for individual Spotify tracks

When SearchYoutube with the Spotify URL fails for individual tracks,
offer a 'Search on YouTube' button that lets the user enter a search
query (artist/song name) to find the content on YouTube.
This commit is contained in:
2026-06-25 16:10:37 +03:30
parent 0c27822871
commit 8408b17ca0
2 changed files with 25 additions and 1 deletions

View File

@@ -24,6 +24,7 @@ type PendingKind string
const (
PendingURL PendingKind = "url"
PendingDRM PendingKind = "drm"
)
type PendingInput struct {
@@ -235,6 +236,9 @@ func (h *Handler) HandleCallback(ctx context.Context, cb *models.CallbackQuery)
case data == "deleteaccount":
h.deleteAccountPrompt(ctx, chatID, msgID, userID)
h.answerCb(ctx, cb.ID)
case data == "drm_search":
h.promptForInput(ctx, chatID, msgID, userID, PendingDRM, "Enter a search query to find this content on YouTube:", nil)
h.answerCb(ctx, cb.ID)
case data == "pending_cancel":
h.backToMenu(ctx, chatID, msgID, cb.ID, userID)
default:
@@ -296,11 +300,23 @@ func (h *Handler) processPendingInput(ctx context.Context, msg *models.Message,
switch pi.Kind {
case PendingURL:
h.handleURLInput(ctx, msg.Chat.ID, text, userID)
case PendingDRM:
h.handleDRMSearch(ctx, msg.Chat.ID, text, userID)
default:
h.sendText(ctx, msg.Chat.ID, "Unknown input type")
}
}
func (h *Handler) handleDRMSearch(ctx context.Context, chatID int64, text string, userID int64) {
youtubeURL, ytTitle, err := h.YtDlp.SearchYoutube(text)
if err != nil {
h.sendText(ctx, chatID, fmt.Sprintf("No results found for '%s'. Try a different search query or send a YouTube URL directly.", text))
return
}
h.sendText(ctx, chatID, fmt.Sprintf("Found on YouTube: %s", ytTitle))
h.handleURLInput(ctx, chatID, youtubeURL, userID)
}
func (h *Handler) promptForInput(ctx context.Context, chatID int64, msgID int, userID int64, kind PendingKind, prompt string, data map[string]string) {
kb := models.InlineKeyboardMarkup{
InlineKeyboard: [][]models.InlineKeyboardButton{