youpy / ruby-lastfm Goto Github PK
View Code? Open in Web Editor NEWA Ruby interface for Last.fm Web Services
License: MIT License
A Ruby interface for Last.fm Web Services
License: MIT License
When calling get_recent_tracks for my last.fm data, some nasty data from Last.fm causes the gem to blow up with:
REXML::ParseException: #<RuntimeError: Illegal character "\uFFFE" in raw string "�䬀愀瀀 匀氀愀瀀">
This probably should get eaten by the gem because as it is, the only way I could effectively catch this is to loop through get_recent_tracks once per song which is a Bad Thing.
Lastfm::MethodCategory::Track#get_tags
uses method_with_authentication
, but the getTags end point on Last.fm doesn't require authentication, which is causing some confusion. I'll try and submit a pull request to adjust this.
Nice gem by the way, very elegant.
I have a problem when I try to set the session attribute.
@lastfm.session = @lastfm.auth.get_session(token: @token)['api_key']
I don't know exactly what to put inside [ ]. I've tried api_key, but I get the following error
Invalid method signature supplied
How can I solve this?
Thanks
lastfm = Lastfm.new(ENV['LAST_FM_KEY'],ENV['LAST_FM_SECRET'])
lastfm.geo.get_events(location: "New York")
>Lastfm::ApiError: Invalid Method - No method with that name in this package
lastfm.artist.get_events(artist: "Morrissey")
>Lastfm::ApiError: Invalid Method - No method with that name in this package
https://plus.google.com/+TimothyMalseed/posts/Sn6qcQuPDrX
Their status doesn't reflect deletion or changes in these methods.
http://status.last.fm/
Anyone else having these problems? Or know what the issue is? I reached out to LastFM but haven't heard back yet.
The problem comes when the required params are dependent, such as:
album.getInfo:
Here you can provide whether mbid or both artist and album.
The gem only implements the artist and album case, not if you provide only the mbid.
The way regular_method is implemented doesn't allow an easy way to solve these cases (or at least I don't see it :( )
def regular_method(id, mandatory, optional = [], &block)
__define_method(:request, id, mandatory, optional, &block)
end
Any idea of how we could handle the mbid case? It's not only a problem of this method (album.getInfo) but also in many other...
When trying to install lastfm gem i get this error message.
ERROR: Error installing lastfm:
lastfm requires lastfm (>= 0)
OSX Lion
ruby 1.9.3p125
Hello,
I upgraded to 1.8.0 and I'm getting this exception on now_playing:
xml-simple (1.1.1) lib/xmlsimple.rb:990:in `find_xml_file'
xml-simple (1.1.1) lib/xmlsimple.rb:168:in `xml_in'
xml-simple (1.1.1) lib/xmlsimple.rb:203:in `xml_in'
lastfm (1.8.0) lib/lastfm/response.rb:9:in `initialize'
lastfm (1.8.0) lib/lastfm.rb:94:in `new'
lastfm (1.8.0) lib/lastfm.rb:94:in `request'
lastfm (1.8.0) lib/lastfm/method_category/base.rb:54:in `request'
lastfm (1.8.0) lib/lastfm/method_category/base.rb:39:in `write_request'
lastfm (1.8.0) lib/lastfm/method_category/base.rb:29:in `block in __define_method'
client.track.update_now_playing(artist, title, album, position)
# or
client.track.update_now_playing(artist: artist, track: title, album: album, trackNumber: position)
Is the Last.fm service being funky?
Some companies will only use gems with a certain license.
The canonical and easy way to check is via the gemspec
via e.g.
spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']
There is even a License Finder to help companies ensure all gems they use
meet their licensing needs. This tool depends on license information being available in the gemspec.
Including a license in your gemspec is a good practice, in any case.
How did I find you?
I'm using a script to collect stats on gems, originally looking for download data, but decided to collect licenses too,
and make issues for missing ones as a public service :)
https://gist.github.com/bf4/5952053#file-license_issue-rb-L13 So far it's going pretty well
Last.FM has JSON API with format=json
Here is what I get when I try both get_token and get_session:
I have the gem accepting a token and getting a session key for a given user. I'm storing this session key for later use in my User
table. My question is, how do I sign my requests like, lastfm.track.scrobble
and lastfm.track.update_now_playing
, with this saved session key so I do not have get the user to give me a new token and retrieve a new session key every time.
cc: @youpy
Thanks!
last.fm returns invalid XML, missing namespace declaration.
<?xml version="1.0" encoding="UTF-8" ?>
<lfm status="ok">
<results for="Believe">
<opensearch:Query role="request" searchTerms="Believe" startPage="1"></opensearch:Query>
...
valid XML is:
<?xml version="1.0" encoding="UTF-8" ?>
<lfm status="ok">
<results for="Believe" xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
<opensearch:Query role="request" searchTerms="Believe" startPage="1"></opensearch:Query>
...
https://github.com/youpy/ruby-lastfm/blob/master/lib/lastfm/method_category/album.rb#L33
I'm debugging an issue for which album.getInfo
raises an error, apparently the lastfm api removed the releasedate
key: http://ws.audioscrobbler.com/2.0/?method=album.getinfo&api_key=19e067c215c61839b6a907e90d1d8d6e&artist=Cher&album=Believe&format=json
I'm not sure if it's intended and I'm going to contact them.
I'd like to contribute, but the Rakefile seems to depend on rspec 1.3. As I have 2.1.0 installed I can't install the library. I've attempted a few different fixes, but my rake foo isn't good enough. Any chance you could upgrade the Rakefile to support 2.1.0?
It is possible to get three different return types from user.get_loved_tracks
:
This leads to ugly code. For example if one wants to use each
on the result from user.get_loved_tracks
one has to check before whether it is nil or a hash. This is similar to #46.
Problem with artist.
I thinks this placeformed=>"Montreal & Ottawa, Canada"
don't escaped
lastfm.artist.get_info(artist: "Obey The Brave")
/Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/rexml/parsers/treeparser.rb:95:in `rescue in parse': #<RuntimeError: Illegal character '&' in raw string "Montreal & Ottawa, Canada"> (REXML::ParseException)
/Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/rexml/text.rb:155:in `block in check'
/Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/rexml/text.rb:153:in `scan'
/Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/rexml/text.rb:153:in `check'
/Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/rexml/text.rb:120:in `initialize'
/Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/rexml/parsers/treeparser.rb:46:in `new'
/Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/rexml/parsers/treeparser.rb:46:in `parse'
/Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/rexml/document.rb:283:in `build'
/Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/rexml/document.rb:43:in `initialize'
/Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/xml-simple-1.1.2/lib/xmlsimple.rb:965:in `new'
/Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/xml-simple-1.1.2/lib/xmlsimple.rb:965:in `parse'
/Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/xml-simple-1.1.2/lib/xmlsimple.rb:164:in `xml_in'
/Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/xml-simple-1.1.2/lib/xmlsimple.rb:203:in `xml_in'
/Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/lastfm-1.19.0/lib/lastfm/response.rb:11:in `rescue in initialize'
/Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/lastfm-1.19.0/lib/lastfm/response.rb:9:in `initialize'
/Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/lastfm-1.19.0/lib/lastfm.rb:114:in `new'
/Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/lastfm-1.19.0/lib/lastfm.rb:114:in `request'
/Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/lastfm-1.19.0/lib/lastfm/method_category/base.rb:84:in `request'
/Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/lastfm-1.19.0/lib/lastfm/method_category/base.rb:46:in `block in __define_method'
lastfm.rb:11:in `<main>'
...
Illegal character '&' in raw string "Montreal & Ottawa, Canada"
Line: 112
Position: 6708
Last 80 unconsumed characters:
</placeformed>
from /Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/rexml/parsers/treeparser.rb:20:in `parse'
from /Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/rexml/document.rb:283:in `build'
from /Users/onemanstartup/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/rexml/document.rb:43:in `initialize'
from /Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/xml-simple-1.1.2/lib/xmlsimple.rb:965:in `new'
from /Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/xml-simple-1.1.2/lib/xmlsimple.rb:965:in `parse'
from /Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/xml-simple-1.1.2/lib/xmlsimple.rb:164:in `xml_in'
from /Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/xml-simple-1.1.2/lib/xmlsimple.rb:203:in `xml_in'
from /Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/lastfm-1.19.0/lib/lastfm/response.rb:11:in `rescue in initialize'
from /Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/lastfm-1.19.0/lib/lastfm/response.rb:9:in `initialize'
from /Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/lastfm-1.19.0/lib/lastfm.rb:114:in `new'
from /Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/lastfm-1.19.0/lib/lastfm.rb:114:in `request'
from /Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/lastfm-1.19.0/lib/lastfm/method_category/base.rb:84:in `request'
from /Users/onemanstartup/.rvm/gems/ruby-2.0.0-p195/gems/lastfm-1.19.0/lib/lastfm/method_category/base.rb:46:in `block in __define_method'
from lastfm.rb:11:in `<main>'
It returns session key only, api has no methods that would return user's name by its session key.
To get name it is needed to modify existing method auth.getSession to return not only session key, but entire session info. But this likely would cause problems to existing gem users.
Hi Youpy,
Thank you for having pulled my recent upgrade! When do you plan to release it on rubygems? Indeed, the gem I'm developing now requires yours and I'd like to release it soon with the right dependency. No pressure, of course. ;-)
Thanks in advance.
Bye
Please have a look at this:
Lastfm.new(yourkey, yoursecret).album.get_info('Vemoth', 'The Upcoming End')
NoMethodError: undefined method `lstrip!' for {}:Hash
from /Users/kain/.rvm/gems/ruby-1.9.3-p125/bundler/gems/ruby-lastfm-33f2415100e3/lib/lastfm/method_category/album.rb:6:in `block in <class:Album>'
from /Users/kain/.rvm/gems/ruby-1.9.3-p125/bundler/gems/ruby-lastfm-33f2415100e3/lib/lastfm/method_category/base.rb:29:in `call'
from /Users/kain/.rvm/gems/ruby-1.9.3-p125/bundler/gems/ruby-lastfm-33f2415100e3/lib/lastfm/method_category/base.rb:29:in `block in __define_method'
from (irb):2
from /Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.3/lib/rails/commands/console.rb:47:in `start'
from /Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.3/lib/rails/commands/console.rb:8:in `start'
from /Users/kain/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.3/lib/rails/commands.rb:41:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
This happens because the releasedate is {}
:
lastfm.request('album.getInfo', { artist: 'Vemoth', album: 'The Upcoming End'})
=> #<Lastfm::Response:0x007fd5d1862460 @xml={"status"=>"ok", "album"=>{"name"=>"The Upcoming End", "artist"=>"Vemoth", "id"=>"75620491", "mbid"=>{}, "url"=>"http://www.last.fm/music/Vemoth/The+Upcoming+End", "releasedate"=>{}, "image"=>[{"size"=>"small", "content"=>"http://userserve-ak.last.fm/serve/34s/35151317.jpg"}, {"size"=>"medium", "content"=>"http://userserve-ak.last.fm/serve/64s/35151317.jpg"}, {"size"=>"large", "content"=>"http://userserve-ak.last.fm/serve/174s/35151317.jpg"}, {"size"=>"extralarge", "content"=>"http://userserve-ak.last.fm/serve/300x300/35151317.jpg"}, {"size"=>"mega", "content"=>"http://userserve-ak.last.fm/serve/_/35151317/The+Upcoming+End.jpg"}], "listeners"=>"242", "playcount"=>"4003", "tracks"=>{}, "toptags"=>{}}}>
Hi, when I try to get this album using your gem,
document = lastfm.album.get_info('artist':'Pepe Deluxé','album':'Queen of the Wave')
I get a result for the album but the tracks attribute is an empty array; while the album exists (with tracks) on Last.fm.
Any idea of why it does this ?
Could it be related to the accents ?
Thanks for the awesome work !
This is an issue to recover rubygems.org account
First of thanks for a awesome gem!
According to the official Last.fm API docs the user.getInfo method doesn't require a user parameter being passed along the call. If it's omitted it will default to the authenticated user. Therefor it would be great if the method would mimic this behaviour aswell.
If there is only one match
@lastfm.track.search(track: song.to_search_term)['results']['trackmatches']['track']
returns a hash but otherwise it returns an array. Is this intended?
Currently I hack around this fact by putting the resulting hash in an array if there only one match.
According to #30 you should be able to use the optional artist
parameter of track.search
. However, when I try it it makes no difference. For example
p lastfm.track.search(artist: 'Spacemen 3', track: 'Revolution')['results']['trackmatches']['track'].length
gives the same result as
p lastfm.track.search(track: 'Revolution')['results']['trackmatches']['track'].length
If the timestamp is older than 14+ days, then Last.fm doesn't accept scrobble, but track.scrobble returns True.
There is no such thing in the Last.fm API documentation, but its so.
The API response for such a track contains ignoredMessage Code 1
a lot of API links are broken on your documentation page...
Thanks for your code !
Lastfm.new(Settings.services.lastfm.api_key, Settings.services.lastfm.secret).track.get_correction('White Stripes', 'One More Cup of Coffee', 'wainekerr')
This uses the same data as in the spec, however it returns nil for me.
If instead we use a mispelt artist or track title, it raises:
Lastfm::ApiError: Supplied artist does not exist
from /Users/kain/.rvm/gems/ruby-1.9.3-p125/bundler/gems/ruby-lastfm-2242de096b1e/lib/lastfm.rb:96:in `request'
from /Users/kain/.rvm/gems/ruby-1.9.3-p125/bundler/gems/ruby-lastfm-2242de096b1e/lib/lastfm/method_category/base.rb:54:in `request'
from /Users/kain/.rvm/gems/ruby-1.9.3-p125/bundler/gems/ruby-lastfm-2242de096b1e/lib/lastfm/method_category/base.rb:29:in `block in __define_method'
I have no idea how to fix it myself, setting scrobble date manually solves the problem.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.