Add a sorted_playlist macro

This commit is contained in:
Benson Chu 2026-04-04 14:34:32 -05:00
parent ca8d753cd0
commit 55205ec0ac
2 changed files with 16 additions and 3 deletions

View file

@ -87,7 +87,7 @@ smartplaylist:
- name: "precision.m3u"
query: ['plprecision:1']
- name: "exercise.m3u"
query: ['label:exercise-'] # ['^plexercise::^$ plexercise-']
query: ['sorted_playlist:exercise'] # ['^plexercise::^$ plexercise-']
- name: "chiptune.m3u"
query: ['genre:chiptune', 'genre:8-bit', 'plchiptune:1']

View file

@ -46,10 +46,23 @@ def parse_sorted_query_override(
"""Given a list of strings, create the `Query` and `Sort` that they
represent.
"""
# First, expand any playlist: macros
# First, expand any playlist: and sorted_playlist: macros
expanded_parts = []
for part in parts:
if part.startswith('playlist:') and not re.match(r"[+-]$", part):
if part.startswith('sorted_playlist:'):
# Extract playlist name
playlist_name = part[len("sorted_playlist:"):]
if valid_playlist(playlist_name):
# Expand to the query
expanded_parts.extend(expand_playlist_query(playlist_name))
# Inject the sort
expanded_parts.append(f"playlist:{playlist_name}-")
else:
# Unknown playlist, just let it go through
expanded_parts.append(part)
elif part.startswith('playlist:') and not re.match(r"[+-]$", part):
playlist_name = part[len("playlist:"):]
if valid_playlist(playlist_name):