Skip to content

Genius

Genius builds a playlist from one song. On the iPod classic, the intelligence lives on the computer: iTunes works out which songs go together and writes the result onto the disk. The device only walks what it was given, with a small rule book that iTunes also wrote. Chikuma reproduces that walk, read in full from the firmware, in chikuma/drivers/media/genius_engine.zig.

Where the data lives

Genius data sits in iPod_Control/iTunes/Extras.itdb, a SQLite database, in three tables:

Table Holds
genius_config the rule book, one blob
genius_metadata per Genius id, the four values the rules compare: genre, artist, album and song
genius_similarities per Genius id, a ranked list of neighbouring ids

The firmware embeds SQLite to read them, and only ever reads. Saving a Genius playlist goes through the ordinary playlist path, never into these tables. Chikuma uses SQLite from upstream at the image's own version, behind a filesystem layer of its own.

A track's Genius id is a 64-bit field of its own in the iTunesDB track record, not the database id. The music database carries it, along with the play and skip statistics one of the rules reads.

A similarity blob is a short header followed by eight-byte entries, rank order first. The header has a compression flag. When the flag is set the firmware inflates the payload with zlib before reading it. No database at hand sets the flag, so for the moment Chikuma refuses a compressed blob instead of reproducing a path nothing can check.

What decides that Genius exists

At start, the firmware opens Extras.itdb and runs the config query. If it returns a non-empty blob, Genius is available. A missing file and a file with no config row give the same answer. The Genius-account id iTunes writes into the iTunesDB is skipped by the reader. It plays no part.

A song's contextual menu offers Start Genius when three tests pass: the track is no podcast, it is no video, and it has Genius data. The row comes first in the menu.

The length of a playlist

The target count is not in the SQLite database, although iTunes writes one there. The firmware takes two numbers from the iTunesDB header, a default length of 25 and a minimum of 10. The run stops once the playlist holds exactly the target.

The rule book

The config blob lists constraints, each one a small object with a test, a way to relax and a hook that runs after every pick. A test answers pass, reject for this round, or reject for the whole run.

Rule What it does
already added a track picked once is never picked again
compatible genre a candidate's genre must be in the seed genre's compatibility set
distance spacing between two picks sharing an artist, an album or a song
skip count keeps out tracks the listener skips
random jitter refuses a share of candidates at random

Distance is spacing

Each distance rule keeps the age of every value it has seen: how many picks ago that artist, album or song last appeared. A candidate is refused while the age of its value is under the rule's limit. The limit is drawn at random at the start and again after every pick, so a run wants roughly six to eleven tracks between two by the same artist, and more for the same album. That randomness is why the same seed never gives the same playlist twice.

Skip count

A track is kept out when all of these hold:

  • it was skipped more than twice
  • its last skip is less than a week old
  • it is skipped more often than it is played

A track skipped eight days ago is forgiven, whatever its score. The statistics come from the iTunesDB as the last sync wrote them.

Jitter

The jitter rule rolls a die for each candidate and refuses about three in ten. It switches itself off for the rest of the run the first time it is relaxed.

The run

The generator answers one track per call. The first call answers the seed itself, so a Genius playlist always starts with the song it was made from.

Later calls walk a pool of candidates in order. The pool starts as the seed's own similarity list and grows by the lists of the tracks already picked, without duplicates. A candidate that passes every rule is taken, and the distance rules redraw their limits.

When a full pass takes nothing, the generator first grows the pool. If that adds nothing, it relaxes one rule, going round the rules in turn. A distance limit drops by one per relaxation down to its floor. So the requirements loosen one track at a time, and the run does not simply fail.

An id that no track on the device carries gets passed over silently. The similarity graph comes from the computer's library and can name songs that were never synced.

The screens

The Music menu's Genius row opens the Genius list once a Genius playlist exists, and the intro screen until then. Starting Genius publishes the new playlist as the playback source and lands on that list, with Refresh and Save Playlist above the tracks. Now Playing arrives over it once the firmware's 3000 ms floor has passed. Refresh runs the generator again, and the random limits give a new list. Save Playlist writes a real playlist into the database, seed included.

Now Playing also has a Genius layout with a slider. A wheel turn while the finger is down moves the switch and nothing else, and the release starts the run.

Tests

Synthetic graphs pin the order of the walk, a candidate killed by genre, the jitter's relaxation and the redraws. The generator then runs over a real device's Extras.itdb through Chikuma's SQLite layer: seed first, 25 tracks, no repeats, never the same artist or album twice in a row, and Refresh answering with a different list.

Differences

Plays and skips made on Chikuma itself are not counted yet, so the skip rule sees the statistics of the last sync only. The pool and seen-set have fixed ceilings in Chikuma, where the device grows its vectors.