Skip to content

Instantly share code, notes, and snippets.

@underr
Last active August 29, 2015 14:22
Show Gist options
  • Save underr/22e8b74d1f341bcc1412 to your computer and use it in GitHub Desktop.
Save underr/22e8b74d1f341bcc1412 to your computer and use it in GitHub Desktop.
Use MPD vs last.fm to get albums you didn't listened to yet
import json, codecs
import rethinkdb as r
from mpd import MPDClient
from collections import OrderedDict
client = MPDClient(use_unicode=True)
client.connect("localhost", 6600)
pre = []
mpd_albums = []
last_albums = []
### GET INFO FROM LAST.FM DUMP
conn = r.connect(host="localhost", port=28015, db="lastfm").repl()
c = r.table("scrobbles").run(conn)
s = list(c)
j = json.dumps(s)
# to prevent dataloss, but you could just use the "s" object
with codecs.open("./ddata.json", "w", "utf-8-sig") as ff:
ff.write(j)
### GET LAST.FM ALBUMS
with open("ddata.json") as data:
s = json.load(data)
for a in s:
aa = a.get("album")
pre.append(aa)
for a in pre:
if isinstance(a, dict):
last_albums.append(a.get("name"))
### GET MPD ALBUMS
f = client.listallinfo()
for a in f:
if isinstance(a, dict):
mpd_albums.append(a.get("album"))
mpd_r_albums = list(OrderedDict.fromkeys(mpd_albums))
print(mpd_r_albums)
### MERGE EVERYTHING
lets_do_this = mpd_r_albums + last_albums
done = list(OrderedDict.fromkeys(lets_do_this))
for a in done:
print(a) # use a pipe or something after this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment