Flirc DBUS MPRIS Daemon
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Control MPRIS media players with your Flirc | |
[Service] | |
ExecStart=/usr/bin/flirc_mpris.py | |
Restart=always | |
[Install] | |
WantedBy=default.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import evdev | |
import mpris2 | |
from evdev import ecodes | |
dev = evdev.InputDevice('/dev/input/by-id/usb-flirc.tv_flirc-event-kbd') | |
mappings = { | |
"KEY_NEXTSONG": "Next", | |
"KEY_PREVIOUSSONG": "Previous", | |
"KEY_PLAYPAUSE": "PlayPause", | |
"KEY_PAUSE": "Pause", | |
"KEY_PLAY": "Play", | |
"KEY_STOP": "Stop", | |
} | |
def handle(event: evdev.KeyEvent): | |
if event.keystate != evdev.KeyEvent.key_down: | |
return | |
try: | |
uri = mpris2.get_players_uri() | |
except StopIteration: | |
print("No media player found") | |
return | |
method_name = mappings.get(event.keycode) | |
if not method_name: | |
return | |
player = mpris2.Player(dbus_interface_info={'dbus_uri': next(mpris2.get_players_uri())}) | |
print("player.{}()".format(method_name)) | |
method = getattr(player, method_name) | |
method() | |
for event in dev.read_loop(): | |
if event.type != ecodes.EV_KEY: | |
continue | |
key_event = evdev.categorize(event) | |
print(key_event) | |
handle(key_event) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
evdev==1.2.0 | |
mpris2==1.0.2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment