# TubeArchivist Accessory Script: YouTube Video Processor
A Python script designed to enhance your **TubeArchivist** setup by:
- Fetching video metadata from YouTube via the YouTube Data API.
- Generating `.nfo` files for integration with **Channels DVR**, **Jellyfin**, **Emby**, or **Kodi**.
- Renaming video files and `.nfo` files based on their titles.
- Organizing video files into directories based on their uploaders.
- Sending notifications using **Apprise** with support for multiple services, now including total deleted files.
- Optionally triggering a Channels DVR metadata refresh after processing.
- **Enhanced file cleanup** with per-channel `delete_after` settings.
This script works alongside **TubeArchivist**, providing enhanced file organization and compatibility for additional media workflows.
---
## Features
- **Metadata Retrieval**: Fetches YouTube video metadata (title, description, uploader, upload date) for each processed video.
- **Generate `.nfo` Files**: Creates `.nfo` files with the metadata for use in **Channels DVR** or other media library systems.
- **File Renaming**: Renames video files and associated `.nfo` files to match the video's title.
- **Directory Organization**: Moves processed files into directories named after their uploaders.
- **Notifications with Apprise**: Sends detailed summaries of processed videos, including a sum total of deleted files in each channel, through services like Pushover, Discord, Slack, etc.
- **Channels DVR Metadata Refresh**: Optionally triggers a Channels DVR library refresh after processing.
- **Flexible File Cleanup**:
- Automatically removes files older than a specified number of days.
- Supports both a global `delete_after` setting and **per-channel `delete_after` settings** for custom retention policies.
- **Provides a total files deleted count per channel** in notifications.
- **Smart Channel Handling:**
- Detects channel directories and automatically adds them to the `config.yaml` if they don't exist.
- Avoids overwriting existing channel configurations, including per-channel `delete_after` settings.
---
## Requirements
### Software
- Python 3.6 or later.
- A working **TubeArchivist** instance.
### Python Libraries
Install required libraries with:
```bash
pip install -r requirements.txt
- A valid YouTube Data API key.
- Apprise-compatible notification service URLs (optional).
-
Clone this repository:
git clone /~https://github.com/peppy6582/TubeArchivist-Accessory-Script.git cd TubeArchivist-Accessory-Script
-
Make the script executable:
chmod +x youtube-process.py
-
Install Python dependencies:
pip install -r requirements.txt
-
Configure the script by creating a
config.yaml
file:video_directory: "/path/to/TubeArchivist/YouTube/" channels_directory: "/path/to/TubeArchivist/YouTube Channels/" channel_specific_delete_after: true or false processed_files_tracker: "processed_files.json" youtube_api_key: "your-youtube-api-key" apprise_url: "pover://your_user_key@your_api_token" channels_dvr_api_refresh_url: "http://YOUR_IP_ADDRESS:8089/dvr/scanner/scan" delete_after: 30 # Remove files older than 30 days by default, set to null to disable
- Required:
video_directory
: Directory where TubeArchivist stores downloaded videos.channels_directory
: Directory to organize videos by uploader.channel_specific_delete_after
: Whether or not to use channel specific values for delete_after, set to true or falseyoutube_api_key
: YouTube Data API key.processed_files_tracker
: Keeps a record of processed files so API hits are not duplicated.
- Optional:
apprise_url
: URL for sending notifications via Apprise-supported services.channels_dvr_api_refresh_url
: URL for Channels DVR metadata refresh.delete_after
: Global value for removing files older than the specified number of days. Set to null to disable the delete function by default.channels
: Will be automatically populated if channel_specific_delete_after is set to true
- Required:
The script supports Apprise for notifications. Apprise allows you to send notifications to various services like Pushover, Discord, Slack, Email, and more.
Here are some examples of how to configure the apprise_url
in your config.yaml
file:
-
Pushover:
apprise_url: "pover://your_user_key@your_api_token"
-
Discord:
apprise_url: "discord://webhook_id/webhook_token"
-
Slack:
apprise_url: "slack://workspace_token@channel_id"
-
Email (SMTP):
apprise_url: "mailto://username:password@mailserver.example.com:587/?to=recipient@example.com"
You can test your notification setup using the Apprise CLI:
apprise -vv -t "Test Notification" -b "This is a test message" "pover://your_user_key@your_api_token"
Run the script manually:
cd /path/to/TubeArchivist-Accessory-Script
./youtube-process.py
To process videos twice a day (at 8:00 AM and 8:00 PM), add this line to your crontab:
0 8,20 * * * cd /path/to/TubeArchivist/YouTube && ./youtube-process.py >> /path/to/TubeArchivist/YouTube/youtube-process.log 2>&1
-
TubeArchivist:
- This script works alongside TubeArchivist to organize downloaded YouTube videos by uploader and enhance metadata compatibility.
-
Channels DVR:
- Generated
.nfo
files are compatible with Channels DVR. - After processing, the script can optionally trigger a Channels DVR library refresh using the
channels_dvr_api_refresh_url
.
- Generated
The delete_after
feature allows you to specify a number of days after which files will be automatically removed. This can help manage disk space and keep your library clean. It will also auto-populate the channels into your config.yaml so you can add per-channel delete_after:
- Global
delete_after
:- Set
delete_after
inconfig.yaml
to the desired number of days. - Example:
delete_after: 30 # Removes files older than 30 days
- Set
- Per-Channel
delete_after
:- You can also specify
delete_after
settings on a per-channel basis within thechannels
section:channels: - America's Test Kitchen - SAM THE COOKING GUY - WatchMojo.com - MsMojo: delete_after: 14 # 14 day retention for MsMojo ...
- If a channel has a
delete_after
value set, that value will be used, otherwise, the global setting will be used. If neither are set, files in that channel will not be deleted.
- You can also specify
- The script will now provide the sum total of files deleted per channel in the apprise notifications.
If delete_after
is not set for a channel, or if it's globally set to null
, the script will skip file deletion for that specific channel or entirely if it is global.
- Missing API Key: Ensure
youtube_api_key
is correctly set inconfig.yaml
. - Invalid Notification URL: Verify your
apprise_url
with the Apprise CLI to ensure it is correct. - File Permissions: Check read/write permissions for the specified directories.
Check the log file for errors (only works if you set your cron job to output to this file as above):
cat /path/to/TubeArchivist/YouTube/youtube-process.log
- Fork this repository.
- Create a new branch:
git checkout -b feature-name
- Commit your changes:
git commit -m "Add feature name"
- Push the branch:
git push origin feature-name
- Submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for details.