Skip to content

Instantly share code, notes, and snippets.

@andrewshatnyy
Created June 25, 2012 04:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andrewshatnyy/2986563 to your computer and use it in GitHub Desktop.
Save andrewshatnyy/2986563 to your computer and use it in GitHub Desktop.
MP3 encoder with image processing

Wave to Mp3 encode

This is folder based encoder script written in bash/zsh that allows you to encode bunch of Wave files to MP3 with ID3 and embedded artwork.

Protocol

  • Script has to be ran inside of the folder named: CATALOGUE####] Artist Name - Album Name

  • The structure inside forlder should look like that: Artist Name - Track name.wav Track itself CATALOGUE####.jpg artwork for the release (any size) it will resize it to 300x300 anyway}

How to use

Simply make it executable and run inside of the folder.

% chmod +x mp3enctag Drop this file in folder with wave files and artwork.jpg you need to process % ./mp3enctag

You could also use apple automator in order to automate the process

#Dependencies

  • lame
  • sips
  • mp3splt
#!/bin/bash
#This program used for resizing and batch wave -- mp3 encoding
#Please make sure you have
#* lame
#* sips
#* mp3splt
#installed before run it
##Author Andrew Shatnyy
year=$(date +"%Y") #today's year tag for ID3v2
comment="Property of nuwax records ${year} (c)" #comment tag for ID3v2
echo
echo "***********************************************"
echo "* Nuwaxrecords encoder *"
echo "* ${comment} *"
echo "* Author: Andrew Shatnyy *"
echo "***********************************************"
echo
function getTotal {
# counts total tracks in forlder
t=1 #counter total for track numbers
for c in *.wav; do
tt=$((t++))
done
}
#fetching release namebased on working derictory and its naming format:
# [Catalogue ##] Artist Name - Album name
function getReleasename {
#assiging script absolute path to variable
# basefolder=$(dirname "$0"|tr " " "\ "|tr "(" "\("|tr ")" "\)")
#echo "basefolder is: "${basefolder}
# relesename=$(echo ${basefolder} |cut -d- -f2| cut -c2-)
# catalogue=$(echo ${basefolder} |cut -d"[" -f2 |cut -d"]" -f1)
relesename=$(echo basename `pwd` |cut -d- -f2| cut -c2-)
catalogue=$(echo basename `pwd` |cut -d"[" -f2 |cut -d"]" -f1)
#catalogue=${catalogue}
#cd script to workfolder
cd "${basefolder}"
#pwd
echo
echo "***********************************************"
echo "Release name is: ${relesename}"
echo "***********************************************"
echo
}
function resize {
#resizing a file
sips -z 300 300 "${catalogue}.jpg" --out "${catalogue}_300.jpg"
artwork="${catalogue}_300.jpg"
}
function encode {
#encoding process
echo
echo "Starting encoding ${filename}"
echo "***********************************************"
echo
lame "$file" "${encodedFile}" -c -b 320 --tg "house" --tt "${title}" --ta "${artist}" --tn "${ct}/${tt}" --tl "${relesename}" --ty "${year}" --ti "${artwork}" --tc "${comment}"--add-id3v2
}
function process {
#main encoding loop
n=1 #counter for track numbers
for file in *.wav; do
#file=$(echo $file|cut -d] -f2|cut -d/ -f2)
#echo "Working on file "${file}
ct=$((n++))
artist=$(echo $file |cut -d- -f1 | cut -d" " -f2)
title=$(echo $file |cut -d- -f2|cut -d. -f1|cut -c2-)
filename=$(echo $file |cut -d\. -f1|tr " " "_")
encodedFile="./${fold}/${filename}.mp3"
echo "***********************************************"
echo "* Track info "
echo "* Artist: "${artist}
echo "* Title: "${title}
echo "* Combined filename: ${filename}"
echo "***********************************************"
encode
done
echo "***********************************************"
echo "*encoding has finished <<<<<<<<<<<<<<<<<<<<<<<*"
echo "***********************************************"
}
function makeFolder () {
#creates folder for encoded mp3s
fold="320"
mkdir ${fold}
}
function chopMp3 {
echo
echo "***********************************************"
echo "Chopping file to a sapmples 2 min long *"
echo "***********************************************"
echo
#mp3split will create 320chops folder with output files in it
for mp3 in ./320/*.mp3 ;do
mp3splt -d 320chops ${mp3} 01.00 03.00
done
}
function check () {
#checking if files are on place
if [ -e ./${catalogue}.jpg ];then {
echo "***********************************************"
echo "* Artwork was found *"
echo "* *"
# Something wrong with the if statement
# if [ -e ./*.wav ];then {
echo "* Wave files were found *"
echo "***********************************************"
getTotal
resize
makeFolder
process
chopMp3
# } else {
# echo "Wave files are missing there's nothing to encode"
# }
# fi
} else {
echo "Missing artwork sorry..."
}
fi
}
getReleasename
check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment