Created
October 20, 2019 02:19
-
-
Save myoung34/61a20525880941e5a84c3ae10ddebed5 to your computer and use it in GitHub Desktop.
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 | |
| [[ $(ps aux | grep rsync | grep -vE 'grep.*rsync' | wc -l) -gt 0 ]] || ( \ | |
| rsync -avzh --chmod=a=rw seedbox:~/finished /volume1/Misc/seedbox/ && \ | |
| ssh seedbox "rm -rf ~/finished/*" && \ | |
| find /volume1/Misc/seedbox/ -type d -exec chmod 777 {} \; && \ | |
| curl -X POST http://192.168.2.113:9898?message=Finished%20rsync \ | |
| ) | |
| tv_dir="/volume1/TV" | |
| movie_dir="/volume1/Movies/Pending" | |
| IFS=$'\n' | |
| for i in $(docker run -v /volume1/Misc/seedbox/finished/:/app -w /app alpine sh -c "(apk add -U --no-cache file >/dev/null 2>&1 && find . -type f -exec file -N -i -- {} + )" | sed -n 's!: video/[^:]*$!!p' | grep -vi sample); do | |
| export filename=$(basename $i) | |
| export dirname=$(dirname $i) | |
| file_json=$(guessit $filename | grep -vE '^For:' | sed 's/GuessIt found: //g' | tr -d '\n') | |
| type=$(echo $file_json | jq -r .type) | |
| if [[ "${type}" == "episode" ]]; then | |
| show=$(echo $file_json | jq -r .title | sed -e "s/\b\(.\)/\u\1/g") | |
| season=$(echo $file_json | jq -r .season) | |
| location="${tv_dir}/${show}/Season ${season}" | |
| [[ ! -d "${location}" ]] && mkdir -p "${location}" | |
| echo "Found tv show: ${filename}" | |
| echo $' -> ' "mv /volume1/Misc/seedbox/finished/${i} ${location} && rm -rf /volume1/Misc/seedbox/finished/${dirname} && chown myoung:users ${location}/${filename}" | |
| mv /volume1/Misc/seedbox/finished/"${i}" "${location}" && rm -rf /volume1/Misc/seedbox/finished/"${dirname}" >/dev/null 2>&1 && chown myoung:users "${location}/${filename}" | |
| curl -G -X POST http://192.168.2.113:9898 --data-urlencode "message=TV Show '${show}' Season '${season}' file '${filename}' Downloaded" | |
| elif [[ "${type}" == "movie" ]]; then | |
| echo "Found movie: ${filename}" | |
| echo $' -> ' "mv /volume1/Misc/seedbox/finished/${i} ${movie_dir} && rm -rf /volume1/Misc/seedbox/finished/${dirname} && chown myoung:users ${movie_dir}/${i}" | |
| mv /volume1/Misc/seedbox/finished/"${i}" "${movie_dir}" && rm -rf /volume1/Misc/seedbox/finished/"${dirname}" >/dev/null 2>&1 && chown myoung:users "${movie_dir}/${i}" | |
| curl -G -X POST http://192.168.2.113:9898 --data-urlencode "message=Movie '${filename}' Downloaded" | |
| fi | |
| done | |
| unset IFS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment