Jump to content

Need help with a simple script [solved]


Recommended Posts

I have bunch of mp3 files that need renaming and tagging (ID3v2). So far I've done this manually - something like:

 

mv track_04.mp3 Ray_Lowe_04.mp3

 

because there's no current tags so all tracks are just track_xx.mp3 and then:

 

id3 -12 -v -t "CJ Mobilise" -a "CJ Mahaney" -l "Brighton 2005" -n 4 -y 2005 -g "Sermon" cj_mobilise_02.mp3

 

to add the tags.

 

The trouble is - each CD contains well over 30 tracks and it gets labourious - I was wondering if someone could help me knock up a simple script to do this for me?

 

Basically I need to loop over all tracks called track_xx.mp3 (where x is the track number) and change them to <other_title>_xx.mp3

 

I then need to add the tags where the track number will obviously be different for each track and the -n parameter will be different. the -n will be n++ every time; so if we start with number 5 then the next will be 6 and so on...

 

Anyone able to help? I'm happy to tweka the script for each set of tracks to change the new filename etc... - that's still much easier than doing what will end up being over 100 tracks by hand...

Link to comment
Share on other sites

The first part's easy:

rename track_ Ray_Lowe_ track*.mp3

For the second part you'll need a bit of bash trickery, but I'm not quite sure how the id3 command works - are all those other parameters staying the same (apart from track number) or do you want to fill in the track title for each one as well?

Link to comment
Share on other sites

It's a bit dirty, but I think it should work. Just save this as a file in the same directory, as "myscript.sh":

#!/bin/bash

let "trackNum=0"
for file in Ray_Lowe_*
do
   let "trackNum+=1"
   echo "Processing track \"$trackNum\" file \"$file\""
   id3 -12 -v -t "CJ Mobilise" -a "CJ Mahaney" -l "Brighton 2005" -n $trackNum -y 2005 -g "Sermon" $file
done

Then you can call it with "sh myscript.sh" - but of course you'll need to edit the Ray_Lowe_ bit of the loop and also the id3 call.

Basically it assumes that all the files are consecutively numbered, so it keeps a counter as it loops through all the files it finds. It's pretty dumb, so it would get confused if it only finds tracks 1, 3 and 5! For another album you'll need to make sure you change both bits, the loop _and_ the id3 call. Fingers crossed! Maybe try it out on copies of the files first?

 

About the rename, yeah it's pretty useful. In case it wasn't obvious, the first parameter is the text to look for in the filename, the second is what to replace it with, and the third says which files to apply the change to.

Edited by neddie
Link to comment
Share on other sites

edit: found a typo in the loop command - the square brackets around the Ray_Lowe_ shouldn't have been there. Hopefully noone noticed :unsure:

True, krename is very useful, I use it a lot for photos. You know the story, you've got a bunch of photos from your holiday with numbered filenames, and then the other people on the holiday give you copies of theirs too. Except now they're all out of order - you can't sort by filename and if you sort by date then all the modified ones, stuck-together-panoramas etc are at the end. Krename lets you manually get them into the right order, and then give them a numbered filename, then the slideshows come out as expected! v useful.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...