Smart playlists

Kodi supports smart playlists for all types of media (excluding pictures), which essentially use a set of rules to limit the results from the databases. This means that to be able to create a smart playlist in the GUI, music/video must first be added to the libraries using a scraper addon or by creating NFO files. Smart playlist can be created either by using the built-in GUI smart playlist editor accessible from the Playlists section, or by creating an XML file with the extension XSP (XBMC Smart Playlist).

Smart playlist for music
Music -> Playlists -> New smart playlist

Smart playlist for video
Video -> Playlists -> New smart playlist

Format of a smart playlist file
Smart playlists are plain text files that can be parsed by an XML reader (e.g. Visual Studio and Notepad++). Any text editor can be used to create them. They should be saved with the extension XSP and placed in your userdata directory, as there is only limited support for smart playlists saved outside of the userdata folder.

The format is as follows:

Types
Smart playlists can be of one of the following types:
 * songs (default)
 * albums
 * movies
 * tvshows
 * episodes
 * musicvideos
 * mixed (audio and music videos)

Name and Match
Basically there are two header tags,  and   and then a set of   tags that define the rules to use, along with an   tag to allow sorting and a   tag to limit the returned results. The  tag is the name of the playlist and the   tag indicates how the   tags should be matched. If  like in the above example, then only songs which satisfy all the  's will be included. If  is specified, then songs that satisfy any one (or more) of the  's will be included.

Rules
The  tags, of which there can be as many as you wish, have two attributes (  and  ) and a   tag.

Fields
Depending on the type of the smart playlist different s are available:

Operators
The  attribute specifies the rule that should be used to match the parameter to the. All matching is done case-insensitive. The allowed s are:

Limit and Order
The  tag simply takes a number of songs as it's limit. A missing limit tag, or  will retrieve all matching songs. The  tag has a   attribute, the values of which can be   or , and it's value is a field as above, or can be   if you want a random ordering returned. Note that random should be used with care - it is quite slow if the returned results from the  sets is large (more than 500 items).

The above example, therefore selects all songs whose artist field is U2 and whose year field is greater than 1990, orders them by the number of times they've been played (most played first) then limits it to just 50. Thus, the top 50 songs you've played from all U2 songs published after 1990.

Grouping
Grouping was added in v13. The  tag allows to group the resulting list of media items by a specific category. The final list will consist of folder nodes containing matching media items. Depending on the type of the Smart Playlist the following grouping categories exist:

Mixed grouping
For the sets grouping category there is support for additional so called mixed grouping. The difference to normal grouping is that the resulting list will not just be a list of grouped folders but a mix of media items and grouped folders. Mixed grouping can be controlled using the mixed attribute in the  tag with a boolean value (true or false).

Combining playlists
The    can be used to combine several playlists together. When playlists are combined, the  and   tags of the included playlists are ignored; only the   and   of the final playlist are used.

As a simple example, lets create a new playlist combining the "Rock Music from the 1970s" and "Recently Played Songs" playlists above, to produce a playlist with the recently played rock songs from the 1970s.

Recently played rock tracks from the 1970s

Using this system allows very complex queries to be built. Note that in a single playlist, you can only match ALL of the rules, or ONE (or more) of the rules. This is basically either ANDing the conditions together, or ORing them together. You cannot mix AND with OR in a single playlist. To build up a playlist with both AND and OR operations on the rules, you use multiple playlists to group the AND operations and the OR operations, then combine them as above.

In progress movies
Moives that are still in progress ordered by last played.

Last played movies (history)
Not in progress movies with a play count bigger than 0 ordered by last played.

One random movie
Only one movie is added to the playlist. This isn't possible to create in the GUI because the lower limit is 10 (or at least the limit needs to be edited afterward).

Even though the limit is only one you still need to set random order.

Though the difference between a playlist containing the GUI minimum 10 or edited to contain only 1 isn't significant. Pressing play on both of them will play a random movie. The "benefit" with a playlist only containing one movie is that you'll only be presented with one if you open the playlist.

Movies with a specific subtitle language
Movies that contain Swedish (swe) internal subtitles.

Last played episodes (history)
Not in progress episodes and with a play count bigger than 0 from the last 6 months ordered by last played.

In progress episodes
Episodes that are still in progress from the last 2 weeks ordered by last played.

Last played TV shows
TV shows that've been played in the last 3 months ordered by last played with play count 0.

The play count setting makes it so if all episodes have been watched it doesn't show up, but as soon new unplayed episodes or seasons are scraped the TV Show will show up again in the playlist.

TV show with specific episode names
A playlist with The Simpsons' Treehouse of Terror episodes.

Random unplayed episodes from a TV show
10 random episodes with a play count of 0 from The Simpsons.

Random unplayed episodes from several TV shows
10 random episodes with a play count of 0 (i.e. unplayed) from six different shows. Though as it's random this can create a list with two to ten episodes of the same show in a row.

If you specifically want to watch 6 random episodes from 6 different shows you could create playlists that are limited to 1 episode and 1 show (see One random movie example). Then you queue the 6 playlists.