### Install Python Version with uv Source: https://github.com/seoulsky/ytnoti/blob/main/CONTRIBUTING.md Use uv to install a specific Python version for the project. Ensure uv is installed first. ```bash uv python install 3.11 ``` -------------------------------- ### Basic YouTube Notifier Example Source: https://github.com/seoulsky/ytnoti/blob/main/docs/quickstart.md A simple example demonstrating how to initialize YouTubeNotifier, set up an asynchronous listener for new videos, subscribe to a channel, and run the notifier. ```python from pyngrok import ngrok from ytnoti import YouTubeNotifier, Video ngrok.set_auth_token("Your ngrok token here") notifier = YouTubeNotifier() @notifier.upload() async def listener(video: Video): print(f"New video from {video.channel.name}: {video.title}") notifier.subscribe("UCuFFtHWoLl5fauMMD5Ww2jA") # Channel ID of CBC News notifier.run() ``` -------------------------------- ### Install ytnoti Source: https://github.com/seoulsky/ytnoti/blob/main/README.md Install the ytnoti library using pip. This library requires Python 3.11 or higher. ```bash pip install ytnoti ``` -------------------------------- ### Receive Upload Notifications with ngrok Source: https://github.com/seoulsky/ytnoti/blob/main/README.md Example demonstrating how to use ngrok to receive real-time push notifications for new video uploads. Requires an ngrok token. ```python from pyngrok import ngrok from ytnoti import YouTubeNotifier, Video ngrok.set_auth_token("Your ngrok token here") notifier = YouTubeNotifier() @notifier.upload() async def listener(video: Video) -> None: print(f"New video from {video.channel.name}: {video.title}") notifier.subscribe("UCuFFtHWoLl5fauMMD5Ww2jA") # Channel ID of CBC News notifier.run() ``` -------------------------------- ### Pin Python Version with uv Source: https://github.com/seoulsky/ytnoti/blob/main/CONTRIBUTING.md After installing a Python version, pin it to the project using uv. This ensures consistent Python environments. ```bash uv python pin 3.11 ``` -------------------------------- ### Receive Upload Notifications with Custom Domain Source: https://github.com/seoulsky/ytnoti/blob/main/README.md Example showing how to receive real-time push notifications for new video uploads using your own domain as the callback URL. ```python from ytnoti import YouTubeNotifier, Video notifier = YouTubeNotifier(callback_url="https://yourdomain.com") @notifier.upload() async def listener(video: Video) -> None: print(f"New video from {video.channel.name}: {video.title}") notifier.subscribe("UCuFFtHWoLl5fauMMD5Ww2jA") # Channel ID of CBC News notifier.run() ``` -------------------------------- ### Sync Development Dependencies with uv Source: https://github.com/seoulsky/ytnoti/blob/main/CONTRIBUTING.md Install and lock all development dependencies for the project using uv. This command syncs dependencies across all specified groups. ```bash uv sync --all-groups ``` -------------------------------- ### Listen to Upload Events with Specific Channels Source: https://github.com/seoulsky/ytnoti/blob/main/docs/quickstart.md Use the `@notifier.upload()` decorator to trigger a listener function specifically for new video uploads or live stream starts from a given channel ID. ```python @notifier.upload(channel_ids="UCuFFtHWoLl5fauMMD5Ww2jA") async def listener(video: Video): print(f"New video from CBC News: {video.title}") ``` -------------------------------- ### Build Documentation with Sphinx Source: https://github.com/seoulsky/ytnoti/blob/main/CONTRIBUTING.md Build the project documentation using Sphinx. This command generates HTML output in the docs/build directory. ```bash uv run sphinx-build -M html docs docs/build/ ``` -------------------------------- ### Implement Custom Video History Source: https://github.com/seoulsky/ytnoti/blob/main/docs/advanced.md Create and use a custom video history class by inheriting from `VideoHistory` and implementing the `add` and `has` methods. This provides full control over how video history is managed. ```python from ytnoti import YouTubeNotifier, Video, VideoHistory class MyVideoHistory(VideoHistory): async def add(self, video: Video) -> None: pass async def has(self, video: Video) -> bool: return False notifier = YouTubeNotifier(video_history=MyVideoHistory()) ``` -------------------------------- ### Set Ngrok Authentication Token Source: https://github.com/seoulsky/ytnoti/blob/main/docs/quickstart.md Before running the notifier, set your ngrok authentication token. This is required if you are using ngrok to expose your local server. ```python from pyngrok import ngrok ngrok.set_auth_token("Your ngrok token here") ``` -------------------------------- ### Run Ruff Linter with uv Source: https://github.com/seoulsky/ytnoti/blob/main/CONTRIBUTING.md Execute the Ruff linter to check for style and potential errors in the codebase. This command runs ruff check on the current directory. ```bash uv run ruff check . ``` -------------------------------- ### Configure Uvicorn Host and Port Source: https://github.com/seoulsky/ytnoti/blob/main/docs/advanced.md Override the default host and port for the uvicorn server used by YouTubeNotifier. This allows you to specify where the notification server should listen. ```python notifier.run(host="123.456.789.012", port=5000) ``` -------------------------------- ### Run Pytest with Coverage Source: https://github.com/seoulsky/ytnoti/blob/main/CONTRIBUTING.md Execute tests using pytest and generate a coverage report. Ensure code coverage reaches 100%. ```bash uv run pytest --cov --cov-report=term-missing ``` -------------------------------- ### Check Minimum Python Version with Vermin Source: https://github.com/seoulsky/ytnoti/blob/main/CONTRIBUTING.md Verify that the updated code meets the minimum required Python version using vermin. This command checks for violations against Python 3.11. ```bash uv run vermin -t=3.11 --violations ytnoti ``` -------------------------------- ### Combine Multiple Decorators for Event Listening Source: https://github.com/seoulsky/ytnoti/blob/main/docs/quickstart.md Combine different decorators like `@notifier.edit()` and `@notifier.upload()` to listen for multiple types of events, optionally filtering by channel ID. ```python @notifier.edit() @notifier.upload(channel_ids="UCuFFtHWoLl5fauMMD5Ww2jA") async def listener(video: Video): print(f"New video from CBC News: {video.title}") ``` -------------------------------- ### Update Type Hint for @notifier.any() Listener Source: https://github.com/seoulsky/ytnoti/blob/main/docs/migration.md When using the `@notifier.any()` listener, update the type hint for the first argument to `Video | DeletedVideo` to correctly handle potential deleted video events. ```python from ytnoti import Video, DeletedVideo @notifier.any() async def listener(video: Video | DeletedVideo) -> None: if isinstance(video, DeletedVideo): return print(video) ``` -------------------------------- ### Integrate with Existing FastAPI App Source: https://github.com/seoulsky/ytnoti/blob/main/docs/advanced.md Pass an existing FastAPI application instance to the YouTubeNotifier to integrate its notification handling into your current web framework. This allows you to add custom routes and logic alongside the notifier. ```python from fastapi import FastAPI from ytnoti import YouTubeNotifier app = FastAPI() # Do whatever you want with the app, like adding routes @app.get("/hello") async def hello(): return {"message": "Hello World"} notifier = YouTubeNotifier(app=app) @notifier.upload() async def listener(video): print(f"New video from {video.channel.name}: {video.title}") notifier.subscribe("UCuFFtHWoLl5fauMMD5Ww2jA") # Channel ID of CBC News notifier.run() ``` -------------------------------- ### Set Custom Callback URL Source: https://github.com/seoulsky/ytnoti/blob/main/docs/advanced.md Specify a custom callback URL for notifications, using either an IP address or a domain name. This is useful for directing notifications to your own server instead of using ngrok. ```python notifier = YouTubeNotifier(callback_url="https://123.456.789.012") ``` ```python notifier = YouTubeNotifier(callback_url="https://yourdomain.com") ``` ```python notifier = YouTubeNotifier(callback_url="https://yourdomain.com/endpoint") ``` -------------------------------- ### Configure Uvicorn Workers Source: https://github.com/seoulsky/ytnoti/blob/main/docs/advanced.md Set the number of worker processes for the uvicorn server. This can be used to scale the notification handling capacity. ```python notifier.run(workers=3) ``` -------------------------------- ### Use File-Based Video History Source: https://github.com/seoulsky/ytnoti/blob/main/docs/advanced.md Configure the YouTubeNotifier to use a file-based history to track videos, preventing duplicate notifications for uploads or edits. Specify a directory path to store the history files. ```python from ytnoti import YouTubeNotifier, FileVideoHistory notifier = YouTubeNotifier(video_history=FileVideoHistory(dir_path="video_history")) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.