Skip to content

Commit 9ce9941

Browse files
committed
fix: YouTube soft-404 detection was matching all videos
The Contains(" - YouTube") check matched every valid video since YouTube's standard title format is "Title - YouTube". Changed to only match the exact title "YouTube" which is what unavailable videos actually return. Also strip the " - YouTube" suffix for cleaner display titles.
1 parent 08371d8 commit 9ce9941

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

internal/handler/preview_youtube.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,16 @@ func (h *Handler) GetYouTubePreview(targetURL string) (map[string]string, error)
2424
return nil, fmt.Errorf("status 404")
2525
}
2626

27-
// Make check more permissible using Contains
28-
if strings.Contains(title, " - YouTube") || title == "YouTube" {
29-
// Special handling for caller to know it's a 404
27+
// Detect YouTube "soft 404": unavailable videos return a generic title
28+
// like "YouTube" without the normal "Video Title - YouTube" format.
29+
if title == "YouTube" {
3030
return nil, fmt.Errorf("status 404")
3131
}
3232

33+
// Strip the standard " - YouTube" suffix from the title
34+
title = strings.TrimSuffix(title, " - YouTube")
35+
meta["title"] = title
36+
3337
meta["type"] = "video"
3438

3539
return meta, nil

0 commit comments

Comments
 (0)