Scrobbling support

102 views
Skip to first unread message

shadyabhi

unread,
Feb 25, 2010, 7:08:04 AM2/25/10
to pylast
Hi,

Please someone share a basic working code for scrobbling a
particular track using pylast. How do i scrobble the "track1" Track
object using Scrobbler class? Pls tell the code. I dont think the code
would be more than a few lines.

#Code starts here
import pylast
API_KEY="something here"
API_SECRET="something here"
username = "shadyabhi"
password_hash = pylast.md5("mypassword")
network = pylast.get_lastfm_network(api_key = API_KEY, api_secret =
API_SECRET, username = username, password_hash = password_hash)
track1 = network.get_track("Breaking Benjamin","Firefly")
#Code Ends here


Thanx

--
Abhijeet Rastogi
(shadyabhi)
http://www.google.com/profiles/abhijeet.1989

Amr Hassan

unread,
Feb 25, 2010, 7:55:37 AM2/25/10
to pyl...@googlegroups.com
to scrobble you need a Scrobbler object. use network.get_scrobbler()
and then use its methods for scrobbling or reporting the nowplaying
track.

-- Amr

> --
> You received this message because you are subscribed to the pylast mailing
> list.
> To post to this mailing list, send email to pyl...@googlegroups.com
> To unsubscribe from this group, send email to
> pylast+un...@googlegroups.com
> pylast is a python wrapper around last.fm's api. the project is hosted at
> http://code.google.com/p/pylast/ and the mailing list/group is at
> http://groups.google.com/group/pylast

NVSBL monster

unread,
Mar 16, 2010, 4:44:38 PM3/16/10
to pylast
I can't seem to Scrobble properly. I've got my Scrobbler object as you
said, but whenever I use it, I get a BadAuthenticationError. Am I
doing something wrong?

I'm trying to read from a file that has an artist, track and utc date
code on each line, and scrobble them

....

import pylast
API_KEY="something here"
API_SECRET="something here"
username = "shadyabhi"
password_hash = pylast.md5("mypassword")
network = pylast.get_lastfm_network(api_key = API_KEY, api_secret =
API_SECRET, username = username, password_hash = password_hash)
network = pylast.get_lastfm_network(api_key = API_KEY, api_secret =
API_SECRET, username = username, password_hash = password_hash)

scrobbler = network.get_scrobbler("tst", "1.0")

def main():
scrobbler = network.get_scrobbler("tst", "1.0")
fin = open(FILE)


for line in fin:
raw = line.strip()
trackinfo = raw.split("\t")
track = network.get_track(trackinfo[0], trackinfo[1])

artist = track.get_artist()
title = track.title
time_started = trackinfo[2]
source = 'SCROBBLE_SOURCE_UNKNOWN'
mode = 'SCROBBLE_MODE_PLAYED'
duration = track.get_duration()
album = track.get_album()
track_number = '1'
mbid = track.get_mbid()

scrobbler.scrobble(artist, title, time_started, source, mode,
duration, album, track_number, mbid)

if __name__ == "__main__":
main()

I'm trying to migrate my scrobbles from one account to a new one (sick
of my username, can't change it). If a tool like this already exists,
please tell me, but I'd still like to finish working on this script.

On Feb 25, 8:55 am, Amr Hassan <amr.has...@gmail.com> wrote:
> to scrobble you need a Scrobbler object. use network.get_scrobbler()
> and then use its methods for scrobbling or reporting the nowplaying
> track.
>
> -- Amr
>

> >http://code.google.com/p/pylast/and the mailing list/group is at
> >http://groups.google.com/group/pylast

NVSBL monster

unread,
Mar 16, 2010, 4:55:44 PM3/16/10
to pylast
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "migratefm.py", line 36, in main

scrobbler.scrobble(artist, title, time_started, source, mode,
duration, album, track_number, mbid)
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 3650,
in scrobble
params = {"s": self._get_session_id(), "a[0]": _string(artist),
"t[0]": _string(title),
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 3613,
in _get_session_id
self._do_handshake()
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 3602,
in _do_handshake
response = _ScrobblerRequest(server, params, self.network,
"GET").execute().split("\n")
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 3542,
in execute
self._check_response_for_errors(response)
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 3558,
in _check_response_for_errors
raise BadAuthenticationError()
pylast.BadAuthenticationError: Bad authentication token


I filled out an issue report, that's here: http://code.google.com/p/pylast/issues/detail?id=36

> > >http://code.google.com/p/pylast/andthe mailing list/group is at
> > >http://groups.google.com/group/pylast

Dan Davison

unread,
Mar 28, 2010, 10:59:30 AM3/28/10
to pyl...@googlegroups.com, NVSBL monster
NVSBL monster <nvsbl....@gmail.com> writes:

[...]

> I'm trying to migrate my scrobbles from one account to a new one (sick
> of my username, can't change it). If a tool like this already exists,
> please tell me, but I'd still like to finish working on this script.

That sounds very useful. Did you get it working? I'd be interested in
using it.

Best wishes,

Dan

NVSBL monster

unread,
Mar 28, 2010, 11:31:27 AM3/28/10
to pylast
Unfortunately not, I'm still getting the same BadAuthenticationError.
If you can help me figure that out, I'm sure it will come together
quickly.

On Mar 28, 10:59 am, Dan Davison <davi...@stats.ox.ac.uk> wrote:

> >> >http://code.google.com/p/pylast/andthe mailing list/group is at
> >> >http://groups.google.com/group/pylast

Isaac Bowen

unread,
Apr 26, 2010, 7:22:46 PM4/26/10
to pylast
Getting the same BadAuthenticationError. Going to dig into it a bit,
see if I can find something.
> > >> >http://code.google.com/p/pylast/andthemailing list/group is at
> > >> >http://groups.google.com/group/pylast

--
You received this message because you are subscribed to the pylast mailing list.
To post to this mailing list, send email to pyl...@googlegroups.com
To unsubscribe from this group, send email to
pylast+un...@googlegroups.com
pylast is a python wrapper around last.fm's api. the project is hosted at http://code.google.com/p/pylast/ and the mailing list/group is at http://groups.google.com/group/pylast

Isaac Bowen

unread,
Apr 26, 2010, 7:59:08 PM4/26/10
to pylast
The problem lies in pylast.Scrobbler._do_handshake, as was noted in
the backtrace. There's some faulty logic in there that pertains to how
the authentication token is generated, and when to include api_key/sk.
Replace lines 3598-3611 with the following:

params = {"hs": "true", "p": "1.2.1", "c": self.client_id,
"v": self.client_version, "u": self.username, "t":
timestamp}

if self.network.api_key and self.network.api_secret and
self.network.session_key:
if not self.username:
self.username =
self.network.get_authenticated_user().get_name()
params["a"] = md5(self.network.api_secret + timestamp)
params["sk"] = self.network.session_key
params["api_key"] = self.network.api_key
elif self.password and self.username:
params["a"] = md5(self.password + timestamp)

Works here, should work for you as well, I think.

On Mar 28, 10:31 am, NVSBL monster <nvsbl.mon...@gmail.com> wrote:
> > >> >http://code.google.com/p/pylast/andthemailing list/group is at
> > >> >http://groups.google.com/group/pylast

--
You received this message because you are subscribed to the pylast mailing list.
To post to this mailing list, send email to pyl...@googlegroups.com
To unsubscribe from this group, send email to
pylast+un...@googlegroups.com
pylast is a python wrapper around last.fm's api. the project is hosted at http://code.google.com/p/pylast/ and the mailing list/group is at http://groups.google.com/group/pylast
Reply all
Reply to author
Forward
0 new messages