You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Extract Apple Music song data (ie play count) from an XML File?

Brief background - I lost my music library when I was moving files across hard drives (stupid!). All of my music became greyed out and unplayable.


The most devastating part about this is losing the data attached to the songs (play count, date added, etc...) since most of my playlists are based on this data (smart playlists), I would love to get this back. I forgot where/when I got it, but I have an XML file with ALL playlists and ALL song data (see image below).


Does anyone have any advice how to merge my current library with data?? I have background in AppleScript, so im thinking about writing a program:

  1. goes through songs in XML file and checks if it exists in my current library (not sure if the track IDs will be the same between current Apple Music and this file...)
  2. if it doesn't, move on to next
  3. if it does, update date added and combine things like play count:
    1. play count = xml file play count + current play count


going through the XML file is the issue.


advice, programs, tutorials how to extract Apple Music data from XML file, ANYTHING...

I started writing a script to extract and store the info into an easier file to work with, but its honestly making my head hurt....



Thanks in advance!!

MacBook Pro 13″, macOS 12.6

Posted on Oct 7, 2022 6:44 PM

Reply
Question marked as Top-ranking reply

Posted on Oct 8, 2022 7:44 AM

Hi,


I have some background in this area, though so far I have found it easier to do in Windows. In fact my script ImportFromXML seems to be a Windows analogue for what you want. When extracting details from a device or file, one may be able to rely on both library and source using the same Persistent ID as a unique key for each track. Failing that one can construct an alternate key from details such as artist, album, disc no, track no, and title. File location is another possible key. I use vbScript which has a dictionary object letting me store a list of keys for every track in the library, after which I can iterate through the tracks on a device, or in an imported text file, identify the target track in the library if it exists, and then apply the metadata that I want to add. So far I have yet to find a way to implement this dictionary structure in AppleScript. Searching through each track in the library each time would be horribly inefficient so this really needs to be solved before progress can be made.


tt2

Similar questions

14 replies
Question marked as Top-ranking reply

Oct 8, 2022 7:44 AM in response to Timbot13

Hi,


I have some background in this area, though so far I have found it easier to do in Windows. In fact my script ImportFromXML seems to be a Windows analogue for what you want. When extracting details from a device or file, one may be able to rely on both library and source using the same Persistent ID as a unique key for each track. Failing that one can construct an alternate key from details such as artist, album, disc no, track no, and title. File location is another possible key. I use vbScript which has a dictionary object letting me store a list of keys for every track in the library, after which I can iterate through the tracks on a device, or in an imported text file, identify the target track in the library if it exists, and then apply the metadata that I want to add. So far I have yet to find a way to implement this dictionary structure in AppleScript. Searching through each track in the library each time would be horribly inefficient so this really needs to be solved before progress can be made.


tt2

Oct 8, 2022 1:17 PM in response to Timbot13

The four digit numbers will be something to do with the current playlist order. The Persistent IDs are 64-bit numbers, but each library will assign a different Persistent ID to the same file. Date Added cannot be modified after the fact. Ratings, play, skips, can each be set from AppleScript, but working out which track in the current library needs to be adjusted will be the tricky part.


Do you still have the original library that you discarded in favour of starting over? You might look at the two scripts I mention in this thread: Accidentally changed the name of every al… - Apple Community. It isn't the same task by any means, but might give you an idea of what can be done. If the data exists somewhere there is usually a way to mash it into a form you can use.


tt2


Oct 8, 2022 5:38 PM in response to Timbot13

See Move your iTunes library to a new computer - Apple Community for my standard advice. As a rule if you have backed up the Music folder, and the media folder if stored on some other path, then you should be able to restore the files to the same paths and option start Music to connect to the library.


From your screenshot I would expect there to be a Music Library.musiclibrary file at Ominus Prime/Other/Music Folder/ARCHIVE/Music/Music.


tt2

Oct 8, 2022 4:17 PM in response to turingtest2

I have so much documentation between apple reps and me... but to sum everything up...

  1. I wanted to format my MacBook and start from scratch, so I copied all files on my MacBook to an external hard drive.
  2. I called customer service to get advice on how to do this and let her know what I did and asked what I should do to proceed correctly
  3. in regards to music - she told me I needed to export my library then it would be okay to delete.
  4. when my MacBook was good to go, I started dropping the files I wanted to the MacBook - including putting the music files in the correct music folder that Apple Music was referencing.
  5. Clicked import playlist and uploaded the file. Everything populated, but greyed out (including ones purchased through iTunes) but was still able to see all of the metadata
  6. troubleshooted everything myself, nothing worked. Called support again and after >2 weeks I found this is typically caused by moving around .m4p (copyright protected). They gave me a call a few days later and basically said I was SOL. I told them I had the XML file and asked how to get the playlists back (that was my main concern at the time). I had well over 300 playlists - literally since high school and Im 34 now...
  7. It wasn't until I started re-building my library and playlists that i realized all of the metadata isn't attached to the cloud, but I guess the music files? im not sure exactly... Regardless all of my smart playlists are garbage....
  8. I have all of the original files on my hard drive, so ill check if the metadata is in them, maybe that's easier to work with?


