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:
@@ -70,7 +70,15 @@ func (h *Handler) handleURLInput(ctx context.Context, chatID int64, text string,
|
||||
if strings.Contains(errMsg, "DRM") {
|
||||
youtubeURL, ytTitle, searchErr := h.YtDlp.SearchYoutube(text)
|
||||
if searchErr != nil {
|
||||
h.sendText(ctx, chatID, fmt.Sprintf("This content is DRM protected and no YouTube alternative was found: %s", errMsg))
|
||||
kb := models.InlineKeyboardMarkup{
|
||||
InlineKeyboard: [][]models.InlineKeyboardButton{
|
||||
{{Text: "Search on YouTube", CallbackData: "drm_search"}},
|
||||
{{Text: "Cancel", CallbackData: "pending_cancel"}},
|
||||
},
|
||||
}
|
||||
h.Bot.SendMessage(ctx, &tgbot.SendMessageParams{
|
||||
ChatID: chatID, Text: "This content is DRM protected and no YouTube alternative was found automatically. Try searching by name:", ReplyMarkup: kb,
|
||||
})
|
||||
return
|
||||
}
|
||||
h.sendText(ctx, chatID, fmt.Sprintf("This content is DRM protected. Found on YouTube: %s", ytTitle))
|
||||
|
||||
@@ -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{
|
||||
|
||||
Reference in New Issue
Block a user