mhite/swinsian2itlxml

Smart Playlists

dashbad opened this issue · 10 comments

Love what you've done here.

You mention in the readme that Swinsian Smart Playlists aren't supported. Can you provide some more info?

Is it technically impossible or just non-trival/difficult?

Thanks

mhite commented

So I was investigating the feasibility of this a while back and concluded that it is a bit over my head complexity wise. I'm pretty certain I'd have to figure out how to use PyObjC in order to deal with the NSPredicate objects and such. I'm not saying all this isn't possible, just not something I've attempted or invested the time in learning.

Specifically, here's what the Swinsian developer shared with me as to how one might decode and translate into the iTunes smart playlist encoding.

The smart playlists are serialised NSPredicate objects (under 'smartpredicate’). Unfortunately it’s probably not that easy to translate them into iTunes smart playlist rules. You’d need some obj-c code to decode them using NSKeyedArchiver and then go through the subpredicates of the top level NSCompoundPredicate and looking at the parts of each NSComparisonPredicate etc

I don’t know if you have looked into it but smart playlists in the iTunes XML file are base64 encoded binary blobs. If you search the internet you should be able to find a bit of info about the format.

There are probably some aspects of Swinsian smart playlists that can’t be translated (e.g. I don’t think iTunes has the publisher field).

I hope this provides some clarity.

Thanks for this. I actually found a solution that will take the swinsian smart playlists and write them as regular playlists in the itunes xml. It uses pyapplescript to parse the tracks in the swinsian smart playlist.

mhite commented

Nice. Mind posting a link to what you found?

Hi. I wish I had some time to work on this. You can see my current solution in my forked repo here: https://github.com/dashbad/swinsian2itlxml/blob/master/swinsian2itlxml.py

I knocked this up very quickly and it really needs some robust testing. On face value it's quite simple but I simply haven't had a chance to test it.

Interested if you can improve/build on this....

mhite commented

Nice! That's pretty creative. ;) I might be able to accomplish the same thing in native Python and render them to non-smart playlists. (IE. Similar approach that you've done with the Applescript)

I'd only been able to test it on a dummy library with a couple of smart playlists. Just tried it on my large library with lots of folders and its got messed up. Doesn't seem to write the correct smart playlists inside the right folders so I've done something wrong.

Will keep an eye on your repo in case you get a chance to work on it.

For anyone still struggling with smart playlists in Swinsian: I hacked together a quick tool in Swift that also exports the smart playlists as regular playlists in the iTunes XML file.

https://github.com/maarten/Ximian

It's heavily inspired by this project so many credits to Matt for writing swinsian2itlxml in the first place.

mhite commented

Nice, @maarten!

are there any news about smart playlists?

mhite commented

@RitterLean - I don't have any plans to attempt to implement this due to the complexity. Predicate objects are basically a special object which encodes how to filter another special object, usually a collection of something. This is all very specific to Mac OS X development frameworks and isn't readily available in Python, unfortunately. You can read more about predicates here:

http://nshipster.com/nspredicate/

If someone was able to figure out how to do this all in Python, I'd certainly take a look at their pull request but unfortunately it's beyond my own time and capabilities. Your best bet is to give Ximian[1] a try, a tool that is similar to this one but has the benefits of being written in Swift and as such has native access to NSPredicate built into the language.

On a side note, I've politely asked the developer of Swinsian to consider adding an XML export option. The DJ market isn't necessarily his thing, so I'm not banking on it, but it certainly doesn't hurt if others reach out with the feature request.

[1] - https://github.com/maarten/Ximian