LMS, play Dynamic playlists created with Dynamic Playlist Creator plugin

Can I use the “squeezebox.call_method” to play dynamic playlists created with the dynamic playlist creator plugin?

I can export a dynamic playlist to a static playlist that I can play but I would like to play the dynamic playlists directly with the “squeezebox.call_method”.

Thanks,
Eric

the wiki page at https://github.com/AF-1/lms-dynamicplaylists/wiki/CLI-commands

seems to provide a method for doing this but so far I’ve been unable to get it to work

But that is probably more to do with my inability to get to grips with yaml and passing parameters

At the moment I have a little script as follows

lms_dynamic_play:
  alias: Lms Dynamic
  mode: single
  icon: mdi:music
  sequence:
  - service: squeezebox.call_query
    data:
      command: dynamicplaylist
      parameters:
      - playlist
      - play
      - dplusercustom_TestList
    target:
      entity_id: media_player.picoreplayer_2

but it doesn’t seem to do anything other than stop whatever is currently playing on the squeezelite player

any help or hints gratefully accepted

to answer my own question the following script fragment works in my scripts.yaml

lms_dynamic_play:
  alias: Lms Dynamic
  mode: single
  icon: mdi:music
  sequence:
  - service: squeezebox.call_method
    data:
      command: dynamicplaylist
      parameters:
      - playlist
      - play
      - dplccustom_guitars
    target:
      entity_id: media_player.picoreplayer_2

note that the playlist prefix is dplccustom_ ie a double c
and that the actual playlist name is lowercase no matter what you have called it

the following curl command also works

curl -g -X POST -d '{"id":1,"method":"slim.request","params":["b8:27:eb:82:e9:e3",["dynamicplaylist","playlist","play","dplccustom_rocksteady"]]}' http://192.168.XX.YY:9000/jsonrpc.js

if you hover your mouse over the play button for your dynamic playlist you can see how it is called

hope this prevents anyone else tearing their hair out for a few days

A fuller script to do this follows

#
# in the following array SqueezePlayLists
# you must replace any URL Encoding strings by the actual characters they represent
# for exampe %2b is + and %2f is /
#
# the string dplstaticpl_PGPBtJ1Dd6Co5RDdrt9%2F%2FJKp1d8
# has to become dplstaticpl_PGPBtJ1Dd6Co5RDdrt9//JKp1d8
#
lms_dynamic_play:
  alias: Lms Dynamic
  mode: single
  icon: mdi:music
  sequence:
  - variables:
      SqueezePlayLists:
        Dinner: 'dplstaticpl_PGPBtJ1Dd6Co5RDdrt9//JKp1d8'
        Karen: 'dplstaticpl_xXMhdJQR/Up59ZgBx+j4ypsz55k'
        Speaker-Test: 'dplstaticpl_maRsj0ELIYXNTbXiYejkTvghpek'
        Guitars: 'dplccustom_guitars'
        Heavy: 'dplccustom_heavy'
        Long_Songs: 'dplccustom_long_songs'
        My_Folk: 'dplccustom_my_folk'
        My_Jazz: 'dplccustom_my_jazz'
        My_Prog: 'dplccustom_my_prog'
        RockSteady: 'dplccustom_rocksteady'
        Short_Songs: 'dplccustom_short_songs'
        1950s: 'dplccustom_1950s'
        1960s: 'dplccustom_1960s'
        1970s: 'dplccustom_1970s'
        1980s: 'dplccustom_1980s'
        '1969': 'dplccustom_1969'
        '1975': 'dplccustom_1975'

      Item: "{{ SqueezePlayLists[ states('input_select.lmsplaylist_select') ]  }}"
  - service: squeezebox.call_method
    data:
      command: dynamicplaylist
      # parameters: "{{ ['playlist', 'play', item] }}"
      parameters:
      - playlist
      - play
      - "{{ Item }}"
    target:
      entity_id: media_player.{{ states('input_select.lms_instance') }}

The only way i have found to obtain the DYNAMICPLAYLIST_ID for a static playlists is by moving the mouse pointer over the play link for a static playlist in

Home > Dynamic Playlists > Static Playlists Menu

and by then copying the link and extracting the DYNAMICPLAYLIST_ID from it

note you must replace any URL Encoding strings by the actual characters they represent
for example %2b is + and %2f is /

the DYNAMICPLAYLIST_ID dplstaticpl_PGPBtJ1Dd6Co5RDdrt9%2F%2FJKp1d8
has to become dplstaticpl_PGPBtJ1Dd6Co5RDdrt9//JKp1d8

before you can use this in in any squeezebox_call_method parameters

Update !!!

Having heard from the creator of the LMS DynamicPlayList plugin how the url for static playlists is created

The specific part after dplstaticpl_ is the SHA1 digest of the playlist url as a base64 encoded string. As you have discovered, this ony applies to static playlists. All other dynamic playlists use the filename to create the playlist id

For Example:
Playlist url/path from the LMS database: file:///Users/af1/Music/LMS%20Playlists/Bookmarked%20Tracks.m3u
SHA1 digest of the playlist url as a base64 encoded string: jor13XtXjcbmjwFHTwGGp8xPK1k
Your playlist id for CLI commands: dplstaticpl_jor13XtXjcbmjwFHTwGGp8xPK1k

I have created a little perl script which you can run on your LMS server in the playlists folder, which will generate the correct playlist id for using in scripts

#!/usr/bin/perl
BEGIN {
    push ( @INC,"/opt/logitechmediaserver/CPAN");
}
use Digest::SHA1 qw(sha1_base64);

$PLAYLIST = "/home/Playlists";

opendir(D, $PLAYLIST) || die "Can't open directory $PLAYLIST: $!\n";

@list = grep /m3u$/, readdir(D);
closedir(D);

foreach my $f (@list)
{

        $string = "file://" . $PLAYLIST . "/" . $f;
        my $playlistid = 'dplstaticpl_'.sha1_base64($string);

        print "$string - $playlistid\n";
}

Hope it helps others

1 Like