Skip to main content

Decode iTunes Smart playlist rules. Convert iTunes smart playlists to Kodi xsp smart playlists.

Project description

iTunes Smartplaylist parser

itunessmart on PyPI Python Versions Coverage Status Codacy Badge Build Status

Convert smart playlist information to a readable form.

This module is a Python 3 implementation, based on banshee-itunes-import-plugin by Scott Peterson.

It was tested on Windows 10 with iTunes 12.10.6.2 (64bit) and Python 3.8.

It does not work with Python 2.x.

Kodi smart playlists

You can convert all your iTunes smart playlists to Kodi smart playlists with this interactive script:

python3 utils/export_xsp.py or python3 -m itunessmart

Then place the resulting .xsp files from out/ in your userdata folder.

Most of the common functions and rules are available in both formats and often iTunes playlists are fully convertible to Kodi.
The biggest difference are nested rules in iTunes which are not available in Kodi. However, nested rules can be simulated with sub-playlists. These "helper"-playlists are named with the prefix "zzzsub_" and a MD5 hash of its rules. When you run utils/export_xsp.py, you can disable generation of subplaylists.

More information on Kodie smart playlists:
http://kodi.wiki/view/smart_playlists#Format_of_a_smart_playlist_file

Text export

To export all playlists to text files, use python3 utils/export.py

The format

Smart playlist data in iTunes is saved in the iTunes Music Library.xml file.

The data in the playlist entry in the xml file is base64 encoded binary data:

<dict>
	<key>Name</key><string>Example</string>
	<key>Playlist ID</key><integer>123456</integer>
	<key>Playlist Persistent ID</key><string>49C97D85843B04CC</string>
	<key>Parent Persistent ID</key><string>4DA0F774D3F70473</string>
	<key>All Items</key><true/>
	<key>Smart Info</key>
	<data>
	AQEAAwAAAAIAAAAZAAAAAAAAAAcAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAA==
	</data>
	<key>Smart Criteria</key>
	<data>
	U0xzdAABAAEAAAADAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	AAAARAAAAAAAAABZAAAAAAAAAAAAAAAAAAAAAQAAAAAAAABZAAAAAAAAAAAAAAAAAAAAAQAAA
	AAAAAAAAAAAAAAAAAAAAAAA
	</data>
	<key>Playlist Items</key>
	<array>
		<dict>
			<key>Track ID</key><integer>123</integer>
		</dict>
		<dict>
			<key>Track ID</key><integer>124</integer>
		</dict>
		<dict>
		...
		<dict>
	</array>
</dict>

It can be converted into three different output formats:

import itunessmart
info = "AQEAAwAAAAIAAAAZ..."
criteria = "U0xzdAABAAEAAAAD..."
parser = itunessmart.Parser(info, criteria)
result = parser.result
print(result.output)
print(result.query)
print(json.dumps(result.queryTree, indent=2))

A text format:

Plays is greater than 15 and
[
	Plays is greater than 16 or
	Plays is greater than 17 or
	Plays is greater than 18
] and
Rating is greater than 4

A sql-like format:

(Plays > 15) AND ( (Plays > 16) OR (Plays > 17) OR (Plays > 18) ) AND (Rating > 4)

And two tree structures

{
  "tree": {
    "and": [
      [
        "Plays",
        "(Plays > 15)"
      ],
      {
        "or": [
          [
            "Plays",
            "(Plays > 16)"
          ],
          [
            "Plays",
            "(Plays > 17)"
          ],
          [
            "Plays",
            "(Plays > 18)"
          ]
        ]
      },
      [
        "Rating",
        "(Rating > 4)"
      ]
    ]
  },
  "liveupdate": true,
  "onlychecked": false
}
{
  "fulltree": {
    "and": [
      {
        "field": "Plays",
        "type": "int",
        "operator": "greater than",
        "value": 15
      },
      {
        "or": [
          {
            "field": "Plays",
            "type": "int",
            "operator": "greater than",
            "value": 16
          },
          {
            "field": "Plays",
            "type": "int",
            "operator": "greater than",
            "value": 17
          },
          {
            "field": "Plays",
            "type": "int",
            "operator": "greater than",
            "value": 18
          }
        ]
      },
      {
        "field": "Rating",
        "type": "int",
        "operator": "greater than",
        "value": 4
      }
    ]
  }
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

itunessmart-1.1.8.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

itunessmart-1.1.8-py3-none-any.whl (20.9 kB view details)

Uploaded Python 3

File details

Details for the file itunessmart-1.1.8.tar.gz.

File metadata

  • Download URL: itunessmart-1.1.8.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for itunessmart-1.1.8.tar.gz
Algorithm Hash digest
SHA256 a646bcc94b7088811079d43974a83806a82961d1e63ecedc07c15b7760cb6e8b
MD5 01f19d32491b3929b6df51d4ba78d0e5
BLAKE2b-256 140de1ec1bff50cc2b44723641c7cf7224e73e9a6037d7cae06ce2b3d8a20ef0

See more details on using hashes here.

File details

Details for the file itunessmart-1.1.8-py3-none-any.whl.

File metadata

  • Download URL: itunessmart-1.1.8-py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for itunessmart-1.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 b2cf8e8da7ebcd4383da7c56a6ffc253cb60adbdb41a2789e3e66e5d0515aedf
MD5 b6010cab45ac1af0a76dbe6e3747be00
BLAKE2b-256 f34c41f1faa9cbbe175c224caa849e475227c6282b98719f0a64626865b9a9f9

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page