Moode Forum
[SOLVED] Random album script - Printable Version

+- Moode Forum (https://moodeaudio.org/forum)
+-- Forum: moOde audio player (https://moodeaudio.org/forum/forumdisplay.php?fid=3)
+--- Forum: Support (https://moodeaudio.org/forum/forumdisplay.php?fid=7)
+--- Thread: [SOLVED] Random album script (/showthread.php?tid=1592)



Random album script - Pieter - 08-10-2019

Hi all

I'm trying to beef up my Denon RC-1173 remote with moOde-tied functionality and would like to set a button queuing up a random album, behaving exactly like the random album icon on the playback panel in the web interface. 
As far as I can tell this is the javascript responsible for the functionality but I don't know how to call it as a script that irexec can run. Could anyone shed some light on this?

/www/js/scripts-library.js lines 654-694
Code:
// Random album instant play (button on Playback panel)

$('.ralbum').click(function(e) {

    if ($('.tab-content').hasClass('fancy')) {

        $('.ralbum svg').attr('class', 'spin');

        setTimeout(function() {

            $('.ralbum svg').attr('class', '');

        }, 1500);

    }

    var array = new Uint16Array(1);

    window.crypto.getRandomValues(array);

    pos = Math.floor((array[0] / 65535) * filteredAlbums.length);




    UI.libPos[0] = pos;

    UI.libPos[1] = filteredAlbumCovers.map(function(e) {return e.album;}).indexOf(filteredAlbums[pos].album);

    var albumobj = filteredAlbums[pos];




    storeLibPos(UI.libPos);

    LIB.albumClicked = true; // For renderSongs()




   // Song list for regular album

    clickedLibItem(e, keyAlbum(albumobj), LIB.filters.albums, renderSongs);




    var files = [];

    for (var i in filteredSongs) {

        files.push(filteredSongs[i].file);

    }




   if (SESSION.json['library_instant_play'] == 'Add/Play') {

       mpdDbCmd('playall', files);

   }

   // Clear/play using add first followed by delete. This approach makes for a smoother visual transition.

   else {

       var endpos = $(".playlist li").length

       mpdDbCmd('addall', files);

       setTimeout(function() {

           endpos == 1 ? cmd = 'delplitem&range=0' : cmd = 'delplitem&range=0:' + endpos;

           var result = sendMoodeCmd('GET', cmd, '', true);

           sendMpdCmd('play 0');

       }, 500);

   }

});



RE: Random album script - swizzle - 08-10-2019

Looking a bit at how irexec works with moode (sends commands to mpc) you probably need additional software like this:

http://lirc.org/html/irxevent.html

It looks like can simulate button clicks by using screen coordinates but it’d be better if keyboard shortcuts were added.


RE: Random album script - Tim Curtis - 08-10-2019

We also have a mechanism (engine-cmd.php) to send commands from the server to the client so in theory it should be possible to use it to provide an interface to the non-MPD features of the UI. There are a lot of moving parts though so not a trivial dev project.

It would be something like below

- LIRC maps button X to command: /var/www/command/new_script.php 'random_album'
- When X is pressed new_script.php executes function sendEngCmd($cmd);
- JS code running in Browser receives 'random_album' command and performs $('.ralbum).click()

Something like that.


RE: Random album script - Pieter - 08-30-2019

Update:

I found a solution much simpler than emulating button presses in X: https://github.com/cbumae/mpdrandom

Calling mpdrandom will select an album at random from the current playlist, and by calling the option -l the script will select, queue and play an album from the entire library.

The script offers a daemon function as well, queuing an entire album when the end of the playlist is reached. I'm an album guy so will replace the ashuffle implementation with this.


RE: Random album script - Tim Curtis - 08-30-2019

Added to TODO list, thanks.

My thought is to change the Auto-shuffle option in Audio Config from ON/OFF to a dropdown that contains

Off
Tracks
Albums