Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ## Written by Julian Alistair Rutledge, November 24, 2013.
- ## Licensed for use under the GPL v3
- #!/bin/sh
- ## clean-up script for audio file dump
- ## takes one argument for the path of the file dump
- ## i.e.:
- ## /usr/sbin/filecleanup.sh /path/to/audio/dump
- cd $1
- dj_mixes="./djmixes"
- if [ ! -e $dj_mixes ]; then
- mkdir ./dj_mixes
- fi
- touch ./filecleanup.log
- timestamp=`date`
- echo "******* "$timestamp" file cleanup begun *******" >> ./filecleanup.log
- for i in ./*
- do
- file_format=`ls "$i" | tr ' ' '_' | tr '[A-Z]' '[a-z]' | cut -d'.' -f3`
- tag=`id3v2 -l "$i" | cut -d':' -f2`
- if
- [ "$tag" == " No ID3 tag" ]
- then
- tagged="false"
- else
- tagged="true"
- fi
- let file_size=`du -b "$i" | cut -f1`
- let max_file_size=20971520
- if
- [[ "$file_format" == "m4a" || "$file_format" == "mp3" || "$file_format" == "flac" || "$file_format" == "ogg" ]]
- then
- if [ $file_size -ge $max_file_size ]
- then
- mv "$i" "$dj_mixes"
- echo ""$timestamp" File "$i" moved to directory "$dj_mixes"" \
- >> ./filecleanup.log
- elif
- [[ $file_size -lt $max_file_size && $tagged == "true" ]]
- then
- name_field=`id3v2 -l "$i" | grep TP1 | cut -d':' -f2`
- artist_name=`echo $name_field | tr ' ' '_' | tr '[A-Z]' '[a-z]'`
- if
- [ -e ./$artist_name ]
- then
- mv "$i" ./$artist_name
- echo ""$timestamp" File "$i" moved to directory "$artist_name"" >> ./filecleanup.log
- else
- mkdir ./$artist_name
- mv "$i" ./$artist_name
- echo ""$timestamp" Directory "$artist_name" created" >> ./filecleanup.log
- echo ""$timestamp" File "$i" moved to directory "$artist_name"" >> ./filecleanup.log
- fi
- elif
- [[ $file_size -lt $max_file_size && tagged == "false" ]]
- then
- echo ""$timestamp" File "$i" is not tagged. Ignoring this file." >> filecleanup.log
- fi
- else
- echo ""$timestamp" Format of file "$i" ("$file_format") unrecognized. Ignoring this file." >> ./filecleanup.log
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment