Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.88 KB | None | 0 0
  1. #!/bin/ksh
  2. #
  3. # Re-encode mp3 files shipped by EVE Online's Windows client for use with wine
  4. # Run in ~/.wine/drive_c/Program\ Files/CCP/EVE/res/audio/Jukebox
  5. #
  6. # Copyright 2011 Waveclaw.net
  7. # License: GPL
  8. # Warranty: not suitable for any purpose, use at your own risk!
  9. #
  10. # Version History
  11. #
  12. # 2005-08-11 JDP mangle-sound.sh based on _Linux_Server_Hacks_
  13. #        2003 Rob Flickenger, O'Reilly
  14. # 2009-03-24 JDP Convert id3v2 to getMplayerID Perl script for tags
  15. # 2011-02-10 JDP Specialize mangle-sound.sh for remasting Eve files
  16. # 2011-02-11 JDP Posted Stripped Version to pastebin
  17. # 2011-02-12 JDP Replace getMplayerID perl script with mplayer
  18. # 2011-02-13 JDP Cleanup, restore comments and repost to pastebin
  19. # 2011-02-15 JDP Fix backwards variable substitution in get_all_tags
  20. #
  21. PATH=/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/sbin:~/bin
  22. EXT=mp3
  23. DATE=`date +%Y%m%d`
  24. BACKUP_LOCATION=backup.$DATE
  25.  
  26. if [ 0 -eq $UID ];
  27. then
  28.     echo "Please do not run `basename $0` as root!"
  29.     exit;
  30. fi
  31.  
  32. is_installed() {
  33.  PROGRAM=$1
  34.  PATHNAME=$( type $PROGRAM 2> /dev/null )
  35.  if [ -z "$PATHNAME" ]; then
  36.   echo "cannot locate $PROGRAM in path"
  37.   exit 1
  38.  fi
  39. }
  40.  
  41. get_tag() {
  42.  TAG=$1
  43.  FILE=$2
  44.  $MPLAYER -vo null -ao null -frames 0 -identify $FILE 2>/dev/null \
  45.   | grep "${TAG}:" | sed -e "s/${TAG}: //g"
  46. }
  47.  
  48. get_all_tags() {
  49.  FILE=$1
  50.  TITLE=`get_tag Title "$FILE"`; TITLE=${TITLE:-"$FILE"}
  51.  COMMENT=`get_tag Comment "$FILE"`; COMMENT=${COMMENT:-'Unknown'}
  52.  ALBUM=`get_tag Album "$FILE"` ; ALBUM=${ALBUM:-'EVE Online'}
  53.  ARTIST=`get_tag Artist "$FILE"` ; ARTIST=${ARTIST:-'Jon Hailur'}
  54. #No Year, Genre or Track on Eve files
  55. # YEAR=`get_tag Year "$NAME"`
  56. # GENRE=`get_tag Genre "$FILE"`'
  57. # TRACK=`get_tag Track "$NAME"`
  58.  YEAR=`date +%Y`
  59.  GENRE=soundtrack
  60.  TRACK="${FILE#Ambient}"
  61.  TRACK="${TRACK%%.$EXT}"
  62. }
  63.  
  64. decode_file() {
  65.  FILE=$1
  66.  $MPLAYER -vc null -vo null -ao pcm:fast $FILE 2>&1 >/dev/null
  67.  mv audiodump.wav "${FILE%%.$EXT}.wav"
  68. }
  69.  
  70. encode_file() {
  71.  FILE="${1%%.$EXT}"
  72.  $LAME "$FILE.wav" --tt "$TITLE" --tl "$ALBUM" --ta "$ARTIST" \
  73.        --tg "$GENRE" --ty "$YEAR" --tn "$TRACK"
  74.  mv "$FILE.wav.$EXT" "$FILE.$EXT"
  75. }
  76.  
  77. is_installed mplayer
  78. MPLAYER=`which mplayer`
  79. is_installed lame
  80. LAME=`which lame`
  81.  
  82. mkdir -p $BACKUP_LOCATION
  83.  
  84. echo "Remastering all MP3 files in current directory!"
  85. echo "Originals backuped up to $BACKUP_LOCATION"
  86.  
  87. for NAME in *.${EXT};
  88. do
  89.  echo "Processing $NAME"
  90.  echo "--------------------------------------------------------------"
  91.  
  92. # tags
  93.  get_all_tags $NAME
  94.  echo "Title: $TITLE"
  95.  echo "Genre: $GENRE"
  96.  echo "Comment: $COMMENT"
  97.  echo "Album: $ALBUM"
  98.  echo "Artist: $ARTIST"
  99.  echo "Year: $YEAR"
  100.  echo "Track: $TRACK"
  101.  
  102. # convert
  103.  decode_file "$NAME"
  104.  
  105. # backup
  106. if [ -d "$BACKUP_LOCATION" ]
  107. then
  108.  mv "$NAME" "$BACKUP_LOCATION"
  109. else
  110.  echo "Could not backup $NAME"
  111.  exit 1
  112. fi
  113.  
  114. # replace
  115.  encode_file "$NAME"
  116.  
  117. # cleanup
  118.  rm "$FILE.wav"
  119. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement