This API scrapes YouTube videos from specified channels, stores them in Supabase, and provides endpoints to retrieve video data.
http://localhost:3000
Returns a simple response to indicate that the API is running.
Response:
"Ok"Fetches all stored videos from Supabase.
Response:
{
"success": true,
"videos": [
{
"channel": "@AdiHidayatOfficial",
"video_id": "KKU4slX5gwM",
"url": "https://www.youtube.com/watch?v=KKU4slX5gwM",
"created_at": "2024-03-08T12:00:00.000Z"
}
]
}Fetches all videos for a specific YouTube channel.
URL Parameters:
channel(string) - The YouTube channel handle (e.g.,@AdiHidayatOfficial).
Example Request:
curl "http://localhost:3000/api/videos/@AdiHidayatOfficial"Response:
{
"success": true,
"videos": [
{
"channel": "@AdiHidayatOfficial",
"video_id": "KKU4slX5gwM",
"url": "https://www.youtube.com/watch?v=KKU4slX5gwM",
"created_at": "2024-03-08T12:00:00.000Z"
}
]
}Triggers the YouTube scraper to fetch new videos and store them in Supabase.
Response:
{
"success": true,
"message": "Scraper ran successfully!",
"videos": [
{
"channel": "@AdiHidayatOfficial",
"video_id": "NEW_VIDEO_ID",
"url": "https://www.youtube.com/watch?v=NEW_VIDEO_ID",
"created_at": "2024-03-09T12:00:00.000Z"
}
]
}Ensure the following environment variables are set:
PORT=3000
SUPABASE_URL=your_supabase_url
SUPABASE_KEY=your_supabase_key
YOUTUBE_CHANNELS='["@AdiHidayatOfficial", "@AnotherChannel"]'This API is designed to be deployed on Vercel. Ensure your environment variables are configured in the Vercel Dashboard.
To automatically run the scraper, set up a cron job using a scheduler service (e.g., GitHub Actions, Vercel Cron Jobs, or a third-party API monitoring tool like UptimeRobot).
Example Cron Job (Every 6 hours):
0 */6 * * * curl -X GET http://localhost:3000/api/schedule
MIT License