Want more features on Pastebin? Sign Up, it's FREE!
Guest

mp3ify PKGBUILD

By: a guest on Jul 10th, 2011  |  syntax: Bash  |  size: 2.12 KB  |  views: 78  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print  |  QR code  |  clone
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. # Contributor: Thiago Okada <thiago DOT mast3r AT gmail DOT com>
  2.  
  3. pkgname=mp3ify
  4. pkgver=0.1
  5. pkgrel=1
  6. pkgdesc="Converts directory structures with a lot of audio formats to mp3"
  7. url="https://wiki.archlinux.org/index.php/Convert_Any_To_Mp3"
  8. arch=('i686' 'x86_64')
  9. license=('GPL')
  10. depends=('lame' 'mutagen' 'mplayer')
  11. provides=('mp3ify')
  12.  
  13. build() {
  14.         echo "#!/bin/bash
  15.  
  16.         DEFAULT_OUTPUT_DIR=/tmp/mp3ify
  17.         VBR_QUALITY=0
  18.  
  19.         function any_to_mp3 {
  20.  
  21.         PIPE=\`mktemp -u -t mp3ify.pipe.XXXXXX\`
  22.         mkfifo \"\$PIPE\"
  23.  
  24.         mplayer -ao pcm -ao pcm:file=\"\$PIPE\" \"\$INPUT_FILE\" -noconsolecontrols > /dev/null 2>&1 &
  25.  
  26.         lame --vbr-new -V \$VBR_QUALITY \"\$PIPE\" \"\$OUTPUT_FILE\" > /dev/null 2>&1
  27.  
  28.         rm \"\$PIPE\"
  29.  
  30.         python2 -c \"
  31. import mutagen
  32. input = mutagen.File(\\\"\$INPUT_FILE\\\", easy = True)
  33. output = mutagen.File(\\\"\$OUTPUT_FILE\\\", easy = True)
  34. for tag in [ 'artist', 'album', 'tracknumber', 'date', 'genre', 'title', 'comment' ]:
  35.  value = input.get(tag)
  36.  if value: output[tag] = value[0]
  37. output.save(v1=2)\"
  38.         }
  39.  
  40.  
  41.                 function usage {
  42.  
  43.                 echo \"mp3ify <input_dir> [<output_dir>]
  44.  
  45.                 Transforms structure <input_dir>/X/Y/.../Z into structure <output_dir>/X/Y/.../Z
  46.                 according to the following rules:
  47.  
  48.                 flac, ogg, m4a, ape, aac, mpc files will be encoded to mp3 preserving tags.
  49.  
  50.                 Everything else will be copied without modification.
  51.  
  52.                 Requires: mplayer, lame, mutagen.
  53.                 \"
  54.                 exit 1
  55.         }
  56.  
  57.  
  58.         INPUT_DIR=\"\$1\"
  59.         [ -d \"\$INPUT_DIR\" ] || usage
  60.         OUTPUT_DIR=\"\${2:-\$DEFAULT_OUTPUT_DIR}\"
  61.  
  62.         find \"\$INPUT_DIR\" -name '*.*' | while read INPUT_FILE
  63. do
  64.         INPUT_EXTENSION=\"\${INPUT_FILE##*.}\"
  65.         OUTPUT_FILE=\"\$OUTPUT_DIR/\${INPUT_FILE#\$INPUT_DIR}\"
  66.         mkdir -p \"`dirname \"\$OUTPUT_FILE\"`\"
  67.  
  68.         case \$INPUT_EXTENSION in
  69.                 flac|m4a|ogg|ape|aac|mpc)
  70.                         OUTPUT_FILE=\"\${OUTPUT_FILE%.\$INPUT_EXTENSION}.mp3\"
  71.                         echo -n \"Converting \${INPUT_FILE##*/}... \"
  72.                         any_to_mp3
  73.                         ;;
  74.                 *)
  75.                         echo -n \"Copying \${INPUT_FILE##*/}... \"
  76.                         cp \"\$INPUT_FILE\" \"\$OUTPUT_FILE\"
  77.                         ;;
  78.         esac
  79.  
  80.         echo \"done.\"
  81. done
  82. " > mp3ify
  83. }
  84.  
  85. package() {
  86.         mkdir -p ${pkgdir}/usr/bin
  87.         install ${srcdir}/mp3ify ${pkgdir}/usr/bin
  88. }
clone this paste RAW Paste Data