Script request: repair Date Added fields

GO TO ADMIN PANEL > ADD-ONS AND INSTALL VERTIFORO SIDEBAR TO SEE FORUMS AND SIDEBAR

mmueck

New member
Joined
May 18, 2005
Messages
10
Points
0
Hi,

After relocating my iTunes library to outside my home directory, all my Date Added fields changed to the same date (the date of the move). I discovered this a couple weeks later. The only way I can think of to get most of the way back to where things used to be is to have a script which goes through the library and changes each song's Date Added field to the song's unix file creation date.

I would be greatly indebited to anybody who knows of such a script or possibly even be able to write one. I'm just not versed in AppleScript and wouldn't know where to start...

Many thanks (in advance) :)

Mick.
 

mmueck

New member
Joined
May 18, 2005
Messages
10
Points
0
Even though it seems editing these dates is impossible from within iTunes, at the end of the day these are just files that needs modifying. I was kind of hoping that there was some scriptable file editor out there (hexedit?) that could be programmed up to read the unix creation date and somehow jam it into the music file's Date Added field. That info may very well be meta-data and so I'm probably way out of my league here.

Does the above spark any new thoughts?
 

moriond

New member
Joined
Oct 14, 2004
Messages
721
Points
0
mmueck said:
. . .at the end of the day these are just files that needs modifying. I was kind of hoping that there was some scriptable file editor out there (hexedit?) that could be programmed up to read the unix creation date and somehow jam it into the music file's Date Added field.
There are two files that iTunes uses for handling music library data. The actual file that iTunes itself works from, the iTunes Library file, is not in a format that users can work with directly and modify. This is the primary source of all the information that gets displayed when you pull up the View Options menu (Mac keyboard shortcut: cmd+j under iTunes.

The iTunes Music Library.xml file is a way for application programs to work with iTunes and you can examine this file in an editor. However, it doesn't contain all the information accessible to the iTunes Library file, and some fields like "Date Added" only report information; they can't be reset. iTunes must do some consistency checking (in the case of file corruption) in the face of apparently contradictory information -- like a "Date Added" which predates the creation date of these library files. This is why the AppleScript that I linked to copies the Creation Date information to the Comments field, since this is a field that can be modified.

Hope this helps to clarify things.
 

mmueck

New member
Joined
May 18, 2005
Messages
10
Points
0
I understand all the magic is in the iTunes Music Library.xml file. If I can figure out how to get the date info into a copy of that file then I can toss the iTunes Library file and recreate the library by importing the edited copy of the .xml file.

Does anybody know of a (hopefully free) scriptable xml editor that I could try for this purpose? I guess this is one way to finally get me into AppleScript. Is Automator also a possible solution? This is also a tool I've never used before.

Thanks.
 

moriond

New member
Joined
Oct 14, 2004
Messages
721
Points
0
mmueck said:
I understand all the magic is in the iTunes Music Library.xml file. If I can figure out how to get the date info into a copy of that file then I can toss the iTunes Library file and recreate the library by importing the edited copy of the .xml file.
Let me try again, because I must really not be explaining any of this clearly. Yes, the iTunes Music Library.xml is the file that you, as a user, can interact with. But it's not the primary file that iTunes itself uses. Instead, it's an intermediary step for communications between the iTunes Library file and other software. The fact that there is a field shown that reports the Date Added does not mean that if you change that value in the iTunes Music Library.xml that it will keep that value the next time you start iTunes. It will be cross-checked against the iTunes Library file, and the value will be reset, I think. That's what was meant by saying that the field is read only. You cannot arbitrarily reset all records that iTunes keeps in its database. iTunes does some internal cross-checking of records as a safeguard against corruption. So, for instance, if an aac audiobook track shows a creator code that indicates it was ripped from CD, and the Make Bookmarkable AppleScript reidentifies the file type to the system as .m4b (like audiobooks purchased from the iTMS instead of .m4a), that creator code will either get changed or the field will disappear from the .xml file because iTunes knows that such books aren't produced by CD rips; it's inconsistent information.

And you can get the date information into a copy of the file simply by using TextEdit, for the purposes of experiment (assuming you keep a separate backup copy of the .xml file). You could certainly perform the experiment of trying to change the Add date for one entry to a time before your move. I think you'll simply find that you won't be able to maintain this date once you start up iTunes, but it's worth a try. Good luck.
 
Joined
Jul 1, 2003
Messages
705
Points
0
Location
Providence, RI, USA
Website
dougscripts.com
There's really no way to change the Date Added. This dilemma (for some users anyway, I suppose) goes back to Day One. iTunes manages this information internally, as was mentioned above, in its database file. The XML file will also display this data. The thing about the XML file is that it is updated by iTunes. You could edit it and reimport it, but then iTunes would set the Date Added to ALL of your tracks to the date/time of the import. So you're back to square one.

The solution I always recommend is along the lines of what has already been suggested: use the Comments field for user-specific data.

FWIW, I have just posted Append Date to Comments which will assist with appending a user-entered date to the Comments field of selected tracks.
 

mmueck

New member
Joined
May 18, 2005
Messages
10
Points
0
Hi Doug,

Thanks very much for writing that script. Hopefully I've caught you while that effort is still fresh in your mind. Any chance of whipping up a related script - one that copies the song file's unix creation date to the comments field. I believe that all the lost iTunes Date Added information is identical to this info.

Thanks, Mick.
 

mmueck

New member
Joined
May 18, 2005
Messages
10
Points
0
So having enticed you to create this script, I got to thinking a little deeper. There are already many things I use the comments field for. I have a bunch of tilde codes that I have made up i.e. a given song's comment might be ~mm~vm~gh. I use these comments to create smart lists e.g. songs to put on my ipod will have ~mm in the comments field, songs for my daughter's ipod would have ~vm in the comments field, a song which is one of a particular group's greatest hits would have ~gh in the comments. I have taken quite some time to sort out all of this and the proposed script to overwrite the comments field with the file's creation date would mess things up royally for me. In addition, I suspect many other people have used the comments field for their own purposes. So I hunted around in the fields that can be changed and discovered that the 'Grouping' field (which I have never used in all the years I've owned an ipod) can accept pretty much any ASCII character. That would be a good target for the unix creation date text and I figure it wouldn't upset people as much as the comment field.

Sorry for the continued hassle...
 

Adamtg1

New member
Joined
Sep 3, 2007
Messages
2
Points
0
A suggestion for Setting the iTunes Date Added Field

Hello,

I also have a problem in that the date added field is pretty much worthless because I have formatted and had to import all my songs into iTunes. However, I am using iTunes on a PC not MAC.

There has been much discussion about modifying the date added field to match the created date of each mp3 but for numerous reasons this doesn't seem possible.

I've tried to think about how to achieve what many people want. It may seem like a slow route but surely it must work. Here goes......but it does require someone with some programming skills.


1) Write a little program to search though a directory containing all your mp3 files and create an array containing the filename and created date for all mp3 files.
2) Sort the array into date and time order
3) Then, with another little program set the computers clock to the date of the first mp3 and by using a mouse recording macro it should be possible to import into iTunes all mp3s with the same creation date.
4) When the array gets to a date that is different to the previous, the PC clock should be set to match the file creation date of the new mp3.

