For those that use Sonarr, I took a stab at Sonarr a post-processing script that will generate a list of paths that need scanning:
#!/bin/bash
seasonrelativepath=${sonarr_episodefile_relativepath%/*}
seasonfullpath="$sonarr_series_path/$seasonrelativepath"
echo "$seasonfullpath" >>/home/plex/temp/makelist/plex.list
sort -u /home/plex/temp/makelist/plex.list -o /home/plex/temp/makelist/plex.list
exit
It generates a list in the following format:
/home/plex/amazon/Media/Television/Animals/Season 02
/home/plex/amazon/Media/Television/Attack on Titan/Season 02
/home/plex/amazon/Media/Television/Chopped/Season 33
/home/plex/amazon/Media/Television/VICE/Season 05
For now Iām calling partial Plex library scans manually on my second machine from the command line via the following commands but it should be easy enough to send the list file over and automate the process:
export LD_LIBRARY_PATH=/usr/lib/plexmediaserver
/usr/lib/plexmediaserver/Plex\ Media\ Scanner -v --list
## find the number corresponding to your tv shows library
/usr/lib/plexmediaserver/Plex\ Media\ Scanner -v -s -r -c 3 -d "/home/plex/amazon/Media/Television/Animals/Season 02"
/usr/lib/plexmediaserver/Plex\ Media\ Scanner -v -s -r -c 3 -d "/home/plex/amazon/Media/Television/Attack on Titan/Season 02"
/usr/lib/plexmediaserver/Plex\ Media\ Scanner -v -s -r -c 3 -d "/home/plex/amazon/Media/Television/Chopped/Season 33"
/usr/lib/plexmediaserver/Plex\ Media\ Scanner -v -s -r -c 3 -d "/home/plex/amazon/Media/Television/VICE/Season 05"
## change 3 to whatever your tv show library number is above
Cheers to @Ajki, @enz1ey, and /r/gesis for their awesome scripts that helped me make sense of everything!
Edit: Hereās a quick script I put together that takes the plex.list generated above and executes a partial library scan for each path in the list. Iām sure it could be written better but Iām learning as I go.
#!/bin/bash
if pidof -o %PPID -x "$0"; then
exit 1
fi
export LD_LIBRARY_PATH=/usr/lib/plexmediaserver
logfile=/home/plex/scripts/logs/plexscan/plexscan.log
list=/home/plex/temp/makelist/plex.list ## set to location of your list
section=3 ## change the section number of your plex tv shows library
echo "$(date "+%d.%m.%Y %T") Scanning for new TV" |& tee -a $logfile
while read -r line;
do
/usr/lib/plexmediaserver/Plex\ Media\ Scanner -v -s -r -c "$section" -d "${line}" |& tee -a $logfile
done < "$list"
echo -e "$(date "+%d.%m.%Y %T") Scan complete\n" |& tee -a $logfile
#echo "Deleting $list" |& tee -a $logfile
#rm "$list"
## uncomment above if you want to delete list after scan
exit
Edit2: If you have multiple lists you can combine them and remove duplicates via something like the following
sort -u /path/to/lists/*.list -o /path/to/output/combined.list
Edit3: Iāve fully automated the process. Server1 downloads new content (Sonarr), makes a list of directories to scan (via Sonarr post-processing), and uploads the content as well as the list to GDrive (rclone cron). Server2 downloads the list (rclone cron) and uses it to run partial scans of only the directories with new content (plex scanner cron).