chore: added youtube support to homepage
4983e3a7
1 file(s) · +19 −1
| 14 | 14 | extractPostDate, |
|
| 15 | 15 | sanitizeFeedData, |
|
| 16 | 16 | sanitizePostData, |
|
| 17 | + | isYouTubeUrl, |
|
| 18 | + | convertYouTubeUrlToFeed, |
|
| 17 | 19 | } from "@/lib/feed-operations"; |
|
| 18 | 20 | import { parseOPML } from "@/lib/opml"; |
|
| 19 | 21 | import { |
|
| 209 | 211 | let feedUrl = urlInput; |
|
| 210 | 212 | let xmlData: string | null = null; |
|
| 211 | 213 | ||
| 212 | - | if (!looksLikeFeedUrl(urlInput)) { |
|
| 214 | + | // Check if it's a YouTube URL and convert it |
|
| 215 | + | if (isYouTubeUrl(urlInput)) { |
|
| 216 | + | setErrorMessage("Detecting YouTube channel..."); |
|
| 217 | + | const youtubeFeedUrl = await convertYouTubeUrlToFeed(urlInput); |
|
| 218 | + | ||
| 219 | + | if (!youtubeFeedUrl) { |
|
| 220 | + | setErrorMessage( |
|
| 221 | + | "Could not extract YouTube channel ID. Please try a direct channel URL.", |
|
| 222 | + | ); |
|
| 223 | + | setIsAddingFeed(false); |
|
| 224 | + | return; |
|
| 225 | + | } |
|
| 226 | + | ||
| 227 | + | feedUrl = youtubeFeedUrl; |
|
| 228 | + | xmlData = await fetchFeedWithFallback(feedUrl); |
|
| 229 | + | } else if (!looksLikeFeedUrl(urlInput)) { |
|
| 230 | + | setErrorMessage("Discovering RSS feed..."); |
|
| 213 | 231 | const discovered = await discoverFeed(urlInput); |
|
| 214 | 232 | ||
| 215 | 233 | if (!discovered) { |
|