transmission-auto-label.sh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #!/usr/bin/env bash
  2. set -euo pipefail # bash strict mode
  3. LABELS=(games ttc music movies art books audiobooks)
  4. ROOT_DIR="/media/${USER}/Seagate8TB/multimedia"
  5. error(){
  6. echo "YOU HAVE SOMETHING WRONG WITH SCRIPT!"
  7. echo "Your label is: '${1}', is not defined!"
  8. exit 2
  9. }
  10. display_help(){
  11. echo "Usage: ${0##*/} [label|set_download_dir]"
  12. exit 2
  13. }
  14. label_torrents(){
  15. for label in "${LABELS[@]}"; do
  16. strings_by_label "$label"
  17. for str in "${strings[@]}"; do
  18. transmission-remote -F n:"$str" -L "$label"
  19. echo "transmission-remote -F n:${str} -L ${label}"
  20. transmission-remote -F n:"${str,,}" -L "$label"
  21. echo "transmission-remote -F n:${str,,} -L ${label}"
  22. transmission-remote -F n:"${str^^}" -L "$label"
  23. echo "transmission-remote -F n:${str^^} -L ${label}"
  24. str=${str,,}; transmission-remote -F n:"${str^}" -L "$label"
  25. echo "transmission-remote -F n:${str^} -L ${label}"
  26. done
  27. done
  28. }
  29. strings_by_label(){
  30. label="$1"
  31. case "${label,,}" in
  32. movies) strings=(mkv mp4 avi 1080p 720p 480p YTS.AM YTS.AM Tigole BluRay x265 5.1 7.1 film);;
  33. music) strings=(flac ogg opus album discography дискография);;
  34. books) strings=(book eBook kindle epub azw pdf mobi cbr cbz DjVu eReader nicolubbin calibre) ;;
  35. audiobooks) strings=(AudioBook ZlotoPolsky SuperProdukcja mp3 abridged) ;;
  36. games) strings=(GoG PlayStation XboX Nintendo GameCube) ;;
  37. art) strings=(art ArtBook painting WallPaper) ;;
  38. ttc) strings=(ttc TheTeachingCompany tgc TheGreatCourses) ;;
  39. *) error "$label";;
  40. esac
  41. }
  42. # implement stuff to only run this on finished stuff
  43. set_download_dir_by_label(){
  44. echo "Usage: ${0##*/} [--move,--find,-c,-C,-w] [destination (default: ${ROOT_DIR}/<label>)]"
  45. flag="${1:---move}"
  46. ROOT_DIR="${2:-$ROOT_DIR}"
  47. for label in "${LABELS[@]}"; do
  48. dest="${ROOT_DIR%/}/${label}"
  49. mkdir -p "$dest"
  50. echo "transmission-remote -F l:${label} ${flag} ${dest}"
  51. transmission-remote -F "l:${label}" "$flag" "$dest"
  52. done
  53. }
  54. [[ $# -lt 1 ]] && display_help
  55. action="$1"; shift 1
  56. case "${action,,}" in
  57. label) label_torrents;;
  58. set_download_dir) set_download_dir_by_label "$@";;
  59. *) error "$action" ;;
  60. esac