In theory this must work but does anyone have the skills and inclination to accept such a challenge.

Any comments on the suggestion are welcome.

Regards
 

cynikal

New member
Joined
Oct 28, 2007
Messages
1
Points
0
funny i should find this thread today seeing as how i have this very same problem and am working to get this all fixed..

fact of the matter is, i've been collecting mp3's since 1996, and have most if not all of the original songs i have had since then, but in the 11 or so years i've been archiving, i've gone through a number of computers (not to mention i only reluctantly started using iTunes like two years ago), and now would love to update my date added field so i can see which songs i've had longest (by sorting on the appropriate column). it's kind of nostalgic seeing what songs i've had longest ;)

anyway i've begun to undertake this very problem, and happen to discover what Adamtg1 was talking about on my own (and i also tried the whole edit xml, re-import and found doug's conclusion to be correct also)..

i am using perl, which will generate applescript, and rather than 'import' a song all over (thereby losing all other info like ratings, etc), i am going to have my perl script tell itunes (by way of applescript) to simply re-encode the file into mp3 (which i know is an abomination due to transcoding), but the script will then take the old file's contents and copy it into the "new" file (thereby preserving the original encoding), the script will then tell it to delete the 'original'.. this all of course will only be done after the system time is set to the desired "Date Added" value, via the "date" command on the command line (also invoked by the perl script).

it may seem like a complex solution, but in fact, if broken down into small steps, it's actually quite managable (i have already written a script that takes the file system creation date from the inodes and updates the .xml with that information, going interactive to resolve songs it can't match up automatically).. this xml will be the input to the script i have yet to write that will interact with itunes via applescript.
 
Last edited:

Syncopator

New member
Joined
Jun 4, 2006
Messages
18
Points
0
cynikal said:
i am going to have my perl script tell itunes (by way of applescript) to simply re-encode the file into mp3 (which i know is an abomination due to transcoding), but the script will then take the old file's contents and copy it into the "new" file (thereby preserving the original encoding), the script will then tell it to delete the 'original'.. this all of course will only be done after the system time is set to the desired "Date Added" value, via the "date" command on the command line (also invoked by the perl script).
clever. do i understand correctly that by "preserving the original encoding" you mean that the track will *not* be re-encoded by the lossy mp3 codec?

cynikal said:
if broken down into small steps, it's actually quite manageable.... [snip] this xml will be the input to the script i have yet to write that will interact with itunes via applescript.
after you do so, will you be willing to share the script with us? and with doug at doug's scripts? <http://dougscripts.com/> there are many of us who would find such a script quite useful, since to date, no one else has been able to write such a script.

will you keep us posted?

thanks in advance.
 

Solo Keita

New member
Joined
Aug 30, 2010
Messages
3
Points
0
Hey I just wanted to check up on this. Is there an apple script out there for this? I realize this forum is like 3 years old but I am interested in making my iTunes look more organized. I always view my iTunes by the "date added" column so this is what I need.
 

Jesse Hollington

Active member
Administrator
Joined
Nov 15, 2004
Messages
13,238
Points
36
Age
47
Location
Toronto, Canada
Website
www.ilounge.com
Hi and welcome to iLounge.

Unfortunately, nothing has changed in this regard, even after three years. :( The Date Added field is still a read-only field that cannot be updated via AppleScript. It's one of the fields that I've frequently wished I could update as well, particularly when re-ripped older music or upgrading it to a higher bit-rate.

You could always go to Apple's feedback page for iTunes at Apple - iTunes - Feedback and request that they provide this capability. It's worth a try, but I wouldn't hold my breath. :)
 

Solo Keita

New member
Joined
Aug 30, 2010
Messages
3
Points
0
Well I am interested in my albums showing up together instead of interlaced. I moved my iTunes library to my MacBook Pro from my desktop and now when I view my library by "date added" all the albums are mixed up.

Could someone write a script to remove albums from iTunes and reimport them one at a time? I met a guy who has done this on Windows but I need one for a Mac. Maybe someone could even write the script to reimport the oldest song files first so they appear as the oldest in iTunes.
 

Jesse Hollington

Active member
Administrator
Joined
Nov 15, 2004
Messages
13,238
Points
36
Age
47
Location
Toronto, Canada
Website
www.ilounge.com
I don't really have that problem with my albums as I've generally added them all at the same time, so all of the tracks have roughly the same date and time added.

I'd suggest searching through the AppleScripts at www.dougscripts.com to see if there's anything there that might be of use. There are quite a few clever scripts over there to perform various tasks, so maybe there's something helpful.
 

Solo Keita

New member
Joined
Aug 30, 2010
Messages
3
Points
0
I have already checked. I have made this same comment on a different forum and they sent me to the same place. They have nothing. I was hoping someone here could write it...
 

GraemeTunes1

New member
Joined
Oct 8, 2011
Messages
4
Points
0
Hi,

I've been annoyed by the 'mixed up import' problem / "Date Added" problem in iTunes for years so I wrote a program that helps sort it.

You can get it here: graemebell DOT net then software, then tools, then add-my-tunes

It's GPL/freeware and works on Mac / Windows. It can help you list your music by artist, album, track and date added simultaneously, depending on how you use it. It's not perfect but it may solve the problem for some people.

Enjoy :D

p.s. can someone with link-posting rights post the link?
 

S2_Mac

New member
Joined
Oct 24, 2006
Messages
4,878
Points
0
Location
About 3 feet in front of the monitor
Nice job for "Hello, World!" (Actually, that's just a guess from reading the code; I stopped updating python at v2.5, so I can't actually run the app ;-) For those who are interested, the "Add My Tunes" page is here; this is the "Add My Tunes" download.

Just observing (not criticizing)... I've done more than a few of these projects myself -- longstanding annoyance, tools at hand, dive in -- and they work great for me or the individual they're written for; turn 'em loose on the world though, and it starts to look like the cure is as bad as the disease...kinda like a Charlie Sheen "win" <g> (In this case, the requirements of folder structure, file naming, and potentially long run time.)

Here's an alternate take on solving this problem, from something I whipped up a few years ago for a friend-- let iTunes do the heavy lifting, then swoop in with Applescript or the iTunes COM interface and tidy up the pieces. I don't have the code here to reference, but it went something like this:
0) Requirement: let iTunes organize/control your files
1) Add files to iTunes in whatever normal way you're used to. If tags need some cleanup, go ahead and do that now
2) After files are added to library, select their tracks in iTunes window (or display a smart playlist that captures the desired tracks, making no selection); then run the script/app
Here's the script->
3) Use iTunes scripting to get the selected tracks or the displayed playlist, then use the "location" property to build a list of all those tracks' filepaths
4) Use iTunes scripting to delete those recently added tracks. The files will still exist, in neatly organized folders; it's just that iTunes no longer knows about them (and, thus, has no more out-of-sequence Date Added info)
5) Now use perl or python or a shell to quickly sort the list of file paths; since iTunes prepends track numbers* to file names, the sorted list has everything in "play order"
6) Finally, use iTunes scripting to loop through the sorted list of paths, adding those files (one at a time) to the library; voila!
* -- auto track number prepention may have been manually turned off by a savvy iTunes user digging in the Prefs file...but p'bly not ;-)

Not as automatic as having code to initially add the files, but it ran really fast and, since iTunes was doing all the folder/file work, it was easy to code and pretty much bulletproof.

Anyway, nice job. If I run across a python-v2.6-totin' Mac toady I'll give it a run. Thanx for posting!
 
Top