Created
November 26, 2017 13:56
-
-
Save esolitos/70036092f9ec2b5594c1fe70ad0380ce to your computer and use it in GitHub Desktop.
This file contains 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 | |
BASE_DIR=/media/data/plex | |
DIR_MOVIES="$BASE_DIR/Movies" | |
DIR_SERIES="$BASE_DIR/TV.Series" | |
ACTIVE_TORRENTS="$(transmission-remote 195.154.136.195:4949 -l | tr -s ' ' | cut -d' ' -f11-)" | |
is_active_torrent() | |
{ | |
search_item="$1" | |
matches="$(echo "$ACTIVE_TORRENTS" | grep -Ec ".*($search_item).*" )" | |
if [[ $matches -eq 1 ]]; then | |
printf "OK: %s\n" "$search_item" | |
true | |
elif [[ $matches -gt 1 ]]; then | |
printf "### MANUAL ACTION REQUIRED.\n\tFound multiple results for: %s\n\tDelete the appropriate one." "$search_item" | |
printf "\n---------- BEGIN OPTIONS ----------\n %s \n---------- END OPTIONS ----------\n" "$(echo "$ACTIVE_TORRENTS" | grep -E ".*($search_item).*" )" | |
# Wait to continue, as manual action is required. | |
read -p "Press return to continue" | |
# Return tru, because this needs to be handled manually, no automated remove is required! | |
true | |
else | |
# Torrent is not active! | |
false | |
fi | |
} | |
SAVEIFS="$IFS" | |
IFS=$(printf "\n\b") | |
for download in $(ls -1 "$DIR_MOVIES"); do | |
if ! is_active_torrent "$download"; then | |
printf "WARN: Missing torrent: %s\n" "$download" | |
read -p "Remove [Y/n]? " yn | |
if [ -z "$yn" -o "$yn" = 'y' -o "$yn" = 'Y' ]; then | |
printf "\nREMOVING: %s" "$DIR_MOVIES/$download" | |
rm -r "$DIR_MOVIES/$download" | |
printf " ...done\n" | |
fi | |
fi | |
done | |
echo "######### NOTE: TV Shows not nicely haned yet!" | |
for serie in $(ls -1 "$DIR_SERIES"); do | |
if ! is_active_torrent "$serie"; then | |
printf "WARN: No torrent for serie: %s\n" "$serie" | |
read -p "Remove [y/N]? " yn | |
if [ "$yn" = 'y' -o "$yn" = 'Y' ]; then | |
printf "\nREMOVING: %s" "$DIR_SERIES/$serie" | |
rm -r "$DIR_SERIES/$serie" | |
printf " ...done\n" | |
fi | |
fi | |
done | |
# restore $IFS | |
IFS="$SAVEIFS" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment