Last active
August 27, 2017 18:26
-
-
Save meeuw/50dbed933b6e89ebe16daca6044e87a4 to your computer and use it in GitHub Desktop.
lua script to write all properties to /dev/shm/mpv-status every second
This file contains hidden or 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
function writeproperty(name) | |
value = mp.get_property(name) | |
if value ~= nil then | |
file:write(string.gsub(value, "\n", "\\n")) | |
end | |
file:write("\n") | |
end | |
timer = mp.add_periodic_timer(1, function() | |
os.remove("/dev/shm/mpv-status") | |
file = io.open(string.format("/dev/shm/mpv-status", math.random(0, 100)), "w") | |
properties = mp.get_property('property-list') | |
file:write("volume,speed,media-title\n") | |
writeproperty("volume") | |
writeproperty("speed") | |
writeproperty("media-title") | |
file:close() | |
end) |
This file contains hidden or 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/env python3 | |
import json | |
import binascii | |
result = {} | |
with open('/dev/shm/mpv-status', 'rb') as f: | |
properties = None | |
for i, line in enumerate(f): | |
line = line[:-1] | |
try: | |
line = line.decode('utf8') | |
except UnicodeDecodeError: | |
line = binascii.hexlify(line).decode('utf8') | |
if properties is None: | |
properties = [None] + line.split(',') | |
continue | |
result[properties[i]] = line | |
print(json.dumps(result, indent=4)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment