Skip to content

Instantly share code, notes, and snippets.

@rafaelribeiroo
Created October 25, 2022 18:24
Show Gist options
  • Save rafaelribeiroo/d94647481b907cc3062c8ab594c5b89c to your computer and use it in GitHub Desktop.
Save rafaelribeiroo/d94647481b907cc3062c8ab594c5b89c to your computer and use it in GitHub Desktop.
in bash
#!/usr/bin/env bash
declare -A f=(
[user_dirs]=~/.config/user-dirs.dirs
[null]=/dev/null
)
source "${f[user_dirs]}"
declare -a d=(
"${XDG_DOWNLOAD_DIR}"/ # 0
/home/"${USER}"/.local/share/Trash/files # 1
)
has_dir=0
inotifywait --quiet --monitor "${d[0]}" --event create |
while read directory action file; do
[[ "${file}" =~ .*torrent$ ]] \
&& transmission-gtk "${d[0]}${file}" \
&& rm --force "${d[0]}${file}"
# [[ "${file}" =~ .*tar.gz$ ]] \
# && tar xvf "${d[0]}${file}" \
# && rm --force "${d[0]}${file}"
if [[ "${file}" =~ .*zip$ ]]; then
unzip "${d[0]}${file}" -d "${d[0]}" &> "${f[null]}"
if [[ -d "${d[0]}${file//.zip/}" ]]; then
has_dir=1
cd "${d[0]}${file//.zip/}" &> "${f[null]}"
sub_dir=$(find "${d[0]}" -maxdepth 2 -type d | tail -1 | awk --field-separator=/ '{print $6}')
[[ "${sub_dir}" ]] \
&& cd "${sub_dir}" &> "${f[null]}"
mv --no-clobber ./* "${d[0]}"
fi
mv --no-clobber "${d[0]}"*720p*.srt "${d[0]}"*480p*.srt "${d[0]}"*XviD*.srt "${d[0]}"*s_tv_*.srt "${d[0]}"*[0-9].WEBRip*.srt "${d[0]}"*[0-9].REPACK*.srt "${d[0]}${file}" "${d[1]}" &> "${f[null]}"
[[ "${has_dir}" -eq 1 ]] \
&& mv --no-clobber "${d[0]}${file//.zip/}" "${d[1]}" \
&& cd - &> "${f[null]}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment