Customize Jellyfin Scan Frequencies

Introduction

In a previous article, I mentioned that ‘Jellyfin’s scheduled task “Scan Media Library” does not consume resources and can run frequently without issues’. In fact, this statement is not entirely correct. The resource consumption of the task depends on the number of media/files.

Recently, I developed a project to scrape videos while automatically generating NFO files and video posters. In this new video directory, there are up to 2000 files (mostly NFO and poster images, with videos not yet downloaded), organized into four-level subdirectories. However, the CPU usage of the scheduled task has increased significantly, indicating an issue.

After some research, I found that using crontab to periodically call the Jellyfin API is currently the only solution to customize scan frequencies for different media libraries.

Steps

Disable Scheduled Task

Navigate to ‘Dashboard | Scheduled Tasks | Scan Media Library’ and delete the existing task:

image-20240611131240942

Obtain an API Key

Navigate to ‘Dashboard | API Keys’ and create a new one:

image-20240611131529710

Get the API Endpoint

I recommend using F12 to capture the request:

image-20240611131657198

Press F12 before clicking ‘Refresh’ and find the corresponding request:

image-20240611131710749

/Items/LibraryID/Refresh?ScanParameters – we can directly use this URL.

image-20240611131902161

crontab

1
2
3
4
# Edit
crontab -e
# View
crontab -l

curl format:

1
curl -k -X POST "https://IPAddress:Port/Items/LibraryID/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default&ReplaceAllImages=false&ReplaceAllMetadata=false" -H "Authorization: MediaBrowser Token=APIKey"

crontab format:

1
2
# New Episodes: every ten minutes
*/10 * * * * curl -k -X POST "https://IPAddress:Port/Items/LibraryID/Refresh?Recursive=true&ImageRefreshMode=Default&MetadataRefreshMode=Default&ReplaceAllImages=false&ReplaceAllMetadata=false" -H "Authorization: MediaBrowser Token=APIKey"

Other frequency configurations:

  • Every hour: 0 * * * *;
  • Weekly: e.g., 0 17 * * 0, every Sunday at 5 PM;
  • Bi-weekly: e.g., 0 11 1,15 * *, 11 AM on the 1st and 15th of every month;

View crontab logs:

1
2
3
4
# 1. Use journalctl 
journalctl -u crond
# 2. Directly view log files, which is more comprehensive
cat /var/log/cron

Results

image-20240611154250550

This software is NetData, and I will write a blog post about it later.

The red one represents scanning the media library of scraped videos, while the blue one is for scanning the anime of the latest season.

Observations:

  • The average value of the blue does not exceed 5%, so executing it every ten minutes is feasible — this frequency also ensures that Jellyfin scrapes newly downloaded anime promptly.

  • Compared to Jellyfin’s scheduled tasks, scanning all media libraries every hour would clearly impose a heavier CPU load.

References