im VERY content with the new structure of music, but Im so bummed about the metadata being wiped...


Also, I didnt setup time machine prior to the initial wipe. The rep said it would be a good idea to do so, so I did, but when I restored from that backup, the same issue was present



Sorry, probably more info than you needed.

Oct 8, 2022 1:39 PM in response to turingtest2

I do! I imported it into my dog's account so I could switch between accounts and test different things (its essentially a guest account for my iPad mini and MacBook). All of the data is correct, but the songs are greyed out... spent honestly DAYS trying to figure out how to get them fixed, but alas, since they are the copyright protected file extensions (can't remember exactly), but it took 4 supervisors over the span of >2 weeks to tell me there's no way to recover this...



Essentially, I feel like it *should* be an easy fix to merge the data from the backed up library (.XML) to my current...


Oh side note: AppleScripts work with the greyed out songs:


ie

Oct 10, 2022 12:38 PM in response to turingtest2

Hey, so update... I decided to download Windows Parallels so I can work with SQL easier than on my Mac. I am so lost on how to convert the .xml file to the database. I found this article, but I think the guys xml output is different than mine...

see mine in screenshot from original post. note the definition of key value pairs <key>...</key><type>....</type>

Screenshot of his XML:

"tutorial" found here:

https://www.concordbusinessservicesllc.com/posts/parsing-itunes-xml-with-sql-server/


I think if I can get my current library into a database and the old one, I can add a field "newPID" which looks up the song based on title, artist, and album (maybe more conditions, but we shall see..). Once I get the newPID in the old library, I can update my current library metadata based on those PIDs (and obviously need some algebra to add play counts etc together).


I feel like im getting so close. Setup a server, made the metadata database I just need to populate the xml library then try to learn SQL lol. Been stuck on the XML->SQL for a day and a half now...


Thanks!

Oct 8, 2022 12:14 PM in response to turingtest2

Oh jeez, so this probably won't be as easy of a fix as I thought?


I used someones windows PC and was able to import a database from the XML library file, but I honestly don't understand how it works (currently watching tutorials).


So a little more background- I had to start my library from scratch (which im very happy with the updated structure, just need the track data for smart playlists). Would this essentially change each ID? I noticed they're 4 digit numbers which is wayyy too small to be a reference to Apple Music. I also noticed the persistent ID you mentioned, but I need to look more into that. Apparently applescripts is not the best working with these (different data types- hex vs floating) - currently googling this too...


Essentially I don't care too much about the songs not in my current library, so im hoping this will be a little more efficient? Im not a programmer, but I have *some* background... I have a really cool program I made that creates static playlists based on a criteria which is linked to smart playlists, then creates a static version of that smart playlist. Overly complicated, but I love what it does.



Based on what you're saying, this will be a very time consuming task? Idk if its worth it :-/


Thanks!


Oct 8, 2022 6:14 PM in response to turingtest2

Wow! Thank you so much, you are so thorough! I will try some of these out.


so I have a few of those files, which is GREAT including iTunes ones from 2010-2014... so I guess its a matter of matching which to the folder I have? Haven't dived into the links in your article, but ill start there. Idk everything is so disorganized because I got a little manic with backing everything up. Music is my life


Seriously this is so helpful- thank you!



Oct 8, 2022 6:19 PM in response to turingtest2

Also, I did not understand how the cloud and Apple Music worked until last year trying to fix this stuff... I didnt even need to store the files on my comp in the first place... I thought it was "safer".



edit: some of these are from my time machine backup, but I also didnt understand that and dragged the backup onto my hard drive so idk if this will work... we shall see

Oct 10, 2022 3:38 PM in response to Timbot13

Well if you've got access to Windows now take a look at my script ExportImport. It can be used to export selected data to a sort of XML lite text file that is somewhat easier to scan through by eye. It can be used to grab data from one library, then import it to another. An alternate key can be generated for when the persistent ID cannot be used.


tt2

Extract Apple Music song data (ie play count) from an XML File?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.