Difference between revisions of "Smart playlists"
(Created page with "XBMC supports "Smart" playlists for all types of media, which essentially use a set of rules to limit the results from the databases. They can be created either by using the buil...")
|Line 155:||Line 155:|
Revision as of 21:44, 11 December 2011
XBMC supports "Smart" playlists for all types of media, which essentially use a set of rules to limit the results from the databases. They can be created either by using the built-in GUI Smart Playlist Editor accessible from the Playlist section, or by creating an xml file with the extension .xsp (XBMC Smart Playlist). They should be placed in your Userdata directory and cannot be read off of remote shares at present.
1 Format of a Smart Playlist File
Smart playlists are plain text files that can be parsed by an xml reader. Any text editor can be used to create them.
The format is as follows:
<?xml version="1.0"?> <smartplaylist type="music"> <name>All U2 from after 1990</name> <match>all</match> <rule field="artist" operator="is">U2</rule> <rule field="year" operator="greaterthan">1990</rule> <limit>50</limit> <order direction="descending">playcount</order> </smartplaylist>
Smart playlists can be of one of the following types:
- songs (default)
1.2 Name and Match
Basically there are 2 header tags,
<match> and then a set of
<rule> tags that define the rules to use, along with an
<order> tag to allow sorting and a
<limit> tag to limit the returned results. Note that the tags and attributes are all case-sensitive. The
<name> tag is the name of the playlist and the
<match> tag indicates how the
<rule> tags should be matched. If
<match>all</match> like in the above example, then only songs which satisfy all the
<rule>'s will be included. If
<match>one</match> is specified, then songs that satisfy any one (or more) of the
<rule>'s will be included.
<rule> tags, of which there can be as many as you wish, have 2 attributes (
operator) and a value.
Depending on the type of the Smart Playlist different
fields are available:
operator attribute specifies the rule that should be used to match the parameter to the
field. All matching is done case-insensitive. The allowed
- True if the field contains the parameter as a substring
- True if the field does not contain the parameter as a substring
- True if the field matches the parameter exactly
- True if the field does not match the parameter exactly
- True if the start of the field matches the parameter
- True if the end of the field matches the parameter
- True if the content of the field is less than the parameter
- True if the content of the field is greater than the parameter
- True if the content of the field comes after the parameter
- True if the content of the field comes before the parameter
- True if the field falls in the last range specified by the parameter. Only applicable for a date field.
- True if the field does not fall in the last range specified by the parameter. Only applicable for a date field.
1.4 Limit and Order
<limit> tag simply takes a number of songs as it's limit. A missing limit tag, or
<limit>0</limit> will retrieve all matching songs. The
<order> tag has a
direction attribute, the values of which can be
descending, and it's value is a field as above, or can be
<order>random</order> 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
<rule> 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.
2 Combining Playlists
field can be used to combine several playlists together. When playlists are combined, the
<order> tags of the included playlists are ignored; only the
<limit> 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
<?xml version="1.0"?> <smartplaylist type="music"> <name>Recently played Rock Tracks from the 1970s</name> <match>all</match> <rule field="playlist" operator="is">Rock Music from the 1970s</rule> <rule field="playlist" operator="is">Recently Played Songs</rule> </smartplaylist>
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.
3.1 Recently played songs
<?xml version="1.0"?> <smartplaylist type="music"> <name>Recently Played Songs</name> <match>all</match> <rule field="lastplayed" operator="inthelast">2 weeks</rule> <order direction="descending">lastplayed</order> </smartplaylist>
3.2 Top 100 songs
<?xml version="1.0"?> <smartplaylist type="music"> <name>Top 100 Songs</name> <match>all</match> <rule field="playcount" operator="greaterthan">0</rule> <order direction="descending">playcount</order> <limit>100</limit> </smartplaylist>
3.3 Rock music from the 1970s
<?xml version="1.0"?> <smartplaylist type="music"> <name>Rock Music from the 1970s</name> <match>all</match> <rule field="genre" operator="is">Rock</rule> <rule field="year" operator="greaterthan">1969</rule> <rule field="year" operator="lessthan">1980</rule> </smartplaylist>