Categories
Programming

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

8 replies on “Använda Spotify MetaData API i Ruby”

Verkar ju sjukt enkelt det där.. Sj så ska jag väl börja ta tag i RoR lite, gäller bara å få tid..

Hello ,
I’m Angelina.
If you’ve ever been too busy and couldn’t finish a academic paper, then you’ve come to the right place. I work with students in all areas of the writing steps . I can also write the assignment from start to finish.
My career as a professional writer started during high school. After learning that I was very able in the field of academic writing, I decided to take it up as a job .

Talented Academic Writer- Angelina- How to Teach Students to Write an Essay Band

I’m an expert writer who loves to bring smiles to people’s face.

Writing is what I do for a living and I am so passionate about this. I have worked with several organizations whose mission is to help people solve writing problems.
I love traveling and have visited several places in the past few years.
I’m happy to have written several books that have contributed positively to the lives of many. My works are available in several parts of the world. And I’m currently working with companies that help people save time. Being a part of this team has open more opportunities for me to excel as a writer. I have worked with different people and met many clients as a professional.
I can handle any kind of writing and provide nothing but the best. People come to me all the time to ask if I can solve their assignment problems and I accept. I find pleasure in helping them to solve their problems as a writer.

Professional Academic Writer – Jeanne – http://www.thunderbirdresearch.org Corp

Hi guys, my name is Mohammod Clayton!

I`m a professional writer and I`m going to change your lifes onсe and for all
Writing has been my passion since early childhood and now I cannot imagine my life without it.
Most of my books were sold throughout Canada, USA, Old England and even Australia. Also I`m working with services that help people to save their time.
People ask me “Hey, Mohammod, I need your professional help” and I always accept the request, `cause I know, that only I can save their time!

Professional Academic Writer – Mohammod – http://www.studentsmeet.org Corps

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.