Skip to content

Instantly share code, notes, and snippets.

@yousefamar
Last active December 8, 2015 05:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yousefamar/63f55ecb26a897f85085 to your computer and use it in GitHub Desktop.
Save yousefamar/63f55ecb26a897f85085 to your computer and use it in GitHub Desktop.
scrobble_file = '/home/amar/.local/share/mpv/scrobble.txt' -- Make sure this dir exists
paused = false
playing = ''
function update_file()
local file = assert(io.open(scrobble_file, 'w'))
file:write(paused and ' ' or ' ', playing)
file:close()
end
function clear_file()
local file = assert(io.open(scrobble_file, 'w'))
file:write('')
file:close()
end
function on_loaded(event)
local data = mp.get_property_native('metadata')
local artist = data and data['artist']
playing = ''
if artist and string.len(artist) > 0 then
playing = artist .. ' - '
end
playing = playing .. mp.get_property('media-title')
update_file()
end
function on_end(event)
clear_file()
end
function on_pause_change(name, value)
paused = value
update_file()
end
mp.register_event('file-loaded', on_loaded)
mp.register_event('end-file', on_end)
mp.observe_property('pause', 'bool', on_pause_change)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment