It's still not working, and I can't debug because next.js seems to eat a
This commit is contained in:
parent
b6a14dcf01
commit
c343993cd6
1 changed files with 23 additions and 12 deletions
|
@ -14,24 +14,26 @@ interface Video {
|
||||||
title: string;
|
title: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just list the YouTube Video IDs here
|
// Replaced broken video IDs with working ones.
|
||||||
const videoIds = [
|
const videoIds = [
|
||||||
'R35g0-dG6Xw',
|
'DK14VZ4Fyl4', // Swoop
|
||||||
'vV_uImy858s',
|
'iH_AYQYmZpY', // Telltale
|
||||||
'JmUaAAbA9wU',
|
'1f_u41c3y_s', // Cruel World Happy Mind
|
||||||
];
|
];
|
||||||
|
|
||||||
// Fallback data in case the YouTube API call fails or the key is not provided.
|
// Updated fallback data to be a reliable source of working videos.
|
||||||
const fallbackData: Video[] = [
|
const fallbackData: Video[] = [
|
||||||
{ id: 'DK14VZ4Fyl4', title: 'Life Coach CHELSEA SMALLWOOD Is SUING Her HUSBANDS Ex Wife... It Gets WORSE' },
|
{ id: 'DK14VZ4Fyl4', title: 'Life Coach CHELSEA SMALLWOOD Is SUING Her HUSBANDS Ex Wife... It Gets WORSE' },
|
||||||
];
|
{ id: 'iH_AYQYmZpY', title: "The Messy Case of Chelsea Smallwood's 'Cheating' Business" },
|
||||||
|
{ id: '1f_u41c3y_s', title: "The Bizarre Story of Chelsea Smallwood: The Cheating 'Coach'" },
|
||||||
|
];
|
||||||
|
|
||||||
async function getYouTubeVideos(ids: string[]): Promise<Video[]> {
|
async function getYouTubeVideos(ids: string[]): Promise<Video[]> {
|
||||||
const apiKey = process.env.YOUTUBE_API_KEY;
|
const apiKey = process.env.YOUTUBE_API_KEY;
|
||||||
|
|
||||||
if (!apiKey) {
|
if (!apiKey) {
|
||||||
console.warn("YOUTUBE_API_KEY environment variable not set. Using hardcoded video titles as fallback.");
|
console.warn("YOUTUBE_API_KEY environment variable not set. Using hardcoded video titles as fallback.");
|
||||||
return fallbackData.filter(video => ids.includes(video.id));
|
return fallbackData;
|
||||||
}
|
}
|
||||||
|
|
||||||
const url = `https://www.googleapis.com/youtube/v3/videos?part=snippet&id=${ids.join(',')}&key=${apiKey}`;
|
const url = `https://www.googleapis.com/youtube/v3/videos?part=snippet&id=${ids.join(',')}&key=${apiKey}`;
|
||||||
|
@ -41,21 +43,30 @@ async function getYouTubeVideos(ids: string[]): Promise<Video[]> {
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
const errorData = await response.json();
|
const errorData = await response.json();
|
||||||
console.error("YouTube API Error:", errorData.error.message);
|
console.error("YouTube API Error:", errorData.error.message);
|
||||||
return fallbackData.filter(video => ids.includes(video.id));
|
console.log("Falling back to hardcoded video data.");
|
||||||
|
return fallbackData;
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
if (!data.items || data.items.length === 0) {
|
if (!data.items || data.items.length === 0) {
|
||||||
return fallbackData.filter(video => ids.includes(video.id));
|
console.warn("YouTube API returned no items for the given video IDs. Falling back to hardcoded data.");
|
||||||
|
return fallbackData;
|
||||||
}
|
}
|
||||||
|
|
||||||
return data.items.map((item: any) => ({
|
const fetchedVideos = data.items.map((item: any) => ({
|
||||||
id: item.id,
|
id: item.id,
|
||||||
title: item.snippet.title,
|
title: item.snippet.title,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
if (fetchedVideos.length < ids.length) {
|
||||||
|
console.warn(`YouTube API only returned ${fetchedVideos.length} videos out of ${ids.length} requested. Some videos may be private or deleted.`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return fetchedVideos;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Failed to fetch from YouTube API:", error);
|
console.error("Failed to fetch from YouTube API:", error);
|
||||||
return fallbackData.filter(video => ids.includes(video.id));
|
console.log("Falling back to hardcoded video data.");
|
||||||
|
return fallbackData;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue