Guest User

Untitled

a guest
Apr 20th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.43 KB | None | 0 0
  1. #!/bin/sh
  2. for file ; do
  3. # We take every file we're given and...
  4.  
  5. echo "FLAC'ing" $file
  6. # ...let the user know we've started working on it...
  7.  
  8. EXT=`echo $file | ruby -e "puts STDIN.read.scan(/([^.]*)$/)"`
  9. # find out wether its name ends in ".wav" or ".aif"
  10.  
  11. COMP_FILE="$file~comp.$EXT"
  12. # remember this for when we need to make the temp file to compare with
  13.  
  14. flac --keep-foreign-metadata "$file" -o "$file~.flac" 2>/dev/null
  15. # We flac the file using the "--keep-foreign-metadata" option
  16. # so all of our magic Pro Tools, broadcast wav, Soundminer and
  17. # descriptive metadata is saved into the final product
  18. #
  19. # We supress FLAC's informative output on account of its obnoxiousness
  20.  
  21. if [[ $? != 0 ]]
  22. # if flac returned an error...
  23.  
  24. then echo " >>>>>> FLAC FAILED TO COMPRESS FILE"
  25. # let the user know, and...
  26.  
  27. continue
  28. # move on to the next file
  29. fi
  30. # Now that we've checked that, we can go on to making sure that the file
  31. # we've made decompresses into a file that matches our original, bit-for-bit
  32.  
  33. echo "Roundtrip-comparing original to FLAC" $file
  34. # Let the use know how far we've gotten
  35.  
  36. flac -d --keep-foreign-metadata "$file~.flac" -o "$COMP_FILE" 2>/dev/null
  37. # We de-compress our temporarily-created FLAC file and save it, using
  38. # the file name we constructed all the way up on line 11
  39.  
  40. if test -e "$COMP_FILE";
  41. # if Flac actually decompressed the file
  42. then diff "$COMP_FILE" "$file"
  43. # run diff between the file we started with and the end result of a
  44. # complete compress-decompress run
  45. if [[ $? = 0 ]]
  46. # if diff had no error
  47. then echo "****** Comparison succeeded"
  48. # let the user know
  49. mv "$file~.flac" "$file.flac"
  50. # give our temporary flac file a permanent name...
  51. rm "$file"
  52. # and delete the file we started with, secure in the knowledge that
  53. # that recovering it is possible
  54. else echo " >>>>>> COMPARISON FAILED!!!"
  55. # otherwise, if diff DID return an error, indicating the files are
  56. # NOT the same
  57. rm "$file~.flac"
  58. # remove the temporary FLAC file we made
  59. fi
  60. rm "$COMP_FILE";
  61. # remove the file we temporarily decompressed from our flac file, wether
  62. # it was good or not
  63. else echo " >>>>>> FLAC FAILED TO DECOMPRESS THE FILE TO COMPARE"
  64. # if the flac -d invocation (remember that online 40?) never suceeded in
  65. # decompressing the file, let the user know
  66. continue
  67. # go to the next file on our to-do list
  68. fi
  69. # we end up here if everything worked...
  70. done
Add Comment
Please, Sign In to add comment