fix: progress stuck at 0%, container not respected, audio display, Spotify DRM fallback
- Remove --no-progress from yt-dlp args that suppressed all progress output - Add --merge-output-format when FormatString is set (container was ignored for combined formats) - Improve formatLabelForDisplay for audio-only formats missing bitrate (show ID+extension) - Detect DRM errors (Spotify) and fall back to YouTube Music search via ytsearch1:
This commit is contained in:
@@ -65,17 +65,34 @@ func (h *Handler) handleURLInput(ctx context.Context, chatID int64, text string,
|
||||
info, err := h.YtDlp.GetMediaInfo(url)
|
||||
if err != nil {
|
||||
errMsg := err.Error()
|
||||
switch {
|
||||
case strings.Contains(errMsg, "Unsupported URL") || strings.Contains(errMsg, "is not a valid URL"):
|
||||
h.sendText(ctx, chatID, "This URL is not supported.")
|
||||
case strings.Contains(errMsg, "HTTP Error 403") || strings.Contains(errMsg, "cookies"):
|
||||
h.sendText(ctx, chatID, "This content requires authentication (cookies).")
|
||||
case strings.Contains(errMsg, "live"):
|
||||
h.sendText(ctx, chatID, "Cannot download live streams.")
|
||||
default:
|
||||
h.sendText(ctx, chatID, fmt.Sprintf("Error: %s", errMsg))
|
||||
|
||||
// DRM content (Spotify, etc.): fall back to YouTube search
|
||||
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))
|
||||
return
|
||||
}
|
||||
h.sendText(ctx, chatID, fmt.Sprintf("This content is DRM protected. Found on YouTube: %s", ytTitle))
|
||||
info, err = h.YtDlp.GetMediaInfo(youtubeURL)
|
||||
if err != nil {
|
||||
h.sendText(ctx, chatID, fmt.Sprintf("YouTube fallback failed: %s", err.Error()))
|
||||
return
|
||||
}
|
||||
url = youtubeURL
|
||||
} else {
|
||||
switch {
|
||||
case strings.Contains(errMsg, "Unsupported URL") || strings.Contains(errMsg, "is not a valid URL"):
|
||||
h.sendText(ctx, chatID, "This URL is not supported.")
|
||||
case strings.Contains(errMsg, "HTTP Error 403") || strings.Contains(errMsg, "cookies"):
|
||||
h.sendText(ctx, chatID, "This content requires authentication (cookies).")
|
||||
case strings.Contains(errMsg, "live"):
|
||||
h.sendText(ctx, chatID, "Cannot download live streams.")
|
||||
default:
|
||||
h.sendText(ctx, chatID, fmt.Sprintf("Error: %s", errMsg))
|
||||
}
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
if info.IsPlaylist {
|
||||
@@ -571,6 +588,17 @@ func formatLabelForDisplay(f domain.Format) string {
|
||||
}
|
||||
return label
|
||||
}
|
||||
// Audio-only with no bitrate: show format ID + extension
|
||||
if f.IsAudioOnly {
|
||||
label := f.ID
|
||||
if f.Extension != "" {
|
||||
label += " (" + f.Extension + ")"
|
||||
}
|
||||
if f.Filesize > 0 {
|
||||
label += fmt.Sprintf(" (%s)", formatBytes(f.Filesize))
|
||||
}
|
||||
return label
|
||||
}
|
||||
return f.ID
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user