Problem:
A while ago I conducted a wide-scale login change for most of my Internet services. Some of them, however, were reluctant to allow effortless username change. This applies in particular to Last.fm.
According to the Last.fm’s FAQ it’s not possible to change one’s initial username. Neither is it possible to move the collected stats/scrobbles to a new account.
Solution:
Well, till (and if) Last.fm introduces this kind of functionality, there’s no real solution to this problem. But there’s some (a bit ugly) workaround for this.
Thanks to Ionut Bizau’s lastfm_backup.py script it’s possible to fetch all the scrobbles to a text file. For the time being, I see the original script is no longer available on GitHub, so here’s the source:
#!/usr/bin/env python
# Copyright (c) 2009 Ionut Bizau
# All rights reserved.
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# 3. The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
__doc__ = """Usage: %s username""" % __file__
import gzip
import sys
from StringIO import StringIO
import time
import urllib2
from lxml.html import parse
try:
from urlgrabber.keepalive import HTTPHandler
opener = urllib2.build_opener(HTTPHandler())
except ImportError:
sys.stderr.write("WARNING: urlgrabber not available. Will not use keepalive.\n")
opener = urllib2.build_opener()
def parse_xml(url):
request = urllib2.Request(url, None, {"Accept-encoding": "gzip"})
response = gzip.GzipFile(fileobj=StringIO(opener.open(request).read()))
return parse(response).getroot()
def scrape_page(url):
doc = parse_xml(url)
for row in reversed(doc.cssselect("table.tracklist tr")):
try:
artist, title = [a.text.strip() for a in row.cssselect("td.subjectCell a")]
timestamp = row.cssselect("td.dateCell abbr")[0].attrib['title']
yield artist, title, timestamp
except Exception:
pass
def scrape_user(url):
doc = parse_xml(url)
try:
page_count = int(doc.cssselect("a.lastpage")[0].text)
except:
page_count = 1
for i in reversed(range(1, page_count + 1)):
for artist, title, timestamp in scrape_page("%s?page=%s" % (url, i)):
yield artist, title, timestamp
def main(username):
url = "http://last.fm/user/%s/tracks" % username
for artist, title, timestamp in scrape_user(url):
sys.stdout.write((u"%s\t%s\t%s\n" % (artist, title, timestamp)).encode("utf-8"))
if __name__ == '__main__':
if len(sys.argv) == 2:
username = sys.argv[1]
main(username)
else:
print __doc__
Before you use it, make sure your recent tracks are set to public (for the transition at least). Theoretically another script by the same author (lastfm2itunes.py) should work better – it’s possible to bulk upload your listening history from iTunes/Winamp on the first account login in Last.fm (via the default client). But of course this went wrong somehow, and I had to rescrobble my tracks “manually” instead of bulk uploading them (you get only one try with this).
There’s a plethora of tools to use the Last.fm API to submit your listening logs – check Rockbox for this. I used dap-scrob as the fastest solution, but due to some unknown problem some of my scrobbles got submitted more than once (though this concerned only a minuscule fraction of tracks).
One problem you can encounter on the way is the need to sanitize the log to conform to .scrobbler-timeless.log format. The general .scrobbler.log info can be handy.
There are two major drawbacks to this approach. First, transferring all other settings (loved tracks, groups etc.) has to be done manually. Second – this method disrupts the listening statistics (thousands scrobbles in a few days time – this gives really weird per day average). As to the former issue – there’s some recent development (Essential Profile Transfer) that should alleviate this particular problem.
This way it’s possible to imitate a Last.fm’s username change. For sure this would be much more clean and easy if Last.fm provided such an option by itself, but it probably involves too much work in the core to be adopted in the near future. So, for the time being, it’s the only way I know to “change” the login without beginning completely from scratch.






Hi, I found the link to the scripts http://github.com/ibz/lastfmtools but I have no idea how to use this stuff, not being a programmer (or knowing anything at all about code). Could you elaborate a bit more on how I run the code (parameters, etc) and what you mean by the formatting? Thanks!
Nice, thanks.
I used lastfm_backup.py initially.
Put the contents of the script into a file, let’s say ~/lastfm_backup.py.
Give executable permissions:
To run it issue:
You will need python and python-lxml bindings installed (sudo apt-get install python python-lxml).
Assuming your recent tracks are not set to private, you should get a list of your scrobbles in the ~/lastfm_backup.log file.
The output of this command is something like this:
To submit it using some sort of online scrobbler you need to convert it to the .scrobbler.log format which is:
Header part (first three lines):
and then one scrobble per line with fields separated by tabs:
according to the standard (http://www.audioscrobbler.net/wiki/Portable_Player_Logging).
So using some sort of text editor (or spreadsheet if more convenient) you have to create a file structure resembling this one:
(The formatting gets messed up here in the comment – there are in fact double tabs for empty fields (check the source of this page to get it in raw format)).
Then rescrobble it using the aforementioned tools.
I see in the repository you’ve mentioned there’s a lastfm_bootstrap.py script, which should theoretically do all this in a more elegant manner, but I didn’t try it. From what I remember bootstrapping was not meant to be supported for 3rd-party tools, so I think either way this would be some undocumented way of using the API, and will probably cease to function in the future.
If you’re still stuck at some point, drop me a line here – maybe we’ll be able to sort it out.
Hey, once again thanks for the help. Do you seriously have to enter everything manually, or is there a method for automation? Because… uh… I have 15′000+ lines to go through O.o
Try importing the backup file to a spreadsheet application (Excel/Calc). This way it’s easy to operate on all rows at the same time (you only need genuine artist and track name data from the backup). Then export to a text file and, if needed, try search & replace (field separators).
Awesome! I got it to work (I’m guessing dap-scrob takes a couple hours to get through everything?). When I saved the file after search-replacing the quotes in gedit, it crashed the program – thank god I have VIM installed too. I owe you big time, thank you so much for all your help – I would never have been able to migrate everything without your help, and now I have one unified username across all the sites I visit.
Thanks again!
Hey, nice to hear you got it sorted out.
dap-scrob can be a bit troublesome with that much data, but IMHO it’s easiest to use – if it doesn’t work, you can try resetting the stats and using some other scrobbler. I had a couple of dozen tracks which were probably submitted more than once (the overall stats did not fully match), but I thought it was still better than nothing.
Turned out it was that the collection of all my music was longer than the account was old – so I set it to scrobble at 30s intervals. I may have lost about a sixth of my scrobbles, but it was still worth it. I wish last.fm would give an official way to grab your scrobbles from another account.
dziendobry~~
ciesze sie, ze po dniu babrania sie w tagach na last fm i internecie tagi skonczylam i znalazlam juz nawet sposob jak zrobic to co bym chciala…
sprobowalam zrobic tak jak napisales, tzn wpisac te komendy w cmd.exe (czy nie w to?) ale nie dziala, winda sie stawia. jak odpalic ten plik? forgive my ignorance, html opanowalam (jakos) ale tu i na lekko zaawansowanej obsludze kompa sie konczy >.> co gdzie trzeba wpisac zeby ten plik odpalic?
ah. dotarlo do mnie tez, ze ty pythonem trzeba. tylko ze ja mam siodma winde i zadna z dwoch promowanych na oficjalnej stronie pythona sie nie chce nawet zaczac instalowac, grozba ani prosba, py scripter sie zainstalowal, ale nie wczytuje zadnych bibliotek i nie dziala.
najwyzej zawola sie najblizszego kolege zaznajomionego z linuksem.. ale serio, na windzie 7 to nie zadziala?
molgbys mi chociaz podeslac ta wygenerowana liste piosenek? (mejla masz, username na last to bouzenjishitsu) musze sie nia najpierw pobawic zanim wrzuce zpowrotem, zamierzam popoprawiac literowki tu i owdzie..
rozumiem, ze zeby wrzucic to zpowrotem i tak potrzebuje rozgryzc jak zainstalowac pythona, zeby otworzyc ten drugi plik py co to laduje zpowrotem? czy przez itunes po prostu mozna?
ok ok udalo mi sie zainstalowac pythona, ale caly czas mowi mi ze nie umiem pisac =.= line syntax error, przepisuje dokladnie to co napisales (min, probowalam tez wpisywac adres pliku).
co jest nie tak, jak to zrobic?
Podsyłam Ci backup scrobbli na maila. Można to przerobić do formatu .scrobbler.log i wgrać przez jakiś scrobbler – jest tego trochę do wyboru.
Teoretycznie lepszy byłby skrypt lastfm_bootstrap.py – czyli pierwszy import jak za pomocą iTunes/odtwarzacza MP3. Ale wymaga poradzenia sobie z pythonem. Poza tym nie testowałem tej metody i nie wiem, czy w ogóle działa.
super, dzieki :D to tym drugim sposobem bede sie bawic pozniej, jak uzyskam uwage kolegow bieglych w te klocki :)
OK, powodzenia.
As a side note here. For Windows users it seems that Last.fm Scrobble Mapper should facilitate the transfer. Grabs all scrobles and exports them into Windows Media Player or iTunes format. Seems promising (at least from description). More information about Last.fm Scrobble Mapper.
And by the way – it seems the problem is more common than I initially thought:
Last.fm “Change the username” group ;-)
Topic at getsatisfaction.com
Last.fm should probably do something about it.