Skip to content

Instantly share code, notes, and snippets.

@willjasen
Last active June 6, 2024 23:35
Show Gist options
  • Save willjasen/468e58d7dd23659f3917545c7fa3688e to your computer and use it in GitHub Desktop.
Save willjasen/468e58d7dd23659f3917545c7fa3688e to your computer and use it in GitHub Desktop.
clean up the media folder
#!/bin/sh
MEDIA_FOLDER=/mnt/crypt/runtipi/media/data;
RED="\e[31m";
GREEN="\e[32m";
YELLOW="\e[33m";
BLUE="\e[34m";
echo "${YELLOW}-- This clean up script has started! --";
echo "${BLUE}---------------------------------------";
echo "${GREEN}Displaying text files that begin with 'RARBG'...";
if [ ! $(find $MEDIA_FOLDER -type f -name "RARBG*.txt" | wc -l) -eq 0 ]; then
find $MEDIA_FOLDER -type f -name "RARBG*.txt";
read -p "Continue with deletions? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1;
find $MEDIA_FOLDER -type f -name "RARBG*.txt" -exec /bin/rm {} \;
else
echo "No matching text files were found...";
fi;
echo "${BLUE}---------------------------------------";
echo "${GREEN}Displaying text files that include variations of 'torrent' in the filename...";
if [ ! $(find $MEDIA_FOLDER -type f -iname "*torrent*.txt" | wc -l) -eq 0 ]; then
find $MEDIA_FOLDER -type f -iname "*torrent*.txt";
read -p "Continue with deletions? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1;
find $MEDIA_FOLDER -type f -iname "*torrent*.txt" -exec /bin/rm {} \;
else
echo "No matching text files were found...";
fi;
echo "${BLUE}---------------------------------------";
echo "${GREEN}Displaying text files that include variations of 'downloaded from' in the filename...";
if [ ! $(find $MEDIA_FOLDER -type f -iname "*downloaded*from*.txt" | wc -l) -eq 0 ]; then
find $MEDIA_FOLDER -type f -iname "*downloaded*from*.txt";
read -p "Continue with deletions? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1;
find $MEDIA_FOLDER -type f -iname "*downloaded*from*.txt" -exec /bin/rm {} \;
else
echo "No matching text files were found...";
fi;
echo "${BLUE}---------------------------------------";
echo "${GREEN}Displaying all text files within the 'Movies' and 'TV' folders except 'info.txt' and 'readme.txt'...";
if [ ! $(find -path $MEDIA_FOLDER/Movies -path $MEDIA_FOLDER/TV -type f -iname "*.txt" ! -iname "*info.txt" ! -iname "*readme.txt" | wc -l) -eq 0 ]; then
find $MEDIA_FOLDER/Movies find $MEDIA_FOLDER/TV -type f -iname "*.txt" ! -iname "*info.txt" ! -iname "*readme.txt" ! -iname "info.txt";
read -p "Continue with deletions? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1;
find $MEDIA_FOLDER/Movies find $MEDIA_FOLDER/TV -type f -iname "*.txt" ! -iname "*info.txt" ! -iname "*readme.txt" -exec /bin/rm {} \;
else
echo "No matching text files were found...";
fi;
echo "${BLUE}---------------------------------------";
echo "${GREEN}Displaying transcode files that are smaller than 256 MB...";
if [ ! $(find $MEDIA_FOLDER -type f -name "*.ts" -size -256M | wc -l) -eq 0 ]; then
find $MEDIA_FOLDER -type f -name "*.ts" -size -256M;
read -p "Continue with deletions? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1;
find $MEDIA_FOLDER -type f -name "*.ts" -size -256M -exec /bin/rm {} \;
else
echo "No matching transcode files were found...";
fi;
echo "${BLUE}---------------------------------------";
echo "${GREEN}Displaying sample video files...";
if [ ! $(find $MEDIA_FOLDER -regextype posix-extended -regex ".*sample.(avi|mkv)" | wc -l) -eq 0 ]; then
find $MEDIA_FOLDER -regextype posix-extended -regex ".*sample.(avi|mkv)";
read -p "Continue with deletions? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1;
find $MEDIA_FOLDER -regextype posix-extended -regex ".*sample.(avi|mkv)" -exec /bin/rm {} \;
else
echo "No matching sample video files were found...";
fi;
echo "${BLUE}---------------------------------------";
echo "${GREEN}Displaying unneeded .jpg files...";
if [ ! $(find $MEDIA_FOLDER -regextype posix-extended -regex ".*WWW.YIFY-TORRENTS.COM.jpg" | wc -l) -eq 0 ]; then
find $MEDIA_FOLDER -regextype posix-extended -regex ".*WWW.YIFY-TORRENTS.COM.jpg";
read -p "Continue with deletions? (Y/N): " confirm && [[ $confirm == [yY] || $confirm == [yY][eE][sS] ]] || exit 1;
find $MEDIA_FOLDER -regextype posix-extended -regex ".*WWW.YIFY-TORRENTS.COM.jpg" -exec /bin/rm {} \;
else
echo "No unneeded .jpg files were found...";
fi;
echo "${BLUE}---------------------------------------";
echo "${YELLOW}-- This clean up script is complete! --";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment