Skip to content

Instantly share code, notes, and snippets.

@aiguofer
Last active November 6, 2017 18:02
Show Gist options
  • Save aiguofer/bcc3fbc899d162ff3e69a13db18e1ebe to your computer and use it in GitHub Desktop.
Save aiguofer/bcc3fbc899d162ff3e69a13db18e1ebe to your computer and use it in GitHub Desktop.
Script to like a song in GPMDP (Google Play Music Desktop Player)

Custom Global GPMDP Shortcuts

GPMDP is an awesome application to use Google Play on the desktop. The only problem with it is that the built in keyshortcuts are very limited by design. They only allow shortcuts with the Control key, but if you use Emacs this is very limiting.

Most media control keys can be configured using the built in media keys for your DE. The 2 shortcuts that I was missing are to like a song, and to raise the player (I generally have it closed to tray). After some digging around dbus and sockets, I managed to write a copule of simple python scripts to accomplish this:

song_liker.py:

#!/usr/bin/env python

import websocket
import json

ws = websocket.WebSocket()
ws.connect('ws://localhost:5672')
ws.timeout = 1

connect = {
    "namespace": "connect",
    "method": "connect",
    "arguments": ["Song Liker", "92a35cb5-a687-401e-a7a8-c85becbc8168"]
}

ws.send(json.dumps(connect))

thumbs_up = {
    "namespace": "rating",
    "method": "setRating",
    "arguments": [5]
}

ws.send(json.dumps(thumbs_up))

try:
    for i in ws:
        pass
except:
    pass

raise_player.py

#!/usr/bin/env python

import dbus
try:
    player = dbus.SessionBus()\
                 .get_object(
                     'org.mpris.MediaPlayer2.google-play-music-desktop-player',
                     '/org/mpris/MediaPlayer2'
                 )
    player.Raise(dbus_interface='org.mpris.MediaPlayer2', timeout=0)
except:
    pass

Now you should be able to configure any shortcuts you want for those scripts using your DE

ps: If you want a 'dislike' song script, change the args to [0] in the song_liker.py script

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment