Skip to content

Instantly share code, notes, and snippets.

@janw
Created December 25, 2024 12:07
Show Gist options
  • Select an option

  • Save janw/aecd7707064f10ba7011355481d31010 to your computer and use it in GitHub Desktop.

Select an option

Save janw/aecd7707064f10ba7011355481d31010 to your computer and use it in GitHub Desktop.
Simple import script for Radarr to ensure an imported movie is first processed by PlexCleaner before the import completes
#!/bin/bash
set -e
start_time=$(date '+%Y-%m-%d %H:%M:%S')
radarr_download_id="${radarr_download_id:-}"
radarr_sourcepath="${radarr_sourcepath:-}"
radarr_destinationpath="${radarr_destinationpath:-}"
ignore_file="$radarr_movie_path/.plexignore"
logs_dir="/config/logs"
source_basename="$(basename "$radarr_sourcepath")"
source_stem="${source_basename%.*}"
source_dir="$(dirname "$radarr_sourcepath")"
destination_base="${radarr_destinationpath%.*}"
(
if [ -z "$radarr_download_id" ]; then
echo "radarr_download_id is not set"
exit 1
fi
if [ -z "$radarr_sourcepath" ]; then
echo "radarr_sourcepath is not set"
exit 1
fi
if [ -z "$radarr_destinationpath" ]; then
echo "radarr_destinationpath is not set"
exit 1
fi
echo "Start time : $start_time"
echo "Source dir : $source_dir"
echo "Source stem : $source_stem"
echo "Destination base : $destination_base"
echo "Writing temporary plexignore file"
echo '*' > "$ignore_file"
echo "Importing file ..."
cp "$radarr_sourcepath" "$radarr_destinationpath"
echo "Waiting for PlexCleaner to commence processing ..."
sleep 65
attempts=0
max_attempts=24
sleep_time=10
while [ ! -f "${destination_base}.PlexCleaner" ] || [ -e "${destination_base}.tmp" ]; do
if [ $attempts -ge $max_attempts ]; then
echo "File ${destination_base}.PlexCleaner not found after $((max_attempts * sleep_time)) seconds, exiting."
exit 1
fi
echo "Waiting for PlexCleaner sidecar ..."
sleep 10
attempts=$((attempts + 1))
done
echo "Waiting for dust to settle ..."
sleep 30
rm -f "$ignore_file"
echo "Import completed successfully." >&2
) | tee "$logs_dir/import_${radarr_movie_tmdbid}_$start_time" >&2
exit 0
@janw
Copy link
Author

janw commented Dec 25, 2024

The idea here is that the deep analysis by Plex and Radarr only occurs after PlexCleaner has processed the file. This ensures that

  1. Radarr can calculate the Custom Format Score correctly based on, for example, the audio tracks that are present and actually wanted
  2. Plex will only see the post-processed file for analysis, showing the correct available subtitles and audio tracks to users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment