A feature request recently implemented in mpdscribble allows plays from mpd to be logged to file. If you already use Last.fm but like the idea of being in control of your private data, this might be of interest.
First, why would you want to do this? I would consider music listening data private data. It is a representation of you as a person, disclosing your tastes, interests and perhaps whether you pirate music.
Last.fm is a great web service, principally offering music recommendation that actually works. The trouble is, users (usually without knowing any better) are happy to give away ownership of their data to be used by services they have no control over. Worse still, the data is typically personally identifiable by collecting IP addresses, mapped to public profile data. All in all, it’s bad news for privacy and a haven for data mining.
Using mpdscribble, we can now log listening habits to a plain-text file, the most guaranteed and ubiquitous format there is. An obvious use-case is to provide statistical reports similar to how Last.fm does it, but also simply to track what we play and when we played it.
Being a Last.fm user since 4 Aug 2006 (with 6617 plays, an average of 4 tracks
per day… or so it tells me), they already have a large chunk of my listening
data. Wouldn’t it be nice to export the data into a format similar to that of
LastToLibre is a collection of Python scripts “… to create a dump of your Last.fm tracks and [import] them to Libre.fm”. Usefully, this creates an intermediary plain-text file in the format:
#!/usr/bin/python3 # lastexport2mpd.py # Copyright 2010 Tom Vincent <http://www.tlvince.com/contact/> import os import sys import time file = sys.path + "/exported_tracks.txt" with open(file) as tracks: with open(sys.path + "/mpd-formatted-tracks.txt", mode='w', encoding='utf-8') as outFile: for line in tracks: timestamp, track, artist, album, trackmbid, artistmbid, albummbid = line.strip("\n").split("\t") timestamp = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.localtime(int(timestamp))) outFile.write(timestamp + " " + artist + " - " + track + "\n")
We could have also used mpdcron’s stats module for this. It keeps a log of
your plays and stores them into an sqlite database, but also includes a tool –
homescrape — that pulls in your Last.fm data and subsequently updates each
matching track’s play count.
#!/usr/bin/python3 # eugene2plain.py # Copyright 2010 Tom Vincent <http://www.tlvince.com/contact/> import os import sqlite3 DB = os.path.expanduser("~") + "/.mpdcron/stats.db" OUT = os.path.expanduser("~") + "/plays.log" PREFIX = "1970-01-01T00:00:00Z" conn = sqlite3.connect(DB) c = conn.cursor() c.execute("SELECT artist,title,play_count FROM song WHERE play_count !='0'") songs = (c.fetchall()) with open(OUT, mode='w', encoding='utf-8') as outFile: for song in songs: for i in range(int(song)): outFile.write(PREFIX + " " + song + " - " + song + "\n") conn.close
$ homescrape [username]
$ python3 eugene2txt.py
$ cat ~/.cache/mpd/plays.log >> ~/plays.log
$ mv ~/plays.log ~/.cache/mpd/