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

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 11 with iTunes 12.13.10.3 (64bit) and Python 3.14.

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
	AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	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.2.0.tar.gz (32.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

itunessmart-1.2.0-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: itunessmart-1.2.0.tar.gz
  • Upload date:
  • Size: 32.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for itunessmart-1.2.0.tar.gz
Algorithm Hash digest
SHA256 02fe0c75cc1b42806093ae84abad197a5fda947dd2f7d8d2ffd05e017f1e1bf8
MD5 b387551e95b1898fd877c082f834f3d4
BLAKE2b-256 77dde2719c235bc520cf0023cf8583f310e4095ac93e7365cb11737d44e2b7af

See more details on using hashes here.

Provenance

The following attestation bundles were made for itunessmart-1.2.0.tar.gz:

Publisher: pythonpublish.yml on cvzi/itunes_smartplaylist

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: itunessmart-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for itunessmart-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8dbefec0a277f80d3e9ae721c15e96414610f947a60c8bf6d7b37c7e8afee3e
MD5 c2ec28b5e523b44832d4e7039400f6cd
BLAKE2b-256 139722fb9ee9cedb4cfc04d41e497572a192a9ca859fcc42fdd7ad7898d4c568

See more details on using hashes here.

Provenance

The following attestation bundles were made for itunessmart-1.2.0-py3-none-any.whl:

Publisher: pythonpublish.yml on cvzi/itunes_smartplaylist

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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