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

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.9.tar.gz (27.4 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.1.9-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for itunessmart-1.1.9.tar.gz
Algorithm Hash digest
SHA256 fd8dee839ed4ab140ceac69e8ae87f222eb8bb9ea4993cee162dcfe32311bec0
MD5 6e34d515f2d669761c0f685ff2f61288
BLAKE2b-256 9083391f23bd81e7d2a486c71109b927cf273e75f4f03b26cacd90a4ae32b9c2

See more details on using hashes here.

Provenance

The following attestation bundles were made for itunessmart-1.1.9.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.1.9-py3-none-any.whl.

File metadata

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

File hashes

Hashes for itunessmart-1.1.9-py3-none-any.whl
Algorithm Hash digest
SHA256 c1ac6f6360dc001ed27f778e0c71423dae99a5eeebaff3924666c55ce241a1e0
MD5 68668996cb3097500bdafa075fd58703
BLAKE2b-256 efa6c29e35c9d57705cf80bbef202b0f02e37c2bc8746ff00b7d3d76194e763b

See more details on using hashes here.

Provenance

The following attestation bundles were made for itunessmart-1.1.9-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