Använda Spotify MetaData API i Ruby

Spotify har släppt ett API för att kunna hämta information om låtar via deras Spotify-url:er. Nedan är ett exempel i Ruby på hur du kan hämta artist och låt. Anropas med ex. spotify:track:4KPU7XGqxo4UlMp3is7NBI

def getTitleFromSpotifyTrack(trackID)
    require 'net/http'
    require 'rexml/document'
    require 'rexml/xpath'

    res = Net::HTTP.get_response(URI.parse("http://ws.spotify.com/lookup/1/?uri=#{trackID}"))
    contents = res.body

    doc = REXML::Document.new contents

    track = REXML::XPath.first(doc,'/track/name/text()')
    artist = REXML::XPath.first(doc,'/track/artist/name/text()')

    return "#{artist} - #{track}"
  end

15 thoughts on “Använda Spotify MetaData API i Ruby”

    1. [Maybe it wouldnt be shocking if you picked up a history book Tony. progressives are equal opprotunists.]“Equal Opportunity” means all individuals have a chance to compete on their own abilities and merits, not having the system gamed to support one group or the other.[Do your research on 209 and youd find that the only group that openly supported the proposition was the KKK. seriously.]You lie. Seriously.

    2. Liebe Joanna,eine so tolle Idee mit dem Häkeldeckchen. Das sieht einfach wunderschön aus! Überhaupt mal wieder so stimmungsvolle Fotos! Ganz liebe Grüße aus Oslo Alice

    3. 182Oi Paula, parabéns pelo post! Leio teu blog desde o começo, e essa por incrível que pareça é a primeira vez que comento. Gosto muito do que tu escreve, não só pelo conteúdo, mas pela pessoa sincera que tu és.É um orgulho ter uma blogueira gaúcha, e ainda mais do interior se destacando!Parabéns mesmo.Beijo

    4. darkness is one thing i’m afraid of if the army ever sends us to alaska. i’m a so cal girl, and the sun and i are incredibly good friends. i start to shut down when i don’t see the sun. i honestly don’t know how people in alaska do it.

  1. Lisa, tack för det inlägget. Jag behövde det mitt i min självömkan.Om tidningarna: det kallas nyhetstorka. Inga dokusÃ¥pestjärnor har gjort nÃ¥got, dÃ¥ skrivs det om dold sjukdom. Eller alternativet ”sÃ¥ farlig är din medicin – vi har hela listan”. Eller ”de tjänar mest i din kommun”.

  2. I love girl trips. I don’t think it even really matters what the destination or activity is. I go a couple times a year with my good friend, and we work like dogs, but the company and the road trip (though much shorter than one to Denver) is great! I think getting away now and then, even if it’s work, is a good thing for anyone.

  3. Hey Nina, I’m with you here.Roger as gajustme and Dawn have mentioned please use gloves if you are going to continue this you are definately spreading infection over other open sores, which will continue to get infected, this will never heal, and could potentially cause you some major health issues in the future.As much as I appreciate your posting yourself here at PTZ,I also want you to be healthy, keep good care of yourself.Puss

  4. “The only normal people are the one’s you don’t know very well.”I like that one. Oh, and the sex one. This is one of my favorite posts so far. I love quotes. And I love the fact that you included pictures to go along with. It would be cool if you did a post on how you got into this field. The process or journey of discovering what it was you wanted to do in life. Or else if you don’t want to get personal on the posts then I would like to know how you got into psychology (sp).Anna

  5. I know!I think a lot of it is the sexualisation of breasts through the page 3 phenomena.I’m glad my daughter has had exposure to breast feeding and hopefully she will continue to see it as completely normal.

Leave a Reply

Your email address will not be published. Required fields are marked *