Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 10 of 10
  1. #1
    Senior Member
    Join Date
    Jul 2010
    Posts
    251

    add url to client playlist

    Hi.

    I have a context menu and I'd like the url of a tracked you click on to be added (= inserted = play next) to the client's current playlist.

    Code:
    my %baseParams = ();
    my $baseMenu = {
    	'actions' => {
    		'do' => {
    			'cmd' => ['playlist', 'insert'],
    			'itemsParams' => 'params',
    		},
    		'play' => {
    			'cmd' => ['playlist', 'insert'],
    			'itemsParams' => 'params',
    		},
    	}
    };
    $request->addResult('base',$baseMenu);
    my $cnt = 0;
    
    foreach my $ratedtrack (@moreratedtracks) {
    	my %itemParams = (
    		'url' => $ratedtrack->url,
    	);
    	$request->addResultLoop('item_loop',$cnt,'params',\%itemParams);
    It kind of works but the url itself that's added to the client playlist is malformed/transformed and therefore not valid in LMS.

    It should be:
    Code:
    #EXTURL:file:///Users/user/Music/MEDIA/04%20trackname.m4a
    /Users/user/Music/MEDIA/04 trackname.m4a
    Instead I get:
    Code:
    #EXTURL:///./url:file:/Users/user/Music/MEDIA/04%2520trackname.m4a
    ///./url:file:/Users/user/Music/MEDIA/04%2520trackname.m4a
    It loses 2 slashes after file: and prepends ///./url:

    How do I get LMS to add the correct url to the client's playlist? I know it's because of how I use the parameter but so far I haven't managed to get it right.

    BTW in the a track's context menu (e.g. Material, jivelite, squeezeplay) I can only tie 1 command to the title entry in a context menu like the one above because all I can do is click on the title. Is that correct?

  2. #2
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    11,290
    Quote Originally Posted by afriend View Post

    How do I get LMS to add the correct url to the client's playlist? I know it's because of how I use the parameter but so far I haven't managed to get it right.
    I wonder if you need to use a CLI command that supports tagged parameters. Feels like it just prepend the url attribute to the actual url in the way you are currently doing it.
    Try using the “playlistcontrol cmd:insert track_id:42” command instead, I think that’s what LMS does internally. I’m guessing it works for you to use the track id instead of the url.

    Quote Originally Posted by afriend View Post
    BTW in the a track's context menu (e.g. Material, jivelite, squeezeplay) I can only tie 1 command to the title entry in a context menu like the one above because all I can do is click on the title. Is that correct?
    Don’t remember, I’ll let Michael or someone else answer this. Can you hold touch on an item ?
    Erland Isaksson (My homepage)
    Developer of many plugins/applets
    Starting with LMS 8.0 I no longer support my plugins/applets (see here for more information )

  3. #3
    Senior Member
    Join Date
    Jul 2010
    Posts
    251
    Quote Originally Posted by erland View Post
    Try using the “playlistcontrol cmd:insert track_id:42” command instead, I think that’s what LMS does internally. I’m guessing it works for you to use the track id instead of the url.
    Thank you, that worked. Do you know how to concat a LMS string and another string variable in the pagetitle?

    Code:
    [% pagetitle = 'PLUGIN_MY_STATIC_STRING_FIRSTPART' | string %]
    I need the static part, then a space and then the content of some variable.

    BTW what's the [%- IF !ajaxUpdate; -%] for? To prevent multiple requests while the first one hasn't finished yet? Just wondering if I need it.

  4. #4
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    11,290
    Quote Originally Posted by afriend View Post
    Thank you, that worked. Do you know how to concat a LMS string and another string variable in the pagetitle?

    Code:
    [% pagetitle = 'PLUGIN_MY_STATIC_STRING_FIRSTPART' | string %]
    I need the static part, then a space and then the content of some variable.
    It’s too long since I worked with this so I honestly don’t remember, hopefully someone else sees this post and can give you an answer.

    Quote Originally Posted by afriend View Post
    BTW what's the [%- IF !ajaxUpdate; -%] for? To prevent multiple requests while the first one hasn't finished yet? Just wondering if I need it.
    If I remember correctly some skins just update the page body when data changes not the header and footer and ajaxUpdate flag is used to support this. If ajaxUpdate is set you just deliver the body otherwise you deliver the whole page. So I think you will need the ajaxUpdate if statement for it to work in all skins.

    Could possibly be a bit related to your first question because it might mean that it’s a bad idea to have dynamic data in header and footer, for example in the pagetitle.

    Anyway, as you might understand from my phrasing I’m guessing a bit here, someone who knows this stuff better have to answer if you want a definitive answer.
    Erland Isaksson (My homepage)
    Developer of many plugins/applets
    Starting with LMS 8.0 I no longer support my plugins/applets (see here for more information )

  5. #5
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,545
    Quote Originally Posted by afriend View Post
    Thank you, that worked. Do you know how to concat a LMS string and another string variable in the pagetitle?

    Code:
    [% pagetitle = 'PLUGIN_MY_STATIC_STRING_FIRSTPART' | string %]
    I need the static part, then a space and then the content of some variable.

    BTW what's the [%- IF !ajaxUpdate; -%] for? To prevent multiple requests while the first one hasn't finished yet? Just wondering if I need it.
    Just add another statement to do the concatenation:
    Code:
    [% pagetitle = 'PLUGIN_MY_STATIC_STRING_FIRSTPART' | string; pagetitle = pagetitle _ " " _ othervariable %]
    The ajaxUpdate flag is used in some skins to render partial content of a page. Some pages would use this to update the page content without re-loading it. Eg. the headers etc. would stay in place, only parts of the page would be updated.
    Michael

    "It doesn't work - what shall I do?" - "Please check your server.log and/or scanner.log file!"
    (LMS: Settings/Information)

  6. #6
    Senior Member
    Join Date
    Jul 2010
    Posts
    251
    Quote Originally Posted by mherger View Post
    Just add another statement to do the concatenation:
    Code:
    [% pagetitle = 'PLUGIN_MY_STATIC_STRING_FIRSTPART' | string; pagetitle = pagetitle _ " " _ othervariable %]
    Thank you for that.

    About that context menu I mentioned in the first post:

    it's supposed to give list of track title + album name.

    It seems that piCorePlayer, SB Touch, SB Radio and Material skin use the jive menu:

    Code:
    if ( $tags->{menuMode} ) {
    	my $jive = {};
    	my $actions = {
    		go => {
    			player => 0,
    			cmd => ['ratingslight', 'moreratedtracksmenu', $trackID, $artistID],
    		},
    	};
    	$jive->{actions} = $actions;
    	return {
    		type => 'redirect',
    		name => $text,
    		jive => $jive,
    	};
    The function/dispatch called returns an item_loop with this value for each track as $text:

    Code:
    $tracktitle." ( ".$ratingtext." )\nAlbum: ".$albumname
    #1
    Now I have a style/font size problem:

    Material somehow does a perfect job and for each track puts the second line "Album: ".$albumname in a smaller font (even in a slightly different color) so that everything fits into one line. And it looks good.

    piCorePlayer, Touch and Radio also display both "lines" but both in the same font size. It looks very crowded, just not good at all.
    I could, of course, return only one line for the jive menu without the "\n" and probably lose the album information so the line would get too long.

    But before I do so (and I'd really like to keep the album info) I thought I'd ask:

    is there a way to assign a different font size to the second line?

    I mean, there is only 1 "name" key, so I can't split the line in two and send 2 values. Even then I wouldn't know how to assign a different font size to the second line/value.

    #2
    And in that context menu can I assign only one action to each item that's executed when a user clicks on it? I can't hold touch and no buttons or other icons are shown in Material or on any of the players.

  7. #7
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    11,290
    Quote Originally Posted by afriend View Post
    Thank you for that.

    About that context menu I mentioned in the first post:

    it's supposed to give list of track title + album name.

    It seems that piCorePlayer, SB Touch, SB Radio and Material skin use the jive menu:

    Code:
    if ( $tags->{menuMode} ) {
    	my $jive = {};
    	my $actions = {
    		go => {
    			player => 0,
    			cmd => ['ratingslight', 'moreratedtracksmenu', $trackID, $artistID],
    		},
    	};
    	$jive->{actions} = $actions;
    	return {
    		type => 'redirect',
    		name => $text,
    		jive => $jive,
    	};
    The function/dispatch called returns an item_loop with this value for each track as $text:

    Code:
    $tracktitle." ( ".$ratingtext." )\nAlbum: ".$albumname
    #1
    Now I have a style/font size problem:

    Material somehow does a perfect job and for each track puts the second line "Album: ".$albumname in a smaller font (even in a slightly different color) so that everything fits into one line. And it looks good.

    piCorePlayer, Touch and Radio also display both "lines" but both in the same font size. It looks very crowded, just not good at all.
    I could, of course, return only one line for the jive menu without the "\n" and probably lose the album information so the line would get too long.

    But before I do so (and I'd really like to keep the album info) I thought I'd ask:

    is there a way to assign a different font size to the second line?

    I mean, there is only 1 "name" key, so I can't split the line in two and send 2 values. Even then I wouldn't know how to assign a different font size to the second line/value.
    Reference to old protocol documentation (not sure it’s updated with latest changes): https://htmlpreview.github.io/?https.../jiveMLON.html

    If I remember correctly it’s controlled with the “window” attribute and its parameters “titleStyle”, “menuStyle” and “windowStyle”. You can see how it’s set in TrackStat menus here: https://github.com/erland/lms-tracks...lugin.pm#L3530
    Note that I more or less implemented this by experimenting so I can’t guarantee that TrackStat sets it correctly. Best way to see the correct way is probably to enable cometd debug logging and navigate into a menu from standard LMS code that looks correct and take a look at the JSON messages in the log.

    Note that “window” is an attribute on same level as “item_loop” so all items will look the same, I don’t think you can mix different item styles in the same list.
    Erland Isaksson (My homepage)
    Developer of many plugins/applets
    Starting with LMS 8.0 I no longer support my plugins/applets (see here for more information )

  8. #8
    Senior Member
    Join Date
    Jul 2010
    Posts
    251
    Quote Originally Posted by erland View Post
    Reference to old protocol documentation (not sure it’s updated with latest changes): https://htmlpreview.github.io/?https.../jiveMLON.html

    If I remember correctly it’s controlled with the “window” attribute and its parameters “titleStyle”, “menuStyle” and “windowStyle”. You can see how it’s set in TrackStat menus here: https://github.com/erland/lms-tracks...lugin.pm#L3530
    Note that I more or less implemented this by experimenting so I can’t guarantee that TrackStat sets it correctly. Best way to see the correct way is probably to enable cometd debug logging and navigate into a menu from standard LMS code that looks correct and take a look at the JSON messages in the log.

    Note that “window” is an attribute on same level as “item_loop” so all items will look the same, I don’t think you can mix different item styles in the same list.
    Thank you, that was very helpful. I'd been looking for a documentation like that one. I did the best I could and I can live with that :-) So I've updated the plugin.

    BTW you don't happen to remember if there's already some plugin that uses a tried and tested url path substitution function?
    I would really like to include that as part of the export to playlist files function. That way I could import rated tracks with even less manual effort into other apps.
    Before I dive into url paths, regex and URI I thought I'd ask.

  9. #9
    Senior Member erland's Avatar
    Join Date
    Dec 2005
    Location
    Sweden
    Posts
    11,290
    Quote Originally Posted by afriend View Post
    BTW you don't happen to remember if there's already some plugin that uses a tried and tested url path substitution function?
    I would really like to include that as part of the export to playlist files function. That way I could import rated tracks with even less manual effort into other apps.
    Before I dive into url paths, regex and URI I thought I'd ask.
    Not exactly what you want but it might be possible to get inspired by:
    - TrackStat iTunes export functionality (getiTunesUrl function): https://github.com/erland/lms-tracks...Export.pm#L215
    - Portable Sync plugin which was never released (getPortablePath function): https://github.com/erland/lms-portab...c/Scan.pm#L135

    You might want to handle:
    - Replacement of beginning of url
    - Replacement of path separator / or \
    - Replacement of extension in case you want to support export to a mobile device using a mp3/aac version of your lossless LMS library

    I’m not saying that any of the above samples is the best way to do it, I wrote those a long time ago when I was pretty inexperienced with Perl. The Portable Sync version was written before LMS had support for multiple music folders, so that needs to be fixed if you get inspired by that sample.
    Erland Isaksson (My homepage)
    Developer of many plugins/applets
    Starting with LMS 8.0 I no longer support my plugins/applets (see here for more information )

  10. #10
    Senior Member
    Join Date
    Jul 2010
    Posts
    251
    Quote Originally Posted by erland View Post
    You might want to handle:
    - Replacement of beginning of url
    - Replacement of path separator / or \
    I don't have access to a Windows PC. I've read on Wikipedia that Windows also uses the file:/// scheme. Would the new url quoted below be a valid file url on Windows? With all the slashes, (un)escaping and whatnot... I'm not sure. BTW it's supposed to be a macOS -> Windows example.

    old url = file:///Users/myuser/Music/media/04%20I%20Just%20Don%27t%20Know.m4a
    lmsbasepath = /Users/myuser/Music/media
    substitutebasepath = C:\Media Documents\Music
    new url = file://C%3A%2FMedia%20Documents%2FMusic/04%20I%20Just%20Don%27t%20Know.m4a
    unescaped new url = file://C:/Media Documents/Music/04 I Just Don't Know.m4a
    Last edited by afriend; 2021-02-27 at 08:45.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •