Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- name=$(basename $0)
- SORTED=~/Music/Modules/Sorted/
- DELETED=~/Music/Modules/_scripts/deleted
- GENRES=~/Music/Modules/_scripts/downloaded
- if [[ ! $1 ]]; then
- echo ""
- echo "Plays the MOD from the directory and allows to decide if to delete or keep afterwards"
- echo ""
- echo "$name mods_dir_name"
- echo ""
- exit 1
- fi
- ###########################################
- choose_location() {
- local name=$1
- local ff=$2
- unset folder
- name=${name##*/}
- # find if the file has genre
- fgen=$(grep ";$name;" $GENRES | cut -d';' -f3 )
- # if genre found then move it automatically
- # otherwise allow user to choose
- if [[ "$fgen" != "n/a" ]]; then
- [ ! -d $SORTED/$fgen ] && mkdir "$SORTED/$fgen"
- [ -d $SORTED/$fgen ] && mv "$ff" $SORTED/$fgen/ && FLAG=1
- else
- IFS=$'\n'
- # get existing dirs and also from the genres list
- dirs1=( $( cat $GENRES | cut -d';' -f3 | grep -v "n/a" ) )
- dirs2=( $( find $SORTED -mindepth 1 -type d -printf "%f\n") )
- dirs=( ${dirs1[*]} ${dirs2[*]} )
- dirs=( 0 $(echo "${dirs[*]}" | sort | uniq ) )
- max=$(( ${#dirs[*]} - 1 ))
- for (( i=1; i <= $max; i++ )); do
- printf "%02d) %-35s\n" "$i" "${dirs[$i]}"
- done | column
- read -N 2 -p "Select / (ne)w: " answ
- # User selected existing folder or will type the new name
- if [[ ($answ -gt 0) && ($answ -le $max) ]]; then
- folder=${dirs[$answ]}
- [ ! -d $SORTED/$folder ] && mkdir "$SORTED/$folder"
- [ -d $SORTED/$folder ] && mv "$ff" $SORTED/$folder/ && FLAG=1
- else
- read -p "New folder name: " folder
- [ ! -d $SORTED/$folder ] && mkdir "$SORTED/$folder"
- [ -d $SORTED/$folder ] && mv "$ff" $SORTED/$folder/ && FLAG=1
- fi
- fi
- }
- ###########################################
- cleanup() {
- rm -r $tmp_dir
- exit 0;
- }
- ###########################################
- trap 'cleanup' SIGINT
- if [[ -d $1 ]]; then
- dir=$1
- tmp_dir=$(mktemp -d)
- IFS=$'\n'
- files=($dir/*)
- while [ $files ]; do
- if [ ! -v current ]; then
- count=${#files[*]}
- file=${files[0]}
- if [ ${file: -3} == .7z ]; then
- rm $tmp_dir/* > /dev/null 2>&1
- 7z e $file -o$tmp_dir
- current=$tmp_dir/$(ls $tmp_dir)
- else
- current=$file
- fi
- fi
- clear
- echo -e "\e[39m$count files to process"
- echo -e ""
- openmpt123 --no-meters -- $current
- echo ""
- echo -en "\e[33m[R]eplay, \e[31m[D]elete, \e[32m[K]eep, \e[36m[Q]uit\e[39m ? : "
- read -N 1 answ
- echo ""
- case $answ in
- [d])
- echo -ne "\e[31mDelete \"$file\" ? "
- read -N 1 answ2
- if [[ "$answ2" == "y" ]]; then
- rm $file
- files=(${files[@]:1:${#files[@]}})
- prefix=${current%/*}
- echo ${current/$prefix\/} >> $DELETED
- unset current
- fi
- ;;
- [D])
- rm $file
- files=(${files[@]:1:${#files[@]}})
- prefix=${current%/*}
- echo ${current/$prefix\/} >> $DELETED
- unset current
- ;;
- [kK])
- choose_location $current $file
- if [ $FLAG -gt 0 ]; then
- files=(${files[@]:1:${#files[@]}})
- FLAG=0
- unset current
- fi
- ;;
- [rR])
- ;;
- [qQ])
- cleanup
- echo ""
- exit 0
- ;;
- esac
- done
- fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement