Skip to content

Instantly share code, notes, and snippets.

@acouvreur
Last active October 16, 2023 21:24
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acouvreur/25f90a605307705cd71c9399fa7eb5b8 to your computer and use it in GitHub Desktop.
Save acouvreur/25f90a605307705cd71c9399fa7eb5b8 to your computer and use it in GitHub Desktop.
Sync deleted files from Radarr/Sonarr
#!/bin/bash
# Find existing files in download/complete that are not in movies or tvshows.
export DOWNLOAD_FOLDER=path/to/downloads
export MOVIES_FOLDER=path/to/movies
export TVSHOWS_FOLDER=path/to/tvshows
findExistingFile() {
file=$(find $MOVIES_FOLDER/ $TVSHOWS_FOLDER/ -samefile "$1")
if [ -z "$file" ]; then
echo "File \"$1\" is not present in the movies or tvshows folders. Deleting..."
rm "$1"
fi;
}
export -f findExistingFile
find $DOWNLOAD_FOLDER -type f -size +1G -exec bash -c 'findExistingFile "$0"' {} \;
@hrb9
Copy link

hrb9 commented Aug 8, 2023

Hey, about this code, i have a path with spaces and when i used " " that used only the one word you know why and how to fix it ?

@acouvreur
Copy link
Author

Hey, about this code, i have a path with spaces and when i used " " that used only the one word you know why and how to fix it ?

I just added quotes around the rm command argument. Does that works for you @hrb9 ?

@ltctceplrm
Copy link

You need to put quotes around all the variables for it to work:

#!/bin/bash
# Find existing files in download/complete that are not in movies or tvshows.

export DOWNLOAD_FOLDER="path/to/downloads"

export MOVIES_FOLDER="path/to/movies"
export TVSHOWS_FOLDER="path/to/tvshows"

findExistingFile() {
  file=$(find "$MOVIES_FOLDER"/ "$TVSHOWS_FOLDER"/ -samefile "$1")
  if [ -z "$file" ]; then
    echo "File \"$1\" is not present in the movies or tvshows folders. Deleting..."
    rm "$1"
  fi;
}
export -f findExistingFile
find "$DOWNLOAD_FOLDER" -type f -size +1G -exec bash -c 'findExistingFile "$0"' {} \;

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