GithubHelp home page GithubHelp logo

pylast / pylast Goto Github PK

View Code? Open in Web Editor NEW
652.0 19.0 106.0 1.56 MB

A Python interface to Last.fm and Libre.fm

Home Page: https://pypi.org/project/pylast/

License: Apache License 2.0

Python 100.00%
python last-fm lastfm pylast music libre libre-fm librefm scrobble scrobbler scrobbling hacktoberfest

pylast's Introduction

pyLast

PyPI version Supported Python versions PyPI downloads Test Coverage (Codecov) Code style: Black DOI

A Python interface to Last.fm and other API-compatible websites such as Libre.fm.

Use the pydoc utility for help on usage or see tests/ for examples.

Installation

Install via pip:

python3 -m pip install pylast

Install latest development version:

python3 -m pip install -U git+https://github.com/pylast/pylast

Or from requirements.txt:

-e https://github.com/pylast/pylast.git#egg=pylast

Note:

  • pyLast 5.3+ supports Python 3.8-3.13.
  • pyLast 5.2+ supports Python 3.8-3.12.
  • pyLast 5.1 supports Python 3.7-3.11.
  • pyLast 5.0 supports Python 3.7-3.10.
  • pyLast 4.3 - 4.5 supports Python 3.6-3.10.
  • pyLast 4.0 - 4.2 supports Python 3.6-3.9.
  • pyLast 3.2 - 3.3 supports Python 3.5-3.8.
  • pyLast 3.0 - 3.1 supports Python 3.5-3.7.
  • pyLast 2.2 - 2.4 supports Python 2.7.10+, 3.4-3.7.
  • pyLast 2.0 - 2.1 supports Python 2.7.10+, 3.4-3.6.
  • pyLast 1.7 - 1.9 supports Python 2.7, 3.3-3.6.
  • pyLast 1.0 - 1.6 supports Python 2.7, 3.3-3.4.
  • pyLast 0.5 supports Python 2, 3.
  • pyLast < 0.5 supports Python 2.

Features

  • Simple public interface.
  • Access to all the data exposed by the Last.fm web services.
  • Scrobbling support.
  • Full object-oriented design.
  • Proxy support.
  • Internal caching support for some web services calls (disabled by default).
  • Support for other API-compatible networks like Libre.fm.

Getting started

Here's some simple code example to get you started. In order to create any object from pyLast, you need a Network object which represents a social music network that is Last.fm or any other API-compatible one. You can obtain a pre-configured one for Last.fm and use it as follows:

import pylast

# You have to have your own unique two values for API_KEY and API_SECRET
# Obtain yours from https://www.last.fm/api/account/create for Last.fm
API_KEY = "b25b959554ed76058ac220b7b2e0a026"  # this is a sample key
API_SECRET = "425b55975eed76058ac220b7b4e8a054"

# In order to perform a write operation you need to authenticate yourself
username = "your_user_name"
password_hash = pylast.md5("your_password")

network = pylast.LastFMNetwork(
    api_key=API_KEY,
    api_secret=API_SECRET,
    username=username,
    password_hash=password_hash,
)

Alternatively, instead of creating network with a username and password, you can authenticate with a session key:

import pylast

SESSION_KEY_FILE = os.path.join(os.path.expanduser("~"), ".session_key")
network = pylast.LastFMNetwork(API_KEY, API_SECRET)
if not os.path.exists(SESSION_KEY_FILE):
    skg = pylast.SessionKeyGenerator(network)
    url = skg.get_web_auth_url()

    print(f"Please authorize this script to access your account: {url}\n")
    import time
    import webbrowser

    webbrowser.open(url)

    while True:
        try:
            session_key = skg.get_web_auth_session_key(url)
            with open(SESSION_KEY_FILE, "w") as f:
                f.write(session_key)
            break
        except pylast.WSError:
            time.sleep(1)
else:
    session_key = open(SESSION_KEY_FILE).read()

network.session_key = session_key

And away we go:

# Now you can use that object everywhere
track = network.get_track("Iron Maiden", "The Nomad")
track.love()
track.add_tags(("awesome", "favorite"))

# Type help(pylast.LastFMNetwork) or help(pylast) in a Python interpreter
# to get more help about anything and see examples of how it works

More examples in hugovk/lastfm-tools and tests/.

Testing

