Created
December 25, 2024 12:07
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The idea here is that the deep analysis by Plex and Radarr only occurs after PlexCleaner has processed the file. This ensures that