Advertisement
Guest User

Untitled

a guest
Jan 25th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.01 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. ## REQUIREMENTS mp3info
  4. ## SOURCE:  https://unix.stackexchange.com/a/95907/20107
  5. ## USAGE: findmp3.sh 3:00 3:15 music/
  6.  
  7. ## Convert MM:SS to seconds.
  8. ## The date is random, you can use your birthday if you want.
  9. ## The important part is not specifying a time so that 00:00:00
  10. ## is returned.
  11. d=$(date -d "1/1/2013" +%s);
  12.  
  13. ## Now add the number of minutes and seconds
  14. ## you give as the first argument
  15. min=$(date -d "1/1/2013 00:$1" +%s);
  16. ## The same for the second arument
  17. max=$(date -d "1/1/2013 00:$2" +%s);
  18.  
  19. ## Search the target directory for files
  20. ## of the correct length.
  21. find "$3" -name "*mp3" |
  22.   while IFS= read -r file; do
  23.    length=$(mp3info -p "%m:%s" "$file");
  24.    ## Convert the actual length of the song (mm:ss format)
  25.    ## to seconds so it can be compared.
  26.    lengthsec=$(date -d "1/1/2013 00:$length" +%s);
  27.  
  28.    ## Compare the length to the $min and $max
  29.    if [[ ($lengthsec -ge $min ) && ($lengthsec -le $max ) ]]; then
  30.        echo "$file :: $length";
  31.    fi;
  32. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement