Sorting Guide¶
There are various sort options available depending on what you want to sort.
Plex Sort Order¶
The first thing to note is that Plex utilizes an ASCII based sort order, which defines which priority a character gets.
Character Priority for Plex Sorting
This is the sorting priority as of Plex Media Server release 1.41.2.9200
Collection Sorting¶
Collections can be sorted so that they appear in a specific order in the Collections
and Library
tab of your library. This is done using the sort_title
attribute.
When using the above Plex Sort Order, a collection with a sort title of !!!My Collection
would appear
before a sort title of !My Collection
, which would be placed before a sort title of My Collection
Let's start with an unmodified set of collections which do not specify a custom sort order:
Example 1 - No Sorting
Now let's use the sort_title
attribute to reorder these collections slightly
Example 2 - Basic Reorder Sorting
collections:
Collection 1:
plex_all: true
sort_title: Collection 3
Collection 2:
plex_all: true
sort_title: Collection 1
Collection 3:
plex_all: true
sort_title: Collection 2
The above could also be achieved using any form of ASCII sort order. This example will produce the same outcome, but uses a (perhaps) illogical set of ASCII characters to define the sort title.
You will often see users using sort titles such as +++++++_My Collection
or !010_My Collection
in order to force a specific order of collections.
Whilst it may not seem logical at a glance, the ASCII sort order allows a lot of flexibility for power users to be able to tailor the ordering of collections.
Kometa Default Collection Sorting¶
When utilizing the Kometa Defaults, they are all built on the same format for their sort titles:
<<sort_prefix>><<collection_section>><<pre>><<order_<<key>>>><<title>>
Users aren't expected to understand what this does, but users can use the sort_prefix
and collection_section
Template Variable to amend the order of categories of collections.
I want to know what that means
<<sort_prefix>><<collection_section>><<pre>><<order_<<key>>>><<title>>
Those parts are all defined as Template Variables, and as such you can override any of them. This format itself is also defined as a Template Variable, so you can override the entire format if you wish.
As a specific example, the "IMDB Lowest Rated" collection has a sort title of !020_IMDb Lowest Rated
- The
!
character makes sure these collections appear at the top of the collection tab. - The
020
is the collection section, which is used to group collections together. - The
_
is a separator between the collection section and the title; no particular purpose other than that. - The
IMDb Lowest Rated
is the title of the collection.
<<order_<<key>>>>
is a Template Variable that is used to order collections within the same collection section. Without this, as above, the collections are sorted by their titles,
since everything before that will be identical for all the collections in a given "section". If you want to modify this, you can set the order key.
Example 3 - Reordering Kometa Defaults
libraries:
Movies:
collection_files:
- default: tmdb
- default: trakt
template_variables:
sort_prefix: ":" #(1)!
- Because the
:
character is a higher priority character than the default `! in the Plex Sort Order, this will place the Trakt collections at the top of the list ahead of all other collections.
Sorting the groups of Default collections¶
Each group of collections created by the Kometa defaults has a default "collection section", so they are displayed in a standard order, which is shown
here. If you want to change the order in which the sections appear within the set of
default-generated collections, you would use the collection_section
Template Variable.
For example, these collection groups display in this order, by default:
If you wanted to reverse the order in which those groups of collections appear [not the collections within them], you would use the collection_section
Template Variable:
libraries:
Movies:
collection_files:
- default: streaming
template_variables:
collection_section: "060" #(1)!
- default: universe
template_variables:
collection_section: "050" #(2)!
- default: network
template_variables:
collection_section: "040" #(3)!
- default: genre
template_variables:
collection_section: "030" #(4)!
- This sets the
collection_section
for the streaming collections to060
, so they take the place of the genre collections. - This sets the
collection_section
for the universe collections to050
, so they take the place of the network collections. - This sets the
collection_section
for the network collections to040
, so they take the place of the universe collections. - This sets the
collection_section
for the genre collections to030
, so they take the place of the streaming collections.
That will result in those four groups of collections appearing in the opposite order to the default.
Sorting the collections within the groups of Default collections¶
You can re-order collections within each Defaults File using the order_<<key>>
Template Variable.
<
Example 4 - Reordering Collections within a Kometa Defaults File
libraries:
Movies:
collection_files:
- default: trakt
template_variables:
sort_prefix: ":" #(1)!
- default: tmdb
template_variables: #(2)!
order_top: 1
order_popular: 2
order_airing: 3
order_air: 4
order_trending: 5
- Because the
:
character is a higher priority character than the default `! in the Plex Sort Order, this will place the Trakt collections at the top of the list ahead of all other collections. - file has 5 collections, each with a defined key. I have reordered each of the collections to appear in the order that I specified.
Sorting the contents of the collections within the groups of Default collections¶
You can also re-order the contents of each collection within a Defaults File using either the sort_by
or collection_order
Template Variables. The specific option you use will depend
on the specific default file [it is ultimately controlled by which type of collection is created by the file, manual or smart], and will be listed on the relevant wiki page.
For example:
libraries:
Movies:
collection_files:
- default: basic
template_variables:
sort_by: year.desc #(1)!
sort_by_episodes: episode_release.asc #(2)!
- default: imdb
template_variables:
collection_order: release #(3)!
collection_order_lowest: alpha.asc #(4)!
- This sets the sort_by for all collections created by
basic
toyear.desc
, overriding the default ofrelease.desc
.basic
creates smart collections, so it usessort_by
. - This sets the sort_by for the
New Episodes
collection created bybasic
toepisode_release.
, overriding the default ofrelease.desc
AND the override value set by the previous Template Variable. - This sets the
collection_order
for the IMDB collections torelease
, overriding the default ofcustom
.imdb
creates manual collections, so it usescollection_order
. - This sets the
collection_order
for theIMDb Lowest Rated
collection toalpha.
, overriding the default ofcustom
AND the override value set by the previous Template Variable.
Builder Sorting¶
When using a collection Builder, it is possible to sort the items within the collection in a number of ways.
This can be useful to control the particular items that end up in the collection, or to control the order that they appear in.
For example, perhaps you want the ten most recent horror movies in your library ordered by critic rating
collections:
Recent Horror:
# start with all the horror in my library, sorted in descending release order
plex_search:
sort_by: release.desc
any:
genre: horror
# put the first ten of those [so the most recent] in the collection
limit: 10
# Sort the items that end up in the collection by critic rating descending
collection_order: critic_rating.desc
Collection Order¶
Within Plex, the attribute that controls the top-level sorting is called the collection_order
and there are three options presented within the Plex UI for this:
- Alpha (sorted alphabetically)
- Release (sorted by release date, this is the default order if you do not specify one)
- Custom (sorted in a custom order)
When using Kometa builders, the majority of builders will require collection_order: custom
to be set, which allows you to sort either by a sort order that the Builder source allows for
(such as sorting an MDBList by revenue), or by the default order that Kometa receives the items from the Builder (such as sorting the IMDb Top 250 in the order that they appear on the list).
Example 5 - Custom Collection Order
If I failed to set collection_order: custom
in this Builder, the Collection Order would be the default Plex order, which is release date.
Manual and Smart Collection Sorting¶
Plex has two types of collections, "Manual" and "Smart".
When using Kometa, a "Manual" collection is one which is static - the collection will only update when you run Kometa.
A "Smart" collection is one which is a living/breathing collection, as you add new media or the data about your media changes, the collection will update in real-time to reflect those changes.
Manual collections can utilize the sort_by
attribute to define the sorting.
Example 6 - Manual Collection Sorting
collections:
Top Action Movies:
collection_order: custom
plex_search:
all:
genre: Action
sort_by: audience_rating.desc
limit: 50
to reduce line count, you can replace the custom
collection order with your desired sort_by
value. This will still set the collection order to custom
within Plex,
but will reorder the items within the collection as it would if you were using the sort_by
attribute.
The Sort Orders available for "Manual" collections are outlined on the Manual Plex Builder page.
Tip
Although the Sort Options are listed on the Manual Plex Builder page, the options are available to mostly any Builder if you use the collection_order
attribute to define a sort_by
value
Smart collections can only utilize sort_by
if it is part of a Smart Filter.
Example 7 - Smart Filter Sorting
if you have a Smart Label collection, you can pass the sort_by
value you want as part of the smart_label
attribute.
Example 8 - Smart Label Sorting
The Sort Orders available for "Smart" collections are outlined on the Plex Builder page.
Tip
Although the Sort Options are listed on the Smart Plex Builder page, the options are available to mostly any Builder when you use a smart Label Builder.
Secondary Sorting¶
You can also leverage "Secondary Sorting" This goes beyond the single sort settings you can apply to a collection in Plex.