Last active
August 29, 2015 14:22
-
-
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
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
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