Kodi Community Forum
Is it possible to create a complex query in a smart playlist - Printable Version

+- Kodi Community Forum (https://forum.kodi.tv)
+-- Forum: Support (https://forum.kodi.tv/forumdisplay.php?fid=33)
+--- Forum: General Support (https://forum.kodi.tv/forumdisplay.php?fid=111)
+---- Forum: OS independent / Other (https://forum.kodi.tv/forumdisplay.php?fid=228)
+---- Thread: Is it possible to create a complex query in a smart playlist (/showthread.php?tid=371256)



Is it possible to create a complex query in a smart playlist - patmcgee1983 - 2023-01-12

Hi,
I've been using Kodi for several years now, with 2 Matrix clients sharing a MYSQL database, and a fileshare located on a VM. It has been excellent so far.

From what I've seen the smart playlists are simply a MYSQL query to return the results, which, by the way works great, however there are some limitations.

One thing I've always wanted to do is create a more complex query using AND/OR's.

For example, a smart playlist might look something like this

Path Contains 'myAwsomeFolder'
MyRating > 8

and you can have all conditions required to be true, or any of the conditions required to be true

What I'd like to do is something like this:

Path Contains ('myAwsomeFolder' OR 'myAwsomeFolder2' OR 'myAwsomeFolder3')
AND MyRating > 8

Is this something that is possible within the UI? Perhaps with the Nexus upgrade? Perhaps something more advanced that can be done?

Thanks!


RE: Is it possible to create a complex query in a smart playlist - Karellen - 2023-01-12

Focusing on your above example only...

I would have thought that Path Contains 'myAwsomeFolder' would also capture Path Contains ('myAwsomeFolder' OR 'myAwsomeFolder2' OR 'myAwsomeFolder3')
The operator is contains and myAwsomeFolder2 does contain myAwsomeFolder

Do you have other sources in addition to myAwsomeFolder? Wouldn't you want to list all movies that match MyRating > 8?


RE: Is it possible to create a complex query in a smart playlist - patmcgee1983 - 2023-01-12

Haha, ok, bad example

how about

Path Contains ('abc' OR 'def' OR 'xyz')
AND MyRating > 8


RE: Is it possible to create a complex query in a smart playlist - patmcgee1983 - 2023-01-12

In reality what I'm trying to is much more complex, as I have numerous folders by genres.

In some cases I want to have a smart playlist, for example that contains the best of multiple genres
so

where (path contains 'house' OR path contains 'lounge' OR path contains 'hip hop')
AND
UserRating > 8


RE: Is it possible to create a complex query in a smart playlist - black_eagle - 2023-01-12

You can probably do something like
xml:
<rule field="path" operator="contains">
    <value>abc</value>
    <value>def</value>
    <value>xyz</value>
</rule>



RE: Is it possible to create a complex query in a smart playlist - Dumyat - 2023-01-12

@black_eagle you beat me to it with your your suggestion!  Wink
Only thing different I was going to add was another rule for user rating is greater than 8 which would be applied to the first 3 rules.


RE: Is it possible to create a complex query in a smart playlist - patmcgee1983 - 2023-01-12

I think you're still limited to either matching ALL or matching ANY of the rules.

I want to match either rule 1 and 2, and rule 3, but I have the match field.

xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<smartplaylist type="songs">
    <name>lounge and beats best</name>
    <match>all</match>
    <rule field="path" operator="contains">
        <value>lounge</value>
    </rule>
    <rule field="path" operator="contains">
        <value>beats</value>
    </rule>
    <rule field="userrating" operator="greaterthan">
        <value>7</value>
    </rule>
    <limit>1000</limit>
    <order direction="ascending">random</order>
</smartplaylist>

I wonder though, if I tried adding a second match rule in if it'd work?

xml:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<smartplaylist type="songs">
    <name>lounge and beats best</name>
    <match>any</match>
    <rule field="path" operator="contains">
        <value>lounge</value>
    </rule>
    <rule field="path" operator="contains">
        <value>beats</value>
    </rule>
<match>all</match>
    <rule field="userrating" operator="greaterthan">
        <value>7</value>
    </rule>
    <limit>1000</limit>
    <order direction="ascending">random</order>
</smartplaylist>



RE: Is it possible to create a complex query in a smart playlist - patmcgee1983 - 2023-01-12

Tested my above theory - the second match is ignored. So I don't think we've got a solution yet


RE: Is it possible to create a complex query in a smart playlist - kcook_shield - 2023-01-13

See https://forum.kodi.tv/showthread.php?tid=361828&pid=3027605#pid3027605 for my working example of combining Smartplaylists to pull this off.

Taking the example in previous posts, this (untested) should work by setting up 2 Smartplaylists like:

1) First setup a list (I use "z_" prefix, and this way you can "hide" this playlist (unless you want it displayed):
I'll call this one z_lounge_and_beats_paths.xsp :

xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<smartplaylist type="songs">
    <name>lounge and beats path</name>
    <match>any</match>
    <rule field="path" operator="contains">
        <value>lounge</value>
    </rule>
    <rule field="path" operator="contains">
        <value>beats</value>
    </rule>
</smartplaylist>

2) Setup the "real" combined smartlist
I'll call this lounge_and_beats_best.xsp :

xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<smartplaylist type="songs">
    <match>all</match>
    <rule field="playlist" operator="is">
        <value>lounge and beats path</value>
    </rule>
    <rule field="userrating" operator="greaterthan">
        <value>7</value>
    </rule>
    <limit>1000</limit>
    <order direction="ascending">random</order>
</smartplaylist>

To hide the helper smartplaylists (prefix "z_" above) , use configuration:

xml:

<advancedsettings>
  <video>
    <excludefromlisting action="append">
     <regexp>z_.*xsp</regexp>
   </excludefromlisting>
  </video>
</advancedsettings>



RE: Is it possible to create a complex query in a smart playlist - patmcgee1983 - 2023-01-13

Brilliant!

That was exactly what I was looking for!

Thanks so much!