The tests/ directory contains integration and unit tests with Last.fm, and plenty of code examples.

For integration tests you need a test account at Last.fm that will become cluttered with test data, and an API key and secret. Either copy example_test_pylast.yaml to test_pylast.yaml and fill out the credentials, or set them as environment variables like:

export PYLAST_USERNAME=TODO_ENTER_YOURS_HERE
export PYLAST_PASSWORD_HASH=TODO_ENTER_YOURS_HERE
export PYLAST_API_KEY=TODO_ENTER_YOURS_HERE
export PYLAST_API_SECRET=TODO_ENTER_YOURS_HERE

To run all unit and integration tests:

python3 -m pip install -e ".[tests]"
pytest

Or run just one test case:

pytest -k test_scrobble

To run with coverage:

pytest -v --cov pylast --cov-report term-missing
coverage report # for command-line report
coverage html   # for HTML report
open htmlcov/index.html

Logging

To enable from your own code:

import logging
import pylast

logging.basicConfig(level=logging.INFO)


network = pylast.LastFMNetwork(...)

To enable from pytest:

pytest --log-cli-level info -k test_album_search_images

To also see data returned from the API, use level=logging.DEBUG or --log-cli-level debug instead.

pylast's People

Contributors

amrhassan avatar ben-xo avatar brtkrbzhnv avatar chandlerswift avatar colonelpanic8 avatar davidmetcalfe avatar edwardbetts avatar esimonov avatar hugovk avatar inversion avatar irishsmurf avatar jacebrowning avatar kiliankoe avatar kvanzuijlen avatar kvanzuijlen-shm avatar lipka avatar meebcodes avatar mergify[bot] avatar peterjeschke avatar philiptrauner avatar pre-commit-ci[bot] avatar qwhex avatar renovate-bot avatar renovate[bot] avatar sfordinc avatar simmel avatar tetrapus avatar tieubinhco avatar zer0kg avatar zinootje avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pylast's Issues

Unused definitions

From [email protected] on October 19, 2009 14:33:06

There are some unused definitions:
I don't submit a patch for this because they may be some reminders of some
TODO stuff. It will be good to clear them up.

W:1510:Artist.get_top_fans: Unused variable 'params'
W:1578:Artist.get_images: Unused argument 'order'
W:1666:Event.attend: Unused variable 'doc'
W:2161:Playlist.get_url: Unused variable 'url'
W:2935:User.get_top_tags: Unused argument 'limit'
W:3690:Scrobbler.report_now_playing: Unused variable 'response'
W:3725:Scrobbler.scrobble: Unused variable 'response'
W: 32: Unused import codecs
W: 36: Unused import os

Original issue: http://code.google.com/p/pylast/issues/detail?id=28

BadAuthenticationError when trying to scrobble

From [email protected] on March 16, 2010 22:52:01

Assuming I've got a working Network object,

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)

Traceback (most recent call last):
File "", line 1, in
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

Original issue: http://code.google.com/p/pylast/issues/detail?id=36

NoneType object is unsubscripable

From [email protected] on November 05, 2008 21:09:29

Please type example code that produces the issue: from pylast import *
import cgi

form = cgi.FieldStorage()

assume a form was submitted with a parameter 'user'

following line should use form['user'].value, but instead makes

a mistake and passes an object

lib = Library(form['user'], API_KEY, API_SECRET, "")
tracks = lib.getTracks() What is the expected output? What do you see instead? Output: Error: nonetype object is unsubscriptable
Expected output: should indicate that the user does not exist, or have the
same output as passing an invalid user to Library() What version of pyLast is this? 0.2.17 Please provide any additional information below. This shouldn't come up if the user uses pylast correctly, but it helps
debugging if they make a mistake.

Original issue: http://code.google.com/p/pylast/issues/detail?id=8

NameError: global name 'unicode' is not defined

From [email protected] on January 02, 2010 11:49:31

hi,
I'm on ubuntu jaunty
when I run

sudo python setup.py install

I get this

Traceback (most recent call last):
  File "setup.py", line 25, in <module>
    version = "0.4." + get_build(),
  File "setup.py", line 22, in get_build
    return unicode(build)
NameError: global name 'unicode' is not defined

pyLast v 0.4.20
Downloaded from http://pypi.python.org/pypi/pylast my python version

$ python -V
Python 3.0.1+

Original issue: http://code.google.com/p/pylast/issues/detail?id=31

get_tags() method throws 'Invalid method signature supplied' exception

From [email protected] on April 03, 2010 17:28:21

The get_tags() method throws an "Invalid method signature" error, both on Album and Artist objects.
Sample code:

lastfm = pylast.get_lastfm_network(api_key=API_KEY, api_secret=API_SECRET)
obj    = lastfm.get_artist('Air')
tags   = obj.get_tags()
print tags

Leads to the following exception:

Traceback (most recent call last):
  File "test_tag.py", line 15, in <module>
    tags   = obj.get_tags()
  File "/Users/rix0rrr/Documents/Dev/genre_tagger/server/pylast.py", line 1024, in get_tags
    doc = self._request(self.ws_prefix + '.getTags', False, params)
  File "/Users/rix0rrr/Documents/Dev/genre_tagger/server/pylast.py", line 969, in _request
    return _Request(self.network, method_name, params).execute(cacheable)
  File "/Users/rix0rrr/Documents/Dev/genre_tagger/server/pylast.py", line 812, in execute
    response = self._download_response()
  File "/Users/rix0rrr/Documents/Dev/genre_tagger/server/pylast.py", line 803, in _download_response
    self._check_response_for_errors(response_text)
  File "/Users/rix0rrr/Documents/Dev/genre_tagger/server/pylast.py", line 826, in 

_check_response_for_errors
raise WSError(self.network, status, details)
server.pylast.WSError: Invalid method signature supplied

Original issue: http://code.google.com/p/pylast/issues/detail?id=41

_do_handshake in scrobbler never called if scrobbling without reporting nowplaying

From [email protected] on October 21, 2010 01:21:20

In line 3651 of pylast.py, in method report_now_playing, if scrobbler request fails, handshake is forced and submissions_url as well as nowplaying_url are obtained.

These values are never requested elsewhere so if one tries scrobbling without reporting nowplaying, as in line 3683 in method scrobble, handshake is not performed and scrobbles are never submitted. Probably should be as below (replacing line 3683), right?

try:
ScrobblerRequest(self.submissions_url, params, self.network).execute()
except BadSessionError:
self._do_handshake()
self.scrobble( artist, title, time_started, source, mode, duration, album, track_number, mbid);

Original issue: http://code.google.com/p/pylast/issues/detail?id=49

A couple patches

From [email protected] on October 20, 2009 03:37:00

commit d95a02ff2aa2ec5d6c6d392b86c9ffe2ef99adb5
Author: Adeodato Simó [email protected]
Date: Tue Oct 20 01:21:45 2009 +0100

Redefine SCROBBLE_MODE_PLAYED as "", provide SCROBBLE_MODE_LOVED as "L".

The 'L' rating is only to be used if the user has manually loved the
track. For a normal play, the documentation clearly says that the rating
should be the empty string.

commit 6f04ee43f8829c8ecefcc03379f20e1b5fa9f286
Author: Adeodato Simó [email protected]
Date: Tue Oct 20 01:21:08 2009 +0100

Fix reference to undefined variable in Track._remove_tag().

Attachment: 0001-Fix-reference-to-undefined-variable-in-Track.remove.diff 0002-Redefine-SCROBBLE_MODE_PLAYED-as-provide-SCROBBLE_MOD.diff

Original issue: http://code.google.com/p/pylast/issues/detail?id=29

Get updated capitalization for names when we can

From [email protected] on March 20, 2010 07:27:13

Just as an example: if you have an artist object and run a get_similar() on it, the xml returned will
contain the artist name with proper capitalization. If you created the artist object with improper
capitalization, running get_name() on it will show it improperly capitalized, but if you've done
get_similar() before you have already gotten the info you need to update that, so why not check to
see if the artist name you got back has the same capitalization as the one we have cached and if
not, update it?

Original issue: http://code.google.com/p/pylast/issues/detail?id=37

getTopWeeklyTracks does not extract playcount

From jehiah on December 19, 2008 02:55:24

Please type example code that produces the issue: The last.fm api shows that there is a playcount variable returned for this
call http://www.last.fm/api/show?service=282 but it's not extracted into
the results.

for track in user.getTopWeeklyTracks(from,to):
print track.playcount What version of pyLast is this? > trunk Please provide any additional information below. the attached diff patch extracts the playcount and the url

Attachment: pylast_extract_playcount.diff

Original issue: http://code.google.com/p/pylast/issues/detail?id=11

"NoneType object is unsubscriptable" Exception

From [email protected] on August 21, 2008 03:27:44

Hi,

I'm getting a "NoneType object is unsubscriptable" error with multiple API methods
(Album.getImage and Artist.getBioSummary). I recently updated my copy of pylast from the
alpha version from August 15th to the latest SVN version. I didn't get this error when using the
alpha code.

Here's the traceback I have for the error when using the getImage method.

Traceback:
File "/Users/brett/Workspace/Development/lastfm.py" in get_data

  1.  album.lf_image_url = lf_album.getImage(pylast.IMAGE_LARGE)
    
    File "/Library/Python/2.5/site-packages/pylast.py" in getImage
  2.  return self._getCachedInfo()['images'][size]
    

Exception Type: TypeError
Exception Value: 'NoneType' object is unsubscriptable

I apologize if this is a bug in my code and not pylast. I'm just getting started with Python, and I
was really happy to find this library was available to save me the time of having to write my own.
Thanks for posting your work, and I hope my bug report helps!

Original issue: http://code.google.com/p/pylast/issues/detail?id=1

Two Library's methods raise exceptions

From [email protected] on February 04, 2009 07:57:50

In version "0.3 alpha", Library.is_end_of_albums() and
Library.get_albums_page() are broken because you are trying to access the
wrong api methods ("library.get_albums" instead of "library.getAlbums").
Diff attached.

And you should rename the "setup" file to "setup.py", so distutils and
setuptools can find it...
$ PYTHONPATH=/tmp/pylast-test; mkdir -p "$PYTHONPATH"; easy_install
--install-dir "$PYTHONPATH" http://pylast.googlecode.com/files/pylast-0.3.0a.tar.gz Creating /tmp/pylast-test/site.py
Downloading http://pylast.googlecode.com/files/pylast-0.3.0a.tar.gz Processing pylast-0.3.0a.tar.gz
error: Couldn't find a setup script in
/tmp/easy_install-KbFrJ2/pylast-0.3.0a.tar.gz

Attachment: get_albums_page-fix.diff

Original issue: http://code.google.com/p/pylast/issues/detail?id=13

__hash__ should be defined for Artist, Album etc.

From [email protected] on October 06, 2009 17:11:34

Please type example code that produces the issue: import pylast
network = pylast.get_lastfm_network(api_key = "(KEY)", api_secret = "(KEY)")

Both rask00 and radio_head247 have RADIOHEAD as top artist

radiohead_1 = network.get_user("rask00").get_top_artists()[0].item
radiohead_2 = network.get_user("radio_head247").get_top_artists()[0].item

Therefore the following statement correctly returns TRUE

radiohead_1 == radiohead_2

But the following statement does not work correctly:

set([radiohead_1, radiohead_2]) What is the expected output? What do you see instead? It is supposed to show set([Radiohead]), while it shows set([Radiohead, Radiohead]) What version of pyLast is this? 0.4.13 Please provide any additional information below. The solution to this bug is to add a function hash to the class Artist and the other related
classes. The reason is explained here: http://wiki.python.org/moin/DictionaryKeys Since eq and ne are already defined in Artist using the artist's name, then the solution is
to add the following code to the class Artist:

def __hash__(self):
    return hash(self.get_name().lower())

and do the same on the other related classes (Album, etc...)

Original issue: http://code.google.com/p/pylast/issues/detail?id=25

non-ascii unicode breaks Album.get_imge_url()

From [email protected] on June 14, 2009 17:33:33

Please type example code that produces the issue: for alb in albums:
url = alb.get_image_url() What is the expected output? What do you see instead? should get a url, but if name contains non ascii characters get unicode error:

File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 657, in
get_image_url
return _extract_all(self._request("album.getInfo", cacheable = True),
'image')[size]
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 354, in
_request
return _Request(method_name, params, *self.auth_data).execute(cacheable)
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 152, in
init
self.sign_it()
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 158, in sign_it
self.params['api_sig'] = self._get_signature()
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 175, in
_get_signature
return md5(string)
File "/usr/local/lib/python2.6/dist-packages/pylast.py", line 2787, in md5
hash.update(text)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in
position 12: ordinal not in range(128) What version of pyLast is this? 0.3.4 Please provide any additional information below.

Original issue: http://code.google.com/p/pylast/issues/detail?id=19

Authentication as described in Wiki does not work

From [email protected] on September 10, 2008 18:58:25

I am using revision 124 , which was current as of last night (Sept 09, 2008).

When I try to authenticate, get the following error:

<type 'exceptions.TypeError'>: 'NoneType' object is unsubscriptable

Apparently sg.getSessionData(token) is returning None rather than a
dictionary with the session key. I took a look in the source code, and
discovered that this happens when the getSessionData method of the
SessionGenerator object tries to execute a Request, and the an exception is
returned. In my case the exception raised is a ServiceException.

I should also note that the auth_url appears to work correctly, that is,
according to the last.fm website, I successfully give my application
permission to access my account. I am accessing my own account, to which
the api key is also registered, but this should not cause a problem.

Any ideas what could be raising this ServiceException? Also, it might be
nice if the .getSessionData method raised a ServiceException rather than
simply returning None. Returning None means that developers have to do
some detective work, and it causes unexpected problems.

Conrad Lee

Original issue: http://code.google.com/p/pylast/issues/detail?id=2

User.fetchPlaylist

From [email protected] on October 16, 2008 12:11:40

Please type example code that produces the issue: user = User('RJ', API_KEY, API_SECRET, SESSION_KEY)
for playlist in user.getPlaylistIDs() :
user.fetchPlaylist(playlist['id']) What is the expected output? What do you see instead? I expect the playlist, instead I see this:

File "/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/site-
packages/pylast.py", line 2376, in fetchPlaylist
return Playlist(uri, self.api_key).fetch()
TypeError: init() takes exactly 5 arguments (3 given) What version of pyLast is this? 0.2b11 Please provide any additional information below. I think the problem is in the definition of User.fetchPlaylist
While the fetchPlaylist function of other classes returns:
return Playlist(uri, *self.auth_data).fetch()
using self.auth_data,
the fetchPlaylist function of the class User returns:
return Playlist(uri, self.api_key).fetch()

Original issue: http://code.google.com/p/pylast/issues/detail?id=3

Album.get_cover_image() AttributeError

From [email protected] on December 22, 2009 02:55:43

Please type example code that produces the issue: a.get_cover_image() What is the expected output? What do you see instead? Traceback (most recent call last):
File "", line 1, in
File "pylast.py", line 1184, in get_cover_image
return _extract_all(self._request("album.getInfo", cacheable = True), 'image
')[size]
File "pylast.py", line 957, in _request
return _Request(self.network, method_name, params).execute(cacheable)
File "pylast.py", line 811, in execute
response = self._download_response()
File "pylast.py", line 781, in _download_response
data.append('='.join((name, urllib.quote_plus(_string(self.params[name])))))

File "pylast.py", line 3358, in _string
return text.encode("utf-8")
AttributeError: 'Album' object has no attribute 'encode' What version of pyLast is this? 0.4.20 Please provide any additional information below.

Original issue: http://code.google.com/p/pylast/issues/detail?id=30

_do_handshake in scrobbler never called if scrobbling without reporting nowplaying

From [email protected] on October 21, 2010 01:21:26

In line 3651 of pylast.py, in method report_now_playing, if scrobbler request fails, handshake is forced and submissions_url as well as nowplaying_url are obtained.

These values are never requested elsewhere so if one tries scrobbling without reporting nowplaying, as in line 3683 in method scrobble, handshake is not performed and scrobbles are never submitted. Probably should be as below (replacing line 3683), right?

try:
ScrobblerRequest(self.submissions_url, params, self.network).execute()
except BadSessionError:
self._do_handshake()
self.scrobble( artist, title, time_started, source, mode, duration, album, track_number, mbid);

Original issue: http://code.google.com/p/pylast/issues/detail?id=50

caching does not scale and create thousands of tiny files in a single directory

From [email protected] on June 25, 2009 14:49:10

Please type example code that produces the issue: enable_caching('.cache') What is the expected output? What do you see instead? each individual object is serialized to disk in its own file. This cannot
scale as it end up creating tens of thousands of individual files on disk.

It would be more appropriate to use something like shelve to store it or
even sqllite What version of pyLast is this? 0.3.1 Please provide any additional information below.

Original issue: http://code.google.com/p/pylast/issues/detail?id=20

_get_signature is incorrectly calling encode(utf-8) for argument in md5 function

From [email protected] on March 27, 2009 14:52:45

Please type example code that produces the issue: def _get_signature(self):
"""Returns a 32-character hexadecimal md5 hash of the signature string."""

    keys = self.params.keys()[:]

    keys.sort()

    string = unicode()

    for name in keys:
        string += name
        string += self.params[name]

    string += self.api_secret

    return md5(string.encode('utf-8')) What is the expected output? What do you see instead? Should be:

    return md5(string)

Since the md5 function takes care of the encode What version of pyLast is this? 0.3.1 Please provide any additional information below. Fetching some artist/track with non ascii characters would lead otherwise
to a flurry of error similar to:

'ascii' codec can't decode byte 0xc3 in position 56: ordinal not in range(128)

Original issue: http://code.google.com/p/pylast/issues/detail?id=16

get_loved_tracks doesn't return a timestamp

From [email protected] on January 28, 2010 20:17:35

Please type example code that produces the issue: user.get_loved_tracks() What is the expected output? What do you see instead? I'd like to see something similar to get_recent_tracks() which does include a timestamp. What version of pyLast is this? 0.4 Please provide any additional information below. Something similar to the get_recent_tracks() method should suffice, and shouldn't be to hard to
implement. I will have a look at it and post some code asap.

Original issue: http://code.google.com/p/pylast/issues/detail?id=33

[PATCH] Whitespace fix

From [email protected] on October 19, 2009 13:11:21

What version of pyLast is this? r214 Please provide any additional information below. There are a lot of trailing whitespaces in the code. You can use
":%s/\s+$//gc" from VIM to remove them. I've also attached a patch.
You can use the following to see them in vim:
let python_space_errors=1
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s+$/

Attachment: whitespace-removal.patch

Original issue: http://code.google.com/p/pylast/issues/detail?id=26

No anonymous access to data

From [email protected] on March 08, 2010 14:08:23

According to last.fm API specs, some services such as album.getinfo do NOT
require authentification (see http://www.lastfm.ru/api/show?service=290 as
an example), but pylast requires it. Please type example code that produces the issue: import pylast

api_key = "my api key"
api_secret = "my secret key"

username = "TLemur"
password_hash = pylast.md5("")

network = pylast.get_lastfm_network(api_key = API_KEY, api_secret =
API_SECRET, username = username, password_hash = password_hash)

user = pylast.User(user_name, network)
tracks = user.get_top_tracks(period='overall')
for track in tracks:
print track What is the expected output? What do you see instead? The expected output is the list of user's top tracks, instead I see a error:
pylast.WSError: Invalid authentication token. Please check
username/password supplied What version of pyLast is this? 0.4 rev. 222

Original issue: http://code.google.com/p/pylast/issues/detail?id=35

Authentication and MD5 with non-ASCII characters

From [email protected] on October 19, 2008 19:27:42

Please type example code that produces the issue: user = User('Zazhigalo4ka', API_KEY, API_SECRET, SESSION_KEY)
p = user.getPlaylistIDs()
pid = p[0]
playlist = Playlist('lastfm://playlist/%s' % pid, API_KEY, API_SECRET, SESSION_KEY)
tracks = playlist.fetch()
t1 = tracks[1]
t1.getTitle()
t1.getTags() What is the expected output? What do you see instead? I expect the title (which is printed) and the tags (which are not printed). The following error is
reported:

Traceback (most recent call last):
File "", line 1, in
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
pylast.py", line 514, in getTags
doc = Request(self, self.ws_prefix + '.getTags', self.api_key, params, True, self.secret).execute
()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
pylast.py", line 285, in execute
self.params['api_sig'] = self._getSignature()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-packages/
pylast.py", line 275, in _getSignature
hash.update(string)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 52-54: ordinal not in range
(128) What version of pyLast is this? pyLast-0.2b13 Please provide any additional information below. This happens both with Python 2.5 and Python 2.6, and I guess the problem is related to the
creation of the MD5 hash with a track that contains non-ASCII characters. The last.fm page http://www.last.fm/api/authspec reminds to "Ensure your parameters are utf8 encoded.", so the
problem might be there.

(Thanks again for this package, by the way!!)

Original issue: http://code.google.com/p/pylast/issues/detail?id=7

problem with get_*_by_mbid

From [email protected] on September 08, 2009 17:49:32

Please type example code that produces the issue: >> lfn = pylast.get_lastfm_network(API_KEY, API_SECRET)

lfn.get_artist_by_mbid('f467181e-d5e0-4285-b47e-e853dcc89ee7') What is the expected output? What do you see instead? /usr/lib/python2.5/site-packages/pylast-0.4.9-py2.5.egg/pylast.pyc in
init(self, network, method_name, params)
775 self.network = network
776
--> 777 (self.api_key, self.api_secret, self.session_key) =
network._get_ws_auth(False)
778
779 self.params["api_key"] = self.api_key

AttributeError: 'str' object has no attribute '_get_ws_auth' What version of pyLast is this? 0.4

Original issue: http://code.google.com/p/pylast/issues/detail?id=23

"list index out of range" in User.get_recent_tracks()

From [email protected] on January 10, 2010 18:01:10

Please type example code that produces the issue: my_user.get_recent_tracks() What is the expected output? What do you see instead? Traceback (most recent call last):
File "./lastadd.py", line 31, in
print user.get_recent_tracks()
File "/usr/lib/python2.5/site-packages/pylast.py", line 2800, in
get_recent_tracks
timestamp = track.getElementsByTagName("date")[0].getAttribute("uts")
IndexError: list index out of range What version of pyLast is this? 0.4 Please provide any additional information below. Looking at the code, I think the continue for attribute "nowplaying" should
be first in the track loop, so that no element gets extracted for the now
playing track at all. This seems particularly important for the date
element which is not present in the now playing track, which results in the
above error.

Original issue: http://code.google.com/p/pylast/issues/detail?id=32

Some characters causing trouble in get_top_tags()

From [email protected] on October 04, 2010 23:21:06

!/usr/bin/env python

import pylast
import os

API_KEY = ""
API_SECRET = ""
u_name = ""
p_hash = pylast.md5("")
lastfm = pylast.get_lastfm_network(api_key = API_KEY, api_secret = API_SECRET, username = u_name, password_hash = p_hash)
Artists = os.listdir(".")
Artists.sort()
for ArtistName in Artists:
print ArtistName
Artist = lastfm.get_artist(ArtistName)
TopTags = Artist.get_top_tags()

Revision: 226

Reproduce:
Create a folder and cd into it. Then make folder Mötorhead or Ljå
Run the program from the first dir you created.

Output:
~/test$ ls
Enslaved Leaves' Eyes Ljå Lumsk Mötorhead
~/test$ /bin/pytest.py
Enslaved
Leaves' Eyes
Ljå
Traceback (most recent call last):
File "
/bin/pytest.py", line 17, in
TopTags = Artist.get_top_tags()
File "/usr/lib/python2.6/pylast.py", line 1080, in get_top_tags
doc = self._request(self.ws_prefix + '.getTopTags', True)
File "/usr/lib/python2.6/pylast.py", line 967, in _request
return _Request(self.network, method_name, params).execute(cacheable)
File "/usr/lib/python2.6/pylast.py", line 719, in init
self.sign_it()
File "/usr/lib/python2.6/pylast.py", line 725, in sign_it
self.params['api_sig'] = self._get_signature()
File "/usr/lib/python2.6/pylast.py", line 738, in _get_signature
string += self.params[name]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 47: ordinal not in range(128)

Original issue: http://code.google.com/p/pylast/issues/detail?id=48

md5 module is deprecated

From [email protected] on October 16, 2008 16:37:09

Please type example code that produces the issue: [Any code] What is the expected output? What do you see instead? /Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-
packages/pylast.py:32: DeprecationWarning: the md5 module is deprecated; use hashlib instead
import md5 What version of pyLast is this? pyLast-0.2b12.tar.gz Please provide any additional information below. This occurs with Python 2.6 (on an Intel-based Mac OS X with MacPython), and did not occur with
Python 2.3

Original issue: http://code.google.com/p/pylast/issues/detail?id=4

_get_cache_key is concatening non utf-8 encoded objects

From [email protected] on March 27, 2009 15:03:18

Please type example code that produces the issue: def _get_cache_key(self):
"""The cache key is a string of concatenated sorted names and values."""

    keys = self.params.keys()
    keys.sort()

    cache_key = str()

    for key in keys:
        if key != "api_sig" and key != "api_key" and key != "sk":
            cache_key += urllib.quote_plus(key) +

urllib.quote_plus(urllib.quote_plus(self.params[key]))

    return hashlib.sha1(cache_key).hexdigest() What is the expected output? What do you see instead? There are 2 chained calls to urllib.quote_plus which is likely a typo, plus

the key/params are not utf-8 encoded while this is assembled into a str object.

Should be:

cache_key += urllib.quote_plus(key.encode('utf-8')) +
urllib.quote_plus(self.params[key].encode('utf-8')) What version of pyLast is this? 0.3.1 Please provide any additional information below. Having some unicode params makes it blow up with:

File "C:\dev\code\lastfm\pylast.py", line 181, in _get_cache_key
cache_key += urllib.quote_plus(key) +
urllib.quote_plus(urllib.quote_plus(self.params[key]))
File "c:\dev\Python25\lib\urllib.py", line 1211, in quote_plus
s = quote(s, safe + ' ')
File "c:\dev\Python25\lib\urllib.py", line 1205, in quote
res = map(safe_map.getitem, s)

KeyError: u'\xfc'

Original issue: http://code.google.com/p/pylast/issues/detail?id=17

[PATCH] Fix redefine of built-ins

From [email protected] on October 19, 2009 14:29:09

What version of pyLast is this? r214 Please provide any additional information below. There are a lot of 'list' and 'id' redefines in the code I fixed most of
them. there are some remaining:

2038:Playlist.init: Redefining built-in 'id'
3379:Venue.init: Redefining built-in 'id'
3424:md5: Redefining built-in 'hash'

Attachment: redefined_built-ins.patch

Original issue: http://code.google.com/p/pylast/issues/detail?id=27

User.get_friends limit parameter

From [email protected] on October 16, 2008 17:11:12

Please type example code that produces the issue: User(user, API_KEY, API_SECRET, SESSION_KEY).getFriends(limit=5) What is the expected output? What do you see instead? The expected output is a list of 5 friends. Instead, I get this:

Traceback (most recent call last):
File "retrieveusers.py", line 86, in
user_friends = get_friends(user)
File "retrieveusers.py", line 59, in get_friends
for friend in User(user, API_KEY, API_SECRET, SESSION_KEY).getFriends(limit=5):
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-
packages/pylast.py", line 2270, in getFriends
doc = Request(self, 'user.getFriends', self.api_key, params).execute()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-
packages/pylast.py", line 289, in execute
data.append('='.join((name, urllib.quote_plus(self.params[name].encode('utf-8')))))
AttributeError: 'int' object has no attribute 'encode' What version of pyLast is this? Please provide any additional information below. The problem is that the limit parameter has to be passed as a string, for instance limit='5' works,
while limit=5 as an integer does not work. I guess this should be fixed, or at least documented

Original issue: http://code.google.com/p/pylast/issues/detail?id=5

User.getFriends breaks when a user has many friends

From [email protected] on October 16, 2008 17:14:50

Please type example code that produces the issue: User('cheap_mondays', API_KEY, API_SECRET, SESSION_KEY).getFriends() What is the expected output? What do you see instead? I expect the list of friends of 'cheap_mondays', instead I get this:

Traceback (most recent call last):
File "retrieveusers.py", line 53, in
User('cheap_mondays', API_KEY, API_SECRET, SESSION_KEY).getFriends()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-
packages/pylast.py", line 2270, in getFriends
doc = Request(self, 'user.getFriends', self.api_key, params).execute()
File "/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/site-
packages/pylast.py", line 304, in execute
doc = minidom.parse(response)
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/dom/minidom.py",
line 1918, in parse
return expatbuilder.parse(file)
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/dom/expatbuilder.py
", line 928, in parse
result = builder.parseFile(file)
File
"/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/xml/dom/expatbuilder.py
", line 211, in parseFile
parser.Parse("", True)
xml.parsers.expat.ExpatError: no element found: line 18585, column 73 What version of pyLast is this? pyLast-0.2b12.tar.gz Please provide any additional information below. This happens because the user cheap_mondays has almost 3,000 friends! http://www.last.fm/user/cheap_mondays/friends I guess in this case, the function should not crash, but return something or wait.

Original issue: http://code.google.com/p/pylast/issues/detail?id=6

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.