This application monitors a YouTube channel's RSS feed for new videos, downloads the audio (MP3) using yt-dlp, and uploads it to a specified Telegram channel. It is designed to run locally, spawning a terminal window for the download process to keep the main application lightweight and responsive.
- RSS Monitoring: checks for new videos based on the
pubDate. - Automated Download: Spawns a dedicated terminal window to run
yt-dlp. - Telegram Integration: Uploads the downloaded MP3 to a Telegram channel with metadata.
- State Management: Keeps track of the last processed video in
last_seen.json. - Smart Cleanup: Deletes local files after successful upload.
- Python 3.8+
ffmpeg(required by yt-dlp for audio conversion)yt-dlp(installed via pip)
- Clone the repository or download the source code.
- Create a virtual environment (recommended):
python3 -m venv venv source venv/bin/activate - Install dependencies:
(Note: valid
pip install -r requirements.txt
requirements.txtshould include:feedparser,python-telegram-bot,python-dotenv,yt-dlp)
Create a .env file in the project root with the following variables:
TELEGRAM_BOT_TOKEN=your_bot_token_here
TELEGRAM_CHANNEL_ID=your_channel_id_here
YOUTUBE_CHANNEL_ID=your_youtube_channel_id_herepython3 yt2tg.pyYou can compile the script into a standalone executable using pyinstaller. A spec file yt2tg.spec is provided.
-
Install PyInstaller:
pip install pyinstaller
-
Build the executable:
pyinstaller yt2tg.spec
Or manually:
pyinstaller --onefile --name yt2tg yt2tg.py
-
The executable will be located in the
dist/folder:./dist/yt2tg
- Feed Check: The script fetches the RSS feed for the configured YouTube channel.
- New Video Detection: It compares the publication date of videos against the timestamp stored in
last_seen.json. - Download:
- For each new video, it spawns a visible terminal window.
yt-dlpruns in this window to download and convert the video to MP3.- The terminal closes automatically upon completion.
- Upload: If the download was successful, the bot uploads the audio file to Telegram.
- Update State: The
last_seen.jsonfile is updated only after a successful upload.
- Terminal not opening: Ensure you have a supported terminal emulator installed (gnome-terminal, xfce4-terminal, konsole, xterm).
- Download fails: Check
yt2tg_monitor.logor the brief output in the spawned terminal. Ensureffmpegis installed.