bash script to insert id3 tags from file and directories
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
thanks but i dont know how to connect it to the id3tool
these are the arguments:
id3tool [<options>] <filename>
-t, --set-title=WORD Sets the title to WORD
-a, --set-album=WORD Sets the album to WORD
-r, --set-artist=WORD Sets the artist to WORD
-y, --set-year=YEAR Sets the year to YEAR [4 digits]
See if this works; the 'echo' command in front of 'id3tool' is to allow the script to be tested without writing the tags.
If the output is OK just remove the 'echo'.
Code:
#!/bin/bash
for fn in "/home/mp3s/artist/album/"*.mp3
do
if [ -f "$fn" ];then
p='.*/\([^/]*\)'
title=$(echo "$fn" | sed "s%$p\.mp3$%\1%")
album=$(echo "$fn" | sed "s%$p/$title\.mp3$%\1%")
artist=$(echo "$fn" | sed "s%$p/$album/$title\.mp3$%\1%")
# Remove 'echo' from next line after testing script
echo id3tool -t "$title" -a "$album" -r "$artist" "$fn"
fi
done
Thanks Kenhelm, this is working. The last thing i guess would be to have the script read the folders the files are in so that i dont have to edit the script everytime.
I guess this is simple but i dont know how to do it.
for example if file is in
/home/user/domain/mp3s/artist/album/file.mp3
the script would ignore
/home/user/domain/mp3s/
and use the folders and filename after that to tag the mp3.
thanks. i guess this is taking the last filenumber and using it to insert tracks???
that is good but not exactly what i need because some of my files dont have a number and are mixed with many others.
i would prefer if the script would just read the file list using "ls" and add tracks to all files in order.
For the record, krename can rename files using id3/metadata tags and directory structures. Most gui tagging tools such as easytag and audiotagtools can also rename files from tags, and I believe you can usually add a directory path to the name with some of them as well.
I wondered if someone could help me. I have all my songs organized like this: <artist>/<album> (<year>)/<track number> <title>.mp3
EXAMPLE Aphex Twin/Windowlicker (1999)/01 Windowlicker.mp3
...with the exception that I sometimes do not include the year, like this: <artist>/<album>/<track number> <title>.mp3 (if this isn't possible, let's say I always include the year)
In addition I would like all previous ID3 tags other than artist, album, year, track number and title to be removed, before the mentioned ones are applied.
What would the script look like then?
Code:
-t, --set-title=WORD Sets the title to WORD
-a, --set-album=WORD Sets the album to WORD
-r, --set-artist=WORD Sets the artist to WORD
-y, --set-year=YEAR Sets the year to YEAR
-n, --set-note=WORD Sets the note to WORD
-g, --set-genre=INT Sets the genre code to INT
-G, --set-genre-word=WORD Sets the genre to WORD
-c, --set-track=INT Sets the track number to INT
Also, I'm not a programmer in any way, so some guidance into how to execute scripts with id3tool is welcome. ;)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.