Unix Technical Forum

A script renaming mp3 files according to their track number

This is a discussion on A script renaming mp3 files according to their track number within the Gentoo Linux Support forums, part of the Unix Operating Systems category; --> Hello Newsgroup, I just got a new portable mp3 player and I really like listening to music everywhere I ...


Go Back   Unix Technical Forum > Unix Operating Systems > Gentoo Linux Support

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-21-2008, 11:32 AM
Daniel =?ISO-8859-1?Q?B=F6hmer?=
 
Posts: n/a
Default A script renaming mp3 files according to their track number

Hello Newsgroup,

I just got a new portable mp3 player and I really like listening to
music everywhere I am. When I ripped the mp3 files (I do really own all
of those CDs but I don't like using CDs due to the risk of scratching) I
made my ripping program naming them this way:

Pink Floyd - High Hopes.mp3
or in general: Artist - Track title.mp3

The mp3 player is not able to handle track lists or recognize the track
numbers which are stored as ID3 tags.

Is anybody of you able and likely to write a little shell script or
anything like that which would rename the tracks beginning with the
track number? Example:

09 Pink Floyd - High Hopes.mp3
or in general: ## Artist - Track title.mp3


This would help my very much because I really don't want to rip all of
my CDs another time. It's not that I buy all this senseless music or rip
every single track I can get but time by time I got a nice collection of
really good music -- it stills exists;-)


Grateful for any advice and help
Daniel Böhmer, Germany

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-21-2008, 11:32 AM
Jesper
 
Posts: n/a
Default Re: A script renaming mp3 files according to their track number

On 2006-06-19, Daniel Böhmer wrote:
> Is anybody of you able and likely to write a little shell script or
> anything like that which would rename the tracks beginning with the
> track number? Example:
>
> 09 Pink Floyd - High Hopes.mp3
> or in general: ## Artist - Track title.mp3


Not sure I can really help, but isn't that naming scheme going to be a
pain when it comes to sorting? For my own collection I decided that the
following would be a lot better:
Artist-Album-Track-Title.extension

With all non-alphanummeric and non-ascii characters removed or converted
so something more filesystem friendly. Eg. spaces converted to
underscores, and various Scandinavian characters changed to more
internationally readable characters (æ->ae, ø->oe, å->aa, etc).

In total, this means that even if I have to put all of the files in the
same directory (not by Artist/Album as I do now), on a non-ID3
compatible device, a simple alphanummeric sort by filename would still
list them appropriately. With your scheme, you'd have tracks from one
album mixed with tracks from other albums.

--
Jesper <xyborx+usenet@xyborx.dk>
"Do not meddle in the affairs of cats, for they are cunning, and you
sleep with your mouth open"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-21-2008, 11:32 AM
AZ Nomad
 
Posts: n/a
Default Re: A script renaming mp3 files according to their track number

On 19 Jun 2006 16:48:18 GMT, Jesper <xyborx+usenet@xyborx.dk> wrote:


>On 2006-06-19, Daniel B?hmer wrote:
>> Is anybody of you able and likely to write a little shell script or
>> anything like that which would rename the tracks beginning with the
>> track number? Example:
>>
>> 09 Pink Floyd - High Hopes.mp3
>> or in general: ## Artist - Track title.mp3


>Not sure I can really help, but isn't that naming scheme going to be a
>pain when it comes to sorting? For my own collection I decided that the
>following would be a lot better:
>Artist-Album-Track-Title.extension


>With all non-alphanummeric and non-ascii characters removed or converted
>so something more filesystem friendly. Eg. spaces converted to
>underscores, and various Scandinavian characters changed to more
>internationally readable characters (?->ae, ?->oe, ?->aa, etc).


>In total, this means that even if I have to put all of the files in the
>same directory (not by Artist/Album as I do now), on a non-ID3
>compatible device, a simple alphanummeric sort by filename would still
>list them appropriately. With your scheme, you'd have tracks from one
>album mixed with tracks from other albums.


I'm not the OP, but I put each album in it's own directory and use
track numers as a track prefix so that I can be sure that they'll
be played in the correct order.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-21-2008, 11:32 AM
Daniel =?ISO-8859-1?Q?B=F6hmer?=
 
Posts: n/a
Default Re: A script renaming mp3 files according to their track number


> I'm not the OP, but I put each album in it's own directory and use
> track numers as a track prefix so that I can be sure that they'll
> be played in the correct order.


That's exactly what I wanna do. The single files are in folders named
with the title of the album. Example:

root
+--Pink Floyd
+--The Division Bell
+--Pink Floyd - High Hopes.mp3
+--Pink Floyd - Marooned.mp3

Problem here is that "High Hopes" comes before "Marooned" by
alphabetical sorting but this is not the correct listing from the CD. I
want to keep the files in their folders but extend their names by the
track number. My mp3 player can handle folders but it's not able to sort
files by track number.

I hope you do now understand what the problem actually is and anybody
can help me.


Thanks
Daniel

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-21-2008, 11:32 AM
AZ Nomad
 
Posts: n/a
Default Re: A script renaming mp3 files according to their track number

On Mon, 19 Jun 2006 20:56:58 +0200, Daniel Böhmer <boehmerdaniel@web.de> wrote:



>> I'm not the OP, but I put each album in it's own directory and use
>> track numers as a track prefix so that I can be sure that they'll
>> be played in the correct order.


>That's exactly what I wanna do. The single files are in folders named
>with the title of the album. Example:


>root
>+--Pink Floyd
> +--The Division Bell
> +--Pink Floyd - High Hopes.mp3
> +--Pink Floyd - Marooned.mp3


>Problem here is that "High Hopes" comes before "Marooned" by
>alphabetical sorting but this is not the correct listing from the CD. I
>want to keep the files in their folders but extend their names by the
>track number. My mp3 player can handle folders but it's not able to sort
>files by track number.


>I hope you do now understand what the problem actually is and anybody
>can help me.


I already had a hard drive walkman that put the tracks in directories in
folders named by the genre. The directories were named artist_album.

I used a python script to scan the entire tree and in each folder put
numerical prefixes on each track, providing there wasn't already
a prefix.

It's a work in progress where I'm going to reset the ID3 tracks and eventually
move away from the artist_album directories. Here it is, as is. You
should be able to figure out how to modify it for your own use. Currently the
parts that change the id3 fields and do the rename are commented out.
Uncomment them out when the debugging printouts are correct.

#! /usr/bin/env python
import os, sys, string


if len(sys.argv) < 2:
sys.exit( "usage scan <topdir>" )

top=sys.argv[1]
for genre in os.listdir(top):
try:
for artist_album in os.listdir(top + "/" + genre):
underscore = string.find(artist_album, "_")
artist=artist_album[:underscore]
album=artist_album[underscore+1:]

print artist, "/", album
track=0
rename_tracknums=1
for filename in os.listdir( top+"/"+genre+"/"+artist_album ) :
if ( (filename[2:4] == ". ") & (filename[1]>="0") & (filename[1]<="9") )\
| ( (filename[2] == "_") & (filename[1]>="0") & (filename[1]<="9") ):
rename_tracknums=0

track=track+1

if filename[-4:] == ".mp3":
song=filename[:-4]
else:
song=filename

# os.system( 'id3v2 '+
print ( "id3v2 " +
'-a"'+artist +'" '+
'-A"'+album +'" '+
'-s"'+"%2d. "%track+song +'" '+
'-t"'+str(track) +'" '+
# '-g"'+genre +'" '+
'"'+top+"/"+genre+"/"+artist_album+"/"+filename+'"' )

if rename_tracknums:
# os.rename(\
print (
"rename "+ \
top+"/"+genre+"/"+artist_album+"/"+ filename +', '+
top+"/"+genre+"/"+artist_album+"/"+ "%2d. "%track+ filename )


except OSError, (errno, strerror):
print "err!"
pass


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-21-2008, 11:33 AM
Daniel =?ISO-8859-1?Q?B=F6hmer?=
 
Posts: n/a
Default Re: A script renaming mp3 files according to their track number

Hello,

> I already had a hard drive walkman that put the tracks in directories in
> folders named by the genre. The directories were named artist_album.
>
> I used a python script to scan the entire tree and in each folder put
> numerical prefixes on each track, providing there wasn't already
> a prefix.
>
> It's a work in progress where I'm going to reset the ID3 tracks and eventually
> move away from the artist_album directories. Here it is, as is. You
> should be able to figure out how to modify it for your own use. Currently the
> parts that change the id3 fields and do the rename are commented out.
> Uncomment them out when the debugging printouts are correct.


Thank you for posting the current state of your work. Might be helpful
for somebody but I cannot speak any word Python... So this script is not
really helpful for me.

I don't know how much work it is to change that script so that it does
what I actually wanted to do. Are you able and likely to do that for me?
I don't want to hustle you but it would be very friendly to help
somebody who has got no clue about Python.


Thanks for reading

Daniel Böhmer

> #! /usr/bin/env python
> import os, sys, string
>
>
> if len(sys.argv) < 2:
> sys.exit( "usage scan <topdir>" )
>
> top=sys.argv[1]
> for genre in os.listdir(top):
> try:
> for artist_album in os.listdir(top + "/" + genre):
> underscore = string.find(artist_album, "_")
> artist=artist_album[:underscore]
> album=artist_album[underscore+1:]
>
> print artist, "/", album
> track=0
> rename_tracknums=1
> for filename in os.listdir( top+"/"+genre+"/"+artist_album ) :
> if ( (filename[2:4] == ". ") & (filename[1]>="0") & (filename[1]<="9") )\
> | ( (filename[2] == "_") & (filename[1]>="0") & (filename[1]<="9") ):
> rename_tracknums=0
>
> track=track+1
>
> if filename[-4:] == ".mp3":
> song=filename[:-4]
> else:
> song=filename
>
> # os.system( 'id3v2 '+
> print ( "id3v2 " +
> '-a"'+artist +'" '+
> '-A"'+album +'" '+
> '-s"'+"%2d. "%track+song +'" '+
> '-t"'+str(track) +'" '+
> # '-g"'+genre +'" '+
> '"'+top+"/"+genre+"/"+artist_album+"/"+filename+'"' )
>
> if rename_tracknums:
> # os.rename(\
> print (
> "rename "+ \
> top+"/"+genre+"/"+artist_album+"/"+ filename +', '+
> top+"/"+genre+"/"+artist_album+"/"+ "%2d. "%track+ filename )
>
>
> except OSError, (errno, strerror):
> print "err!"
> pass
>
>


Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 02-21-2008, 11:33 AM
Thomas Jensen
 
Posts: n/a
Default Re: A script renaming mp3 files according to their track number

I use easytag to rename and retag my mp3's.

http://easytag.sourceforge.net/
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 02-21-2008, 11:33 AM
AZ Nomad
 
Posts: n/a
Default Re: A script renaming mp3 files according to their track number

On Thu, 22 Jun 2006 20:17:06 +0200, Daniel Böhmer <boehmerdaniel@web.de> wrote:


>Hello,


>> I already had a hard drive walkman that put the tracks in directories in
>> folders named by the genre. The directories were named artist_album.
>>
>> I used a python script to scan the entire tree and in each folder put
>> numerical prefixes on each track, providing there wasn't already
>> a prefix.
>>
>> It's a work in progress where I'm going to reset the ID3 tracks and eventually
>> move away from the artist_album directories. Here it is, as is. You
>> should be able to figure out how to modify it for your own use. Currently the
>> parts that change the id3 fields and do the rename are commented out.
>> Uncomment them out when the debugging printouts are correct.


>Thank you for posting the current state of your work. Might be helpful
>for somebody but I cannot speak any word Python... So this script is not
>really helpful for me.


Go to www.python.org and do an 'emerge python'.

Unless you're a moron, learning and using python is a snap.
Modify that script so that the debugging print statement output the
correct rename operation and then ncomment out the rename operation
when it looks right. Do a backup before going live, of course.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 02-21-2008, 11:33 AM
Bob
 
Posts: n/a
Default Re: A script renaming mp3 files according to their track number

Daniel Böhmer wrote:

> Is anybody of you able and likely to write a little shell script or
> anything like that which would rename the tracks beginning with the
> track number? Example:
>


I'd go with the 'anything like that' option here. I've tried the shell
script option before, but it's too hard to pinpoint all the screwed up
tags around the place.

Use EasyTag (try the gtk2 version) it is seriously the best out there. I
tried all the Windows ones, and some where pretty good, but EasyTag does
everything. It can do batch renaming et al if you're worried that a gui
one might take too long.

Also, I go for <artist name>.<year>.<album>.<track #>.<track name>.<ext>
so I'm not completely lost just in case all the files somehow get in the
one directory.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 02-21-2008, 11:36 AM
Lawrence D'Oliveiro
 
Posts: n/a
Default Re: A script renaming mp3 files according to their track number

In article <slrne9dlai.hvc.xyborx+usenet@cheetah.catden.dk> ,
Jesper <xyborx+usenet@xyborx.dk> wrote:

>... isn't that naming scheme going to be a
>pain when it comes to sorting?


I think this would be true of any naming scheme you might come up with.

Another approach might be to consider it relationally. Keep the MP3
files themselves in one directory, with arbitrary unique names assigned
(e.g. sequence numbers: 00001.mp3, 00002.mp3 ...) and then have separate
sets of directories organized by artist, album, style, mood etc, which
contain symlinks to the actual files.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 09:35 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com