Skip to main content

Encode and decode Apple Music Smart Playlist binary format (Smart Info + Smart Criteria)

Project description

smart-playlist-io

PyPI

Build and inspect Apple Music smart playlists from Python.

from smart_playlist_io import AND, OR, rule, encode_b64

rules = AND([
    rule("Rating", "greater", 3),
    rule("LastPlayed", "not_in_last", 6, "months"),
    OR([
        rule("Genre", "starts", "Ambient"),
        rule("Genre", "starts", "Electronic / Ambient"),
    ]),
])

info_b64, criteria_b64 = encode_b64(rules, limit=25, select_by="most_played")

Produces the Smart Info and Smart Criteria base64 blobs used in Music.app's Library XML format. Import them via File > Library > Import Playlist or the AppleScript add command. Also decodes existing smart playlists back to readable rules.

Not affiliated with or endorsed by Apple Inc.

Install

Requires Python 3.12+.

pip install smart-playlist-io

Encode

from smart_playlist_io import AND, OR, rule, encode, encode_b64

# Raw bytes
info_bytes, criteria_bytes = encode(rules, limit=25, select_by="most_played", live=True)

# Base64 strings (for XML plist)
info_b64, criteria_b64 = encode_b64(rules, limit=25, select_by="most_played")

Options

Parameter Default Values
limit None Any int, or None to disable
limit_by "items" "items", "minutes", "hours", "MB", "GB"
select_by "most_played" random, name, album, artist, genre, highest_rated, lowest_rated, most_played, least_played, most_recently_played, least_recently_played, most_recently_added, least_recently_added
live True True / False
only_checked False True / False

Fields and operators

Type Fields Operators
String Name, Artist, Album, Genre, Comments, Grouping, Composer, AlbumArtist, Kind is, is_not, contains, not_contains, starts, ends
Integer Rating (1–5), Year, Plays, BPM, BitRate, TrackNumber, DiskNumber, Size, Duration, Skips is, is_not, greater, less, between
Boolean Checked, HasArtwork is
Date DateAdded, DateModified, LastPlayed, LastSkipped in_last, not_in_last (+ unit: "days", "weeks", "months"), after, before
Enum iCloudStatus, Love, MediaKind, Location is, is_not

Decode

from smart_playlist_io import decode_criteria, decode_info_flags

rules = decode_criteria(criteria_bytes)   # ['AND', 'Rating > 3', ...]
flags = decode_info_flags(info_bytes)     # 'live updating, limit 25 items, most played'

CLI

Decode all smart playlists in a Library XML export:

decode-smart-playlists /path/to/Library.xml
decode-smart-playlists /path/to/Library.xml --out baseline.md

Notes

Binary format details and the skip-length padding decision are in docs/format-constants.md.

Format knowledge derived from itunessmart by cvzi and banshee-itunes-import-plugin by Scott Peterson. See THIRD_PARTY_NOTICES for license text.

License

MIT

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

smart_playlist_io-1.0.1.tar.gz (24.5 kB view details)

Uploaded Source

Built Distribution

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

smart_playlist_io-1.0.1-py3-none-any.whl (17.4 kB view details)

Uploaded Python 3

File details

Details for the file smart_playlist_io-1.0.1.tar.gz.

File metadata

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

File hashes

Hashes for smart_playlist_io-1.0.1.tar.gz
Algorithm Hash digest
SHA256 bb6b52d9736381953f7134acc81a258855578cb13c5bf3e3353389110076bd5a
MD5 bb578c18f6354131484c30a723f2bb13
BLAKE2b-256 5e7eda899c438263272ebe8f50bccfb501f62f3d42846edd873d906d3fc12b93

See more details on using hashes here.

Provenance

The following attestation bundles were made for smart_playlist_io-1.0.1.tar.gz:

Publisher: publish.yml on kynoptic/smart-playlist-io

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

File details

Details for the file smart_playlist_io-1.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for smart_playlist_io-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e6ea9f0d1281b77d7e7cb19b8298326533a07de60d362530bb8113bdef19748d
MD5 a7a8b725871f056e0f3f075421515a5b
BLAKE2b-256 9c018a2c4078664025a5f82dae58f11f7caeb2468d73d6a85b8d1af02e6b14f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for smart_playlist_io-1.0.1-py3-none-any.whl:

Publisher: publish.yml on kynoptic/smart-playlist-io

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