iTunes & Traktor Collection
I’m using BeaTunes and love it.
I’ve been searching for a long time for a way to manipulate the metadata that Traktor creates and stores in iTunes.
For example - I’d love to create an iTunes smart playlist that is based on the number of times a track has been played in Traktor.
It would mean comparing the Traktor Collection .xml with the iTunes Library .xml, and updating the iTunes .nml with the Traktor playcount from the Collection .xml.
Could BeaTunes be the bridge that sits between Traktor and iTunes, to allow us to manipulate the Traktor metadata in iTunes???
Showing page 3 out of 4. View the first page
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Support Staff 61 Posted by hendrik on 16 May, 2019 06:28 AM
Do you know how XML is structured? The
.nml
file is written in XML.XML consists of tags also called elements. They follow the format:
An XML element starts with
<NAME>
and ends with</NAME>
. It may have one or more attributes each consisting ofattributeName
andattributeValue
. It's very similar to HTML.The code in the beaTlet is structured in functions. This particular beaTlet is written in the scripting language Groovy (there are other options, but let's stick to this one for now). Each function follows the form:
Note that anything after
//
is ignored by the program. It's just a comment.The given beaTlet already has some code in there to read the XML element
<INFO>
. This code is in the function importInfo. Here's the original function with additional comments that show how to add genre import:So to add import capability for genre, you have to effectively add code in three places:
Very important: The shown code depends on additional attributes being part of the
<INFO>
element. If they occur outside the<INFO>
element, other changes are necessary.I can recommend using Atom for coding this, as it does syntax highlighting, which is helpful. For a syntax highlighted version of the code above, see https://gist.github.com/hendriks73/736be182cb221b75896898da7127295d It's much easier to read, as the (non-functional) comments are gray.
Good luck!
PS: If you encounter issues, please always attach your complete
.groovy
file to the message, so I can see what you have done.62 Posted by Patch on 16 May, 2019 10:18 AM
I had a go at coding this last night. I had some success - but I’ll revisit it using the info above.
Thanks for the detailed explanation.
I wanted to utilise the Tags “Programme” and “Sort Programme”, called “Series” and “Sort Series” in the iTunes Library respectively (according to Atom).
Not entirely sure if these tags can be used for .mp3’s, since I can only add/edit them within iTunes (they don’t show up in MP3Tag, for example). If they can’t be saved to the file I’ll be stumped...
Like I said - you’ve given me much more knowledge than I had last night, so I’ll have a go tonight.
Support Staff 63 Posted by hendrik on 16 May, 2019 11:00 AM
Good luck! 🍀
64 Posted by Patch on 16 May, 2019 08:26 PM
Woo-hoo!!! I think did it!!!
I've got:
(Traktor's) Mix tag showing up in the .mp3's Sort Programme/Sort Show in iTunes
(Traktors) Remixer tag in the .mp3's Programme/Show tag in iTunes
(Traktors) Comment2 tag in the .mp3's Movement tag in iTunes
Honestly can't thank you enough for all of your help, Hendrik! This opens a LOT of possibilities with Smart Playlists in Traktor.
Something did cross my mind here. Could we take existing tags from .mp3 files, and add them to the Traktor .nml using Beatlets???
65 Posted by Patch on 16 May, 2019 08:43 PM
One other thing - the tags in the Sort Show column in BeaTunes are greyed out. What does that mean?
Also, it looks like iTunes does not write the tags to the file, it must store them in it's own database. Because if I delete files from iTunes, then re-import them, the tags are gone.
:-(
Still very useful, though!
Support Staff 66 Posted by hendrik on 17 May, 2019 11:59 AM
Congrats! :-)
I am not sure whether Traktor ever reads from the
.nml
file and if so, when.It's not usually mean to be edited in the table view. However, you can edit it in the Get Info dialog, just like in iTunes.
Really? That's odd. Perhaps not using the sort fields works better.
67 Posted by Patch on 17 May, 2019 01:52 PM
Sort Programme & Programme/Sort Show and Show are .mp4 tags only. So you can use them for .mp3 files and write to them and read them in iTunes, but they’re stored in the iTunes Library file, not the .mp3 file.
Can BeaTunes get info from files, or from the iTunes Library, and write them to the Traktor .nml? That would be amazing. The final piece of the puzzle for me!
Support Staff 68 Posted by hendrik on 17 May, 2019 01:57 PM
In theory that's possible.
But you assume that Traktor reads any information from the
.nml
file. Are you sure it does? What makes you so sure?iTunes for example, never reads from its
iTunes Library.xml
file.69 Posted by Patch on 17 May, 2019 02:51 PM
I get where you’re going, but how can we tell?
So, does iTunes READ from its .itl file? That is to say, when we write a tag in iTunes it gets stored on its .xml file and it’s .itl file?
Do we need to understand if Traktor has an equivalent of iTunes .itl file?
Support Staff 70 Posted by hendrik on 17 May, 2019 02:53 PM
You could modify the
.nml
file and see if Traktor picks it up somehow.The
.itl
file is iTunes' actually database. iTunes always stores data there and if possible in the audio file. If configured correctly, it dumps the XML file after each change.71 Posted by Patch on 17 May, 2019 03:28 PM
Right!!!
Traktor DOES read from it's .nml file! I added a Tag (Comment) in MP3Tag ("Traktor READ nml Test") then opened the file in Traktor, and the Comment Tag got populated with that text.
Then, I opened the Traktor .NML in Atom, and edited the entry next to Comment (Traktor WRITE nml Test"), then re-opened the file in Traktor, and presto! tag had been updated!
After a check, I could see that the file Tag was not changed - so the file tag said READ, and the Traktor .nml Tag said WRITE.
So - using BeaTunes, can we copy from iTunes, write to Traktor .nml?
72 Posted by Patch on 17 May, 2019 03:36 PM
And I've just confirmed - once Traktor has an entry in the collection for an .mp3, it DOESN'T re-read the tags in the file the next time you play it!!! It takes the info from it's own Collection.nml.
This is great!
73 Posted by Patch on 18 May, 2019 08:16 AM
So, our original .groovy file takes text tags OUT of the Tractor Collection.nml, and moves it to iTunes which writes it to the .mp3 file. BeaTunes knows the location of the iTunes Library & .xml, and the .groovy asks for the Traktor Collection.nml
Collection.nml = source
iTunes/File Tags = destination
How do we flip that so that iTunes/File is source, and Collection.nml is destination?
I’m guessing it would need to be a separate Beatlet?
Support Staff 74 Posted by hendrik on 18 May, 2019 08:37 AM
Yes, it could be.
You'd have to iterate over the tracks in the
.nml
file and find the corresponding songs in beaTunes, just like the existing beaTlet does. Then you add the additional information to the.nml
file (actually, I'd recommend writing to a different file first). To do so, first remember everything you want to export to.nml
, then load the XML into memory (like a DOM), manipulate it, and serialize it. This is a bit of programming...BTW: I don't want to make my own product obsolete, but you don't need beaTunes for this. You just need to write a small script that reads the
iTunes Library.xml
file from beaTunes, matches it with thecollection.nml
file from Traktor, and then adds info to the Traktor file as needed. You could write this little program in pretty much any scripting language you want, e.g. Python, Ruby or JavaScript.75 Posted by Patch on 18 May, 2019 10:56 AM
Thanks Hendrik. I’d definitely like to keep this in BeaTunes. BeaTunes is a massive part of my preparation and keeping changes contained in your software is one of the things that make it indispensable to me!
I’m gonna hit up a chap I know to see if he can code this for me, because, this is definitely outside of my coding ability.
76 Posted by Patch on 19 May, 2019 07:53 PM
Back to the original Beatlet - is there a way to NOT over-write the iTunes field if there is already text in there, or if the text in there is different to rating field in the Traktor .nml? It would be around here in the code:
It feels to me like we need to add an IF statement before song.setmovement (saying something like IF Movement is NOT null, do nothing, else song.setmovement(rating.getValue())
Am I on the right lines here? Or am I waaaay off???
Ideally, we'd have something like IF Movement is blank, set.movement(rating.getvalue(), IF movement is not equal to rating, set,movement(rating.getValue()
I know the syntax above is WAAAY of, but can what I've described be done?
Support Staff 77 Posted by hendrik on 20 May, 2019 07:33 AM
You'd do:
&&
means "and". The!
means "not". Soif (rating != null && !rating.equals(song.getMovement())) {
means:if
rating
exists und is not equal tosong.getMovement()
, then ...So this would only overwrite movement, if it is not already the same as rating.
If you'd like to only overwrite it, when it's empty, you'd do:
||
means "or". So this checks whethergetMovement()
has a value at all or whether the value it may have is empty, i.e. a string of length 0.78 Posted by Patch on 20 May, 2019 11:58 AM
How would we over-write Movement, but ONLY when it is empty, OR when it is populated but different to the text in rating?
Reason for this, is that I will not type anything new directly into Movement, but I do already have a lot of files with Movement already populated. So I may update rating, and I'd like that to over-write existing text in Movement, or populate Movement if it is blank.
Support Staff 79 Posted by hendrik on 22 May, 2019 09:24 AM
Because we ONLY write the
rating
when it is not empty, it seems sufficient to check whether the current movement value is different from rating and rating is not empty, which is exactly the first example I gave:Boolean logic is not that hard. Just use
&&
and||
, set your parenthesis right, and you're golden! :-)80 Posted by Patch on 22 May, 2019 03:25 PM
You've been SO helpful, Hendrik.
Finally - can we populate iTunes Rating (5 star scale) with info from Traktors Rating (also 5 star scale)?
Support Staff 81 Posted by hendrik on 22 May, 2019 03:34 PM
How does Traktor expose its rating. Can you give an example from the
.nml
file?82 Posted by Patch on 22 May, 2019 04:08 PM
It's stored as an integer in RANKING:
0* = 0
1* = 51
2* = 102
3* = 153
4* = 204
5* = 255
ex.: Ranking="153"
Support Staff 83 Posted by hendrik on 23 May, 2019 07:17 AM
OK, that means you have to get the attribute like this (assuming, it is an
<INFO>
attribute):Add the variable
ranking
to this list:and then set it like this:
Disclaimer: the code is untested.
This should lead to the same star ratings. however, it may be off a little, depending on how the mapping integer -> stars is implemented.
84 Posted by Patch on 23 May, 2019 07:57 AM
I shall give it a try.
85 Posted by Patch on 23 May, 2019 07:19 PM
Simply put - you are THE MAN. :-)
86 Posted by Patch on 23 May, 2019 09:34 PM
Hendrik - would you consider (as paid work) writing a Beatlet that would copy information from iTunes, and write it to the corresponding entries in the Traktor .nml?
I really want to baseline the metadata in my music collection, and I'd really need all of the information currently held in the tags to be available in Traktor.
We touched on it above, but it feels very much out of my ability to create it...
Support Staff 87 Posted by hendrik on 25 May, 2019 08:53 AM
I'm sorry, but I will have virtually no time until July for such a thing and even then I might not get to it.
So, if you want this quickly, you will probably be better off asking someone else. It's not rocket science (for a seasoned programmer).
88 Posted by Patch on 25 May, 2019 09:26 AM
Understood.
I've just spotted this discussion:
http://help.beatunes.com/discussions/plugin/1837-embed-ratings-in-file-from-itunes
So right now, the script that you've been helping me with in this thread takes the Star Rating (called Ranking) from the Traktor .nml, and copies that info to the itunes database (Star Rating). Great!
Would using the EmbedRatings.groovy listed in the discussion above take that Star Rating (originally input in Traktor, then copied to iTunes) and embed it in the audio file???
89 Posted by Patch on 25 May, 2019 09:27 AM
Sorry - and which tag in the audio file would it go to?
90 Posted by PAtch on 25 May, 2019 10:15 AM
IGNORE ME! Traktor actually writes its star rating directly to the file.
Who knew?