Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- ## REQUIREMENTS mp3info
- ## SOURCE: https://unix.stackexchange.com/a/95907/20107
- ## USAGE: findmp3.sh 3:00 3:15 music/
- ## Convert MM:SS to seconds.
- ## The date is random, you can use your birthday if you want.
- ## The important part is not specifying a time so that 00:00:00
- ## is returned.
- d=$(date -d "1/1/2013" +%s);
- ## Now add the number of minutes and seconds
- ## you give as the first argument
- min=$(date -d "1/1/2013 00:$1" +%s);
- ## The same for the second arument
- max=$(date -d "1/1/2013 00:$2" +%s);
- ## Search the target directory for files
- ## of the correct length.
- find "$3" -name "*mp3" |
- while IFS= read -r file; do
- length=$(mp3info -p "%m:%s" "$file");
- ## Convert the actual length of the song (mm:ss format)
- ## to seconds so it can be compared.
- lengthsec=$(date -d "1/1/2013 00:$length" +%s);
- ## Compare the length to the $min and $max
- if [[ ($lengthsec -ge $min ) && ($lengthsec -le $max ) ]]; then
- echo "$file :: $length";
- fi;
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement