Files
cuz-guide/3.youtube-service.md
2026-11-02 19:55:04 +01:00

26 lines
1.5 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# YouTube Notification Service – Overview
You need to use an [external Website like this one](https://channelsurfer.tv/tools/youtube-rss-feed/) to get the RSS feed ID for a channel.
## 1. Order of events
1. **Connect to the database:** Establish a connection to the database containing the subscribed YouTube channels.
2. **Retrieve subscriptions:** Fetch all subscribed YouTube RSS feed URLs from the database.
3. **Fetch RSS feeds:** Use `feedparser` to query each subscribed feed.
4. **Check for updates:** Compare the latest feed entries against the last known entry stored in the database.
5. **Send notifications:** If a new video is found, send its information (`title`, `body`, `link`, `timestamp`) to the `backend-api` using a POST request.
6. **Update database:** After successfully sending the notification, update the stored latest video information to prevent duplicate notifications.
7. **Close database connection:** Close the database connection once all subscriptions have been processed.
## 2. Dependencies
- **feedparser:** Parse YouTube RSS feeds and extract video information.
- **requests:** Send HTTP POST requests to the `backend-api`.
- **Database driver:** Connect to and query the database.
## 3. Things to improve once it works
- Handle unavailable RSS feeds without stopping the entire service.
- Handle failed API requests so notifications aren't accidentally marked as processed.
- Log errors and processing information using Python's `logging` module. Use a LOG_LEVEL to set it to either debugging or production(info)