Generating player menus

The LMSMenuHandler class allows you to generate squeezeplayer menus on the fly. This will allow you to create your own interfaces in your applications.

Note

This code is a work in progress and may therefore lack some of the functionality that you may encounter on more ‘professional’ applications.

If there is some functionality that is missing (or the code otherwise works in unexpected ways) then please notify me in the GitHub issues tracker.

Understanding the menu system

Menus are provided by the server as JSON objects. At their most basic, they provide text, icon path and the relevant command to be executed.

This library currently categorises each menu item into one of four types:

  • NextMenuItem: a menu item which just provides an additional submenu;
  • PlaylistMenuItem: a menu item which can be played/added to playlist or can provide a subsequent menu showing the tracks in the playlist;
  • AudioMenuItem: a menu item which can be played/added to playlist; and
  • SearchMenuItem: a menu item which requires user input before providing results.

The use of these different menu types is set out further below.

Creating a menu handler

The menu handler is currently included as a separate class. As the menus are specific to each player, the menu handler must have information about the player for which the menu is being requested.

>>>from LMSTools import LMSServer, LMSMenuHandler
>>>server = LMSServer("192.168.0.1")
>>>laptop = server.get_players()[1]
>>>handler = LMSMenuHandler(laptop)
>>>

If you wish to create a menu for a different player then you can change the current player as follows:

>>>livingroom = server.get_players()[0]
>>>handler.changePlayer(livingroom)
>>>

Generating a menu

To simplify the process of creating a menu, the menu handler has a a built infunction to retrieve the home menu: getHomeMenu .

>>>home = handler.getHomeMenu()
>>>home
[<LMSTools.menuitems.NextMenuItem at 0x7f049a0de490>,
 <LMSTools.menuitems.NextMenuItem at 0x7f049a0de450>,
 <LMSTools.menuitems.NextMenuItem at 0x7f049a0de9d0>,
 <LMSTools.menuitems.NextMenuItem at 0x7f049a0de510>,
 # etc.
 ]

Custom menus

As you can see from the above, the default home menu is very large and may be unwieldy for your own application.

As a result, you may want to define your own menu and have the menu handler process this menu.

CUSTOM_MENU = {
    "count": 5,
    "item_loop": [{
        "node": "myMusic",
        "weight": 11,
        "text": "Artists",
        "actions": {
            "go": {
                "cmd": ["browselibrary", "items"],
                "params": {
                    "menu": 1,
                    "mode": "artists",
                    "role_id": "ALBUMARTIST,ARTIST,BAND,COMPOSER,CONDUCTOR,TRACKARTIST"
                }
            }
        },
        "icon": "html/images/artists.png"
    }, {
        "node": "myMusic",
        "text": "Albums",
        "actions": {
            "go": {
                "cmd": ["browselibrary", "items"],
                "params": {
                    "menu": 1,
                    "mode": "albums"
                }
            }
        },
        "id": "myMusicAlbums",
        "icon": "html/images/albums.png"
    }, {
        "node": "myMusic",
        "text": "Playlists",
        "icon": "html/images/playlists.png",
        "actions": {
            "go": {
                "cmd": ["browselibrary", "items"],
                "params": {
                    "menu": 1,
                    "mode": "playlists"
                }
            }
        }
    }, {
         "node": "myMusic",
         "text": "Search",
         "icon": "html/images/search.png",
         "actions": {
            "go": {
                "cmd": ["browselibrary", "items"],
                "params": {
                    "menu": 1,
                    "mode": "search"
                }
            }
        }
    }, {
        "node": "home",
        "window": {
            "titleStyle": "album",
            "icon-id": "plugins/MyApps/html/images/icon.png"
        },
        "text": "My Apps",
        "actions": {
            "go": {
                "player": 0,
                "cmd": ["myapps", "items"],
                "params": {
                    "menu": "myapps"
                }
            }
        }
    }]
    }

menu = LMSMenuHandler(player)
results = menu.getCustomMenu(CUSTOM_MENU)
for item in results:
    print item.text, item.cmd

should output the following

Artists ['browselibrary', 'items', 0, 1000, 'menu:1', 'mode:artists', 'role_id:ALBUMARTIST,ARTIST,BAND,COMPOSER,CONDUCTOR,TRACKARTIST']
Albums ['browselibrary', 'items', 0, 1000, 'menu:1', 'mode:albums']
Playlists ['browselibrary', 'items', 0, 1000, 'menu:1', 'mode:playlists']
Search ['browselibrary', 'items', 0, 1000, 'menu:1', 'mode:search']
My Apps ['myapps', 'items', 0, 1000, 'menu:myapps']