Advertisement
ZaxonXP45

sort_by_genre.sh

Oct 13th, 2022 (edited)
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.82 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. LOC=$(dirname $(realpath $0))
  4. LIST=$LOC/downloaded
  5. OUTDIR=$LOC/../Sorted
  6.  
  7. [ ! -d "$1" ] && exit 1;
  8. dir=$1
  9. dir=${dir%%/}
  10.  
  11. dirs=( 0 $( cat $LIST | cut -d';' -f3 | grep -v "n/a" | sort | uniq ) )
  12.  
  13. IFS=$'\n'
  14. files=($dir/*)
  15.  
  16. for file in ${files[*]}; do
  17.  
  18.     # get the name of the module from the 7z archive
  19.     if [ ${file: -3} == .7z ]; then
  20.         name=$(7z l -slt $file | grep Path | tail -1)
  21.         name=${name##*= }
  22.         name=${name##*/}
  23.     else
  24.         name=$file
  25.     fi
  26.  
  27.     # find the genre of the file
  28.     genre=($(grep $name $LIST | cut -d';' -f3 | grep -v "n/a"))
  29.  
  30.     if [[ ${#genre[@]} -eq 1 ]]; then
  31.  
  32.         file2=$( basename $file )
  33.  
  34.         [ ! -d "$OUTDIR/${genre[0]}" ] && mkdir "$OUTDIR/${genre[0]}"
  35.  
  36.         mv -iv "$file" "$OUTDIR/${genre[0]}/$file2"
  37.     fi
  38. done
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement