Randomise Playlist

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Randomise Playlist

Re: Randomise Playlist

by Peke » Mon Nov 29, 2021 6:29 pm

Erwin Hanzl wrote: Mon Nov 29, 2021 12:14 pm Hello Drakinite, a suggestion:
I think "Randomise Playlist" does not (or not only) belong in the "Info-Panel",
but with a RIGHT CLICK on the playlist in the archive tree.
This means that this command is ALWAYS available and therefore the more convenient method.
Thanks, Erwin
Image
Main reason for not adding it on right click is accidental unreverted randomize of playlists. If you check your picture below yellow pointer you have Play shuffle option with sub-options. I do not mind adding it, but I personally think it is safer as is now.

Re: Randomise Playlist

by Erwin Hanzl » Mon Nov 29, 2021 1:51 pm

That's it. Thanks

Would you be so kind as to look at and judge another suggestion?
viewtopic.php?f=27&t=100631

Re: Randomise Playlist

by drakinite » Mon Nov 29, 2021 1:36 pm

Good idea, and wasn't very complex to add. New version of the addon is up.

Re: Randomise Playlist

by Erwin Hanzl » Mon Nov 29, 2021 12:14 pm

Hallo Drakinite, eine Anregung:
ich denke, "Randomise Playlist" gehört nicht (oder nicht nur) in das "Info-Panel",
sondern mit RECHTSKLICK auf die Playliste im Archiv-Baum.
Dadurch ist dieser Befehl IMMER erreichbar und deshalb die bequemere Methode.
Danke, Erwin

Hello Drakinite, a suggestion:
I think "Randomise Playlist" does not (or not only) belong in the "Info-Panel",
but with a RIGHT CLICK on the playlist in the archive tree.
This means that this command is ALWAYS available and therefore the more convenient method.
Thanks, Erwin

Image

Re: Randomise Playlist

by drakinite » Tue Nov 16, 2021 10:44 am

That's true! But scripts and addons can make it a lot simpler to do :)

Image

Re: Randomise Playlist

by Poobslag » Tue Nov 16, 2021 9:44 am

As an alternative way to randomize a playlist without a script:

1. Right-click your playlist, and select "Play Shuffled -> Play Now". (The playlist will play in a random order.)
2. Delete the contents of your playlist. (The playlist is now empty.)
3. In the "Playing" panel, press "CTRL + A" and "CTRL + C" to copy all playing items.
4. Right-click your playlist and select "Paste". (The playlist is now in random order.)

Re: Randomise Playlist

by drakinite » Mon Oct 11, 2021 10:58 pm

I've now put the script up on the site as a sample addon here: https://www.mediamonkey.com/addons/brow ... laylist-1/ :slight_smile:

Randomize stattic playlist

by shani » Sat Sep 18, 2021 6:58 am

In version 4 there was a script that randomize a static playlist. is There something familiar in version 5?

Re: Randomise Playlist

by telecore » Fri Jul 09, 2021 9:49 am

Would someone be able to show me how to expand upon this code a bit (?): I am trying to re-write a MM4 VBS script that I developed which does the following:

(1) create a new non-auto playlist with the same name (+ "*" at the end), in the same location as the specified playlist (either auto or non-auto) - (I have this part basically working)
(2) iterate through the tracklist of the specified playlist and copy tracks determined to be unique (non-duplicate) per a programmatic criteria to the new playlist (cannot seem to do this)
(3) Note: the criteria for uniqueness is basically that the artist and title strings are different from all other tracks in the playlist, however, this will be expanded upon programmatically for some string cleanup prior to comparison and a selection criteria would eventually be added to select the highest bitrate version of any duplicated tracks for inclusion in the new playlist

I use this script all the time on auto-playlists that contain a lot of duplicates in MM4 but I am having difficulties getting some basic things to work in this new environment

Re: Randomise Playlist

by plain » Fri Jun 18, 2021 2:40 pm

Oh Wow! This is great! Thanks drakinite! I don't know if I have the skill to do this but knowing it is possible and how to do it is going to be a really nice encouragement to try! Thanks!

Re: Randomise Playlist

by drakinite » Tue Jun 15, 2021 11:25 pm

You're welcome - that's great to hear :)

Re: Randomise Playlist

by mmain » Fri Jun 11, 2021 2:31 am

Thanks for your support and guidance, works a treat :D

Re: Randomise Playlist

by drakinite » Fri Jun 04, 2021 5:10 pm

Yep! You can find a step by step guide on how to create an addon/script here: https://www.mediamonkey.com/wiki/Gettin ... d_(Addons)

One thing you'd have to decide is where exactly you want the "randomise playlist" action to be accessible.
If you want it to be accessible in that little context menu, here are the steps I'd take to figure out how to make the script into an addon:

1) To find out exactly where in the code is responsible for that context menu, I can do a text search (in the installation directory, through all the .js files) for one of the items: in this case, "Remove duplicates".
2) I then find that the text "Remove duplicates" is defined in actions.playlistRemoveDuplicates. Good! Now do a text search for playlistRemoveDuplicates, to see where that action is called.
3) Bingo! There's one inside playlistHeader.js, where it creates this.btnMenu.controlClass.menuArray. That's what we're looking for!

So what we need to do now is:
- Create a new "action", similar to actions.playlistRemoveDuplicates, which randomizes the playlist
- Add that "action" to the menu defined in playlistHeader.js.

4) So to create a new action, let's create a new file in our project folder (where you placed info.json; take a look at the Hello World example in the getting started guide) named actions_add.js. We then define, let's call it , "playlistRandomise".

To start with, let's define actions.playlistRandomise:

Code: Select all

actions.playlistRandomise = {  }
In fact, actions.playlistRemoveDuplicates is a very good baseline, and we can keep most of its properties. We just need to change its title, and preferably its icon. Let's go with shuffle. Also, the contents of its execute function is pretty close to what we need already. It gets the associated playlist object, and even loads its tracklist. So let's put Ludek's code inside the whenLoaded callback, careful to rename the variables so that we don't encounter an error:

Code: Select all

actions.playlistRandomise = {
    title: function () {
        return 'Randomise Playlist'
    },
    icon: 'shuffle',
    visible: function () {
        if (!window.uitools.getCanEdit())
            return false;
        else {
            var pl = resolveToValue(this.boundObject);
            return (pl.parent != undefined && !pl.isAutoPlaylist); // to exclude root playlists node and auto-playlists
        }
    },
    execute: function () {
        var playlist = resolveToValue(this.boundObject);
        var tracks = playlist.getTracklist();
        tracks.whenLoaded().then(() => {
            tracks.randomize();
            playlist.reorderAsync(tracks);
        });
    }
};
5) Now, we need to add it to the playlist header menu that we talked about before. To do this, we'll use the Override method as discussed here: https://www.mediamonkey.com/wiki/Import ... )#Override So here, we will create playlistHeader_add.js (within a "controls" subfolder).

To start with, this is the format you need to do to override the PlaylistHeader's _initButtons method, inside controls/playlistHeader_add.js:

Code: Select all

PlaylistHeader.prototype.override({
    _initButtons: function ($super) {
        $super();
        // now we do our own stuff
    }
});
If we want our item to be ordered directly after "Remove duplicates", we'll want to order it correctly. "Remove Duplicates" has a grouporder of 10 and an order of 20, and "Pin it" has a grouporder of 10 and an order of 30. So we'll want our order to be between those two; so we'll do 25.

Now, as we were using playlistRemoveDuplicates as a baseline, you can see that it uses a function called bindAction. This is so that the actions can figure out which playlist it's supposed to be editing (and that's where the "resolveToValue(this.boundObject)" comes in to play). So let's do the same for our new menu item:

Code: Select all

PlaylistHeader.prototype.override({
    _initButtons: function ($super) {
        $super();
        var _this = this;
        this.btnMenu.controlClass.menuArray.push({
            action: bindAction(window.actions.playlistRandomise, () => {
                return _this._playlist;
            }),
            order: 25,
            grouporder: 10
        });
    }
});
6) Now, pack your MMIP, install it, and test it! https://lambda.sx/IdwS.mp4

Re: Randomise Playlist

by mmain » Mon May 31, 2021 10:53 pm

Is there some guidance on how to add this as a script?

Re: Randomise Playlist

by Ludek » Mon May 17, 2021 4:48 am

As for using 'Playlist is' condition in an auto-playlist and using [x] Limit ... selected by [Random (refresh-all)]
Yes, this can be used as workaround without a need for scripting.

But I guess that user "mmmain" is asking for a script that randomizes static playlist directly (without a need using auto-playlists) ?

Then I think that code like this should work:

Code: Select all

var tracks = playlist.getTracklist();
tracks.whenLoaded().then(()=> {
  tracks.randomize();
  playlist.reorderAsync(tracks);
});
The true is that neither the randomize and reorderAsync are documented atm. I'll update the docs.

Top