Skip to content

Instantly share code, notes, and snippets.

@rweichler
Last active December 15, 2017 22:54
Show Gist options
  • Select an option

  • Save rweichler/1a8493d17f101f613219a4c0274809c4 to your computer and use it in GitHub Desktop.

Select an option

Save rweichler/1a8493d17f101f613219a4c0274809c4 to your computer and use it in GitHub Desktop.
mpv eqe.fm scrobbler

EQE scrobbler for mpv

Here's how to install this:

  • Put the scrobble.py script somewhere on your computer.
  • Put the mpv_eqe.lua script in ~/.config/mpv/scripts/.
  • Edit the variable at the top of mpv_eqe.lua to point to scrobble.py.

Then, create an account at eqe.fm if you haven't already.

Then visit this url, replacing USERNAME_HERE and PASSWORD_HERE as appropriate:

https://eqe.fm/api/login?username=USERNAME_HERE&password=PASSWORD_HERE

It will then return some json with a hexadecimal string, copy that and put it in the sesh variable near the top of scrobble.py.

I would also edit the platform variable to reflect your platform. For me I put "Mac", but for you you can put "Linux", "Ubuntu", "BSD", "TempleOS" or whatever.

Then you should be able to scrobble.

-- eqe.fm scrobbler for mpv
-- Usage:
-- put this file in ~/.config/mpv/scripts
-- put the accompanying python script somewhere on your computer
-- and change the variable PYTHON_SCRIPT below
local PYTHON_SCRIPT = '/EDIT/ME/scrobble.py'
local msg = require 'mp.msg'
require 'mp.options'
function mkmetatable()
local m = {}
for i = 0, mp.get_property("metadata/list/count") - 1 do
local p = "metadata/list/"..i.."/"
m[mp.get_property(p.."key")] = mp.get_property(p.."value")
end
return m
end
function scrobble()
mp.resume_all()
-- Parameter escaping function. Works with POSIX shells; idk if there's a better way to call stuff portably in Lua.
function esc(s)
return "'"..string.gsub(s, "'", "'\\''").."'"
end
msg.info(string.format('%s - %s', artist, title))
os.execute(PYTHON_SCRIPT..' '..esc(title)..' '..esc(artist)..' '..esc(album or 'NULL')..' '..start..' mpv > /dev/null')
end
function enqueue()
mp.resume_all()
if artist and title then
if tim then tim.kill(tim) end
tim = mp.add_timeout(30, scrobble)
end
end
function on_metadata()
local m = mkmetatable()
local icy = m["icy-title"]
if icy then
-- TODO better magic
artist, title = string.gmatch(icy, "(.+) %- (.+)")()
album = nil
length = nil
else
length = mp.get_property("duration")
start = os.time()
artist = m.artist or m.ARTIST
album = m.album or m.ALBUM
title = m.title or m.TITLE
end
enqueue()
end
mp.register_event("metadata-update", on_metadata)
mp.register_event("file-loaded", on_metadata)
#!/usr/bin/env python
import urllib
import urllib2
from sys import argv
from sys import exit
base = 'https://eqe.fm'
sesh = 'YOUR_SESH_HERE'
platform = 'Some flavor of Unix probably'
if len(argv) != 6:
print("Usage: " + argv[0] + " title artist album time app")
exit(1)
tup = (
('title', argv[1]),
('artist', argv[2]),
('album', argv[3]),
('date', argv[4]),
('app', argv[5]),
('sesh', sesh),
('platform', platform),
)
uri_args = urllib.urlencode(tup)
url = base + "/api/spin?" + uri_args
print(urllib2.urlopen(url).read())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment