LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (http://www.linuxquestions.org/questions/linux-software-2/)
-   -   mp3's created with kaudiocreator play in wrong order (http://www.linuxquestions.org/questions/linux-software-2/mp3s-created-with-kaudiocreator-play-in-wrong-order-666150/)

MartyJay 08-28-2008 05:32 PM

mp3's created with kaudiocreator play in wrong order
 
I am running Debian Etch with KDE, and I was successful ripping my CD's to MP3's with kaudiocreator, but there seems no logic in the way they r played back on my MP3 player. The same MP3's ripped with Windows Media Player play in the right order. I have checked the track numbers, but they are the same for MP3's ripped with kaudiocreator or windows media. I have tried renaming the files but nothing seems to work. They r not played alphabetically either. I tried ripping the songs 1 by 1, but it still will play in the wrong order. And it takes too long. Anyone got any ideas? I ran out of them...

David the H. 08-29-2008 03:06 AM

I've seen the same problem before with a friend's mp3 player, and it had nothing to do with the encoding (how could it, since they're all separate, individual files?). It was a cheap little no-brand flash player, and the order it played in was the order the files were loaded into the player. For some reason Linux doesn't seem to always transfer files in the same order that they exist in the directories. I guess is uses some kind of internal ordering system, perhaps last-accessed-time or something. I don't know.

jomen 08-29-2008 03:59 AM

I'm having this wierd behavior too with some cheap player - it is really annoying. I never figured out the criteria how it seems to shuffle the order it plays the files.
It even lists them in a random order. Did not have the chance to try the copying using Windows since I don't have a copy.
Will test the theory by copying the files individually.

jomen 08-29-2008 04:39 AM

Quote:

Will test the theory by copying the files individually.
indeed it is the behaviour of "cp" - it copies the files ordered not by name but by some other criteria.

The player treats the files not by name but by time of copying them to it - If copied in order, they will play in order. They will play in whatever order they where copied to it.

Can the cp command easily be changed to copy in the order ls would display the files by name?
How does cp determine the order?

jomen 08-29-2008 06:40 AM

a partial solution is to touch all the files in alphabetical order:
ls * | touch *
this will only work when inside the directory where the files are.

Can anyone help with an idea on how to do this recursively for the entire collection?
There are usually directories namend after the artist - inside is one named after the album and inside that are the files.
The directory names as well as the file names contain whitespace.

I'm not experienced enough in bash to do this - I'm stuck with:

find -type d -exec _the commands_ to change into it and do the "ls * | touch *"{} \;

matthewg42 08-29-2008 08:21 AM

It might be that the files are playing in the order of the modification date stamp on the file.

Open a terminal, change to the directory where the device is mounted and do:
Code:

ls -ltr
If the order is the same as the files get played, then that's probably what is happening.

Check the original files (where they are on your hard disk). If the times are the same, then whatever copy procedure you are using is preserving the time stamps. If this is the case, then all you need to do it touch the originals in the correct order.

However, if the time stamps are being set when the files are getting copied to your player, you must do something each time you copy the files.

Here a good naming convention on the original file names will help.

For example, if you use the track number with leading 0's at the start of the file name, you can easily write a little program to do the touching...

e.g. original files:
Code:

01_trackname.mp3
02_trackname.mp3
03_trackname.mp3
04_trackname.mp3
05_trackname.mp3
06_trackname.mp3
07_trackname.mp3
08_trackname.mp3
09_trackname.mp3
10_trackname.mp3
11_trackname.mp3

You can write a script which looks at each file and touches it in turn, like this:
Code:

#!/bin/bash

media_root=${1?Please specify media device root as parameter}
base_date=$(date)
find $media_root -type d | while read dir; do
        cd "$dir"
        n=1
        ls |sort -r |while read file; do
                echo touch -t $(date --date="$base_date - $n seconds"  +%Y%m%d%k%M%S) "$file"
                let n+=1
        done
        cd -
done

If you use amarok to copy files, you can get it to automatically run such a script with the "post-disconnect command" option.

matthewg42 08-29-2008 08:21 AM

Oh by the way, if there are no track numbers in the file name, you might be able to write some program for getting the track number from the id3 tags if it is set.

jomen 08-29-2008 08:51 AM

Thank you matthewg42 !

It looks like this is what should work - however it does not for me right now.
ls -ltr still shows the original dates after running the script.

But it could be that my mount-options might get in the way (?)
I have mounted my partitions with the "noatime" option.
Could this be a cause? I'll try removing it and check again.

Not now though because I need to leave now...thanks again!

matthewg42 08-29-2008 08:58 AM

Probably your media device is formatted with a FAT filesystem.

atime is access time. I am not 100% sure if FAT actually records this anyway, but if it does it is conceivable (although pretty weird!) that it might be looked at by your media player.

touch can modify either, I think. See what makes a difference (if anything does).

The two other things which a media player might looks at at the track number id3 tag, and the directory order.

Check to see if the windows-created files have a track id3 tag set.

If it's the directory order, the only thing to do is delete the directory which the files are in, re-create it, and make sure the files are copied in according to come order (try both forwards and backwards!)

David the H. 08-29-2008 04:26 PM

I spent a few minutes googling to see if anyone had written any good copy scripts that could be used here. No use reinventing the wheel after all. But while I came across several partial solutions I didn't find anything that would comprehensively work in all situations. I did come up with this little utility however: FATSort, which says it will reorganize the files directly on your player. It's available in the Debian and Ubuntu repositories.

If these players are anything like the one I played with, they don't use the id3 tags or filenames at all for playback order. They can usually read id3 tags, but only enough to display the artist and title during playback. They're simple, low-end players without a lot of bells & whistles, and limited options for organization and playback. They seem to simply read the files in the order they were written to and that's it (probably using the FAT file creation time). The problem here then is simply getting Linux to copy the files over in straight alphanumeric order in the first place. I wish I still had access to the player I used so I could play with it some more, but it's gone now.

Re: renaming files. There are several tagging applications like easytag and audiotagtools that can do batch renaming based on metadata. I also use krename sometimes. It has the ability to extract metadata for use in renaming files, and is useful for reorganizing the names to be more consistent overall; removing spaces and illegal characters, naming files from directory names, etc. (It's also handy for renaming digital camera images according to their creation date and such). Finally, there are a few cli applications like exiftool that can extract tag fields so that you can use them in scripts.

Now for a personal pet peeve of mine. One thing I always recommend to everyone is to always avoid using spaces in filenames (and other restricted characters, but spaces are the worst). Spaces always seem to make dealing with situations like this much more complicated than they would be otherwise. Scripting is so much easier when you don't have to worry about a command choking because it thinks there are 5 filenames instead of one. I usually use underscores in place of spaces myself.

Finally, regarding atime, it's a Unix relic and I'm almost certain FAT doesn't have any support for it (but I could be wrong, of course). It's generally a useless setting anyway. The idea that the file access time (and thus the file itself) has to be updated every time it's read is nothing but a performance waster. Most people recommend that disks be mounted with either the noatime or relatime mount options to disable it. Note that the atime flag will still get updated whenever the file is moved or modified, so it shouldn't break anything.

jomen 09-01-2008 04:07 AM

Quote:

They seem to simply read the files in the order they were written to and that's it (probably using the FAT file creation time). The problem here then is simply getting Linux to copy the files over in straight alphanumeric order in the first place.
That was what I wanted and did not know how to achieve.
The player I was talking about here behaves exactly like that.
I know all this about not having spaces in filenames and all and I rip all my stuff paying attention to that but sometimes one gets a few pieces of music from friends and they do not bother because they don't see the need (there really is no need - it just makes things harder sometimes).
Quote:

regarding atime, it's a Unix relic and I'm almost certain FAT doesn't have any support for it
Yes - I was only wondering if me having my filesystems mounted with "noatime" could cause the script to fail do its work.
The script from matthewg42 seems to work well.
I also came across http://fatsort.berlios.de/ while I was looking for a solution. I simply did not figure it out from the short description that this was what I wanted.
Read too quickly...
This tool does the same job and I now have two good solutions to this problem.

Thank you all!

Takla 09-01-2008 10:30 AM

Very interesting thread :-)

fatsort is great, I'm happy to have discovered it just now.

And here's another solution:

This is only good for people who keep songs from a CD or compilation together in directories. If your mp3 player just contains a long list of tracks this is no help.

Instead of copying over a directory to the mp3 player, first create the directory on the player, then copy the tracks in to that directory. i.e.

mkdir /media/mymp3player/artist-album

cp artist-album/*.mp3 /media/mymp3player/artist-album

The tracks will now be sorted by filename (01,02,03 etc)

Of course this doesn't mean the directories will be sorted correctly, only the files within. It's what I was doing before I found fatsort here. It has the benefit of working on any OS without needing any extra application, only a command prompt or file manager.

MartyJay 09-08-2008 12:20 PM

thanks all
 
:D Now I have something to work with. I am going to try some things. fatsort sounds interesting

hit100 09-11-2008 10:15 AM

Wrong ID3-Tag?
 
Maybe it's the wrong id3-tag.
Maybe your player needs ID3-tag V2 and your mp3-songs have the id3-tag V1.
That seems to be the reason why i have the same problem.
My player tells me about title, album, ... : unknown.
My ID3-v1.1-tags are o.k, but the ID3-v2-tags are empty.
You can see this e.g. in kid3.

jmfv 10-31-2008 06:08 AM

+1 fatsort!

I had this problem with Grundig MPAxx703
and TEAC MP-370, fatsort quickly solved it!


All times are GMT -5. The time now is 06:19 PM.