Smart playlists

XBMC 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
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.

Random movie
Only one movie is added to the list. 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.

Last played episodes (history)
Not in progress episodes and playcount > 0.

Last played TV shows
Including TV shows with in progress episodes.