• This repository has been archived on 09/Dec/2022
  • Stars
    star
    147
  • Rank 251,347 (Top 5 %)
  • Language
    C++
  • License
    Other
  • Created over 13 years ago
  • Updated over 9 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Low-level Ruby bindings for libspotify, the official Spotify C API

Low-level Ruby bindings for libspotify, the official Spotify C API

Build Status Dependency Status Code Climate Gem Version

Caution: libspotify in its current form has been deprecated: https://developer.spotify.com/news-stories/2015/05/26/last-month-news/

The libspotify C API package allows third party developers to write
applications that utilize the Spotify music streaming service.

Spotify is a really nice music streaming service, and being able to interact with it in an API is awesome. libspotify itself is however written in C, making it unavailable or cumbersome to use for many developers.

This project aims to allow Ruby developers access to all of the libspotify C API, without needing to reach down to C. However, to use this library to its full extent you will need to learn how to use the Ruby FFI API.

The Spotify gem has:

Contact details

Questions, notes and answers

Links to keep close at hand when using libspotify

How to run the examples

You’ll need:

  1. Your Spotify premium account credentials. If you sign in with Facebook, you’ll need your Facebook account e-mail and password.
  2. Your Spotify application key. Download the binary key, and put it in the examples/ directory.

Running the examples is as simple as:

ruby example-audio_stream.rb

Available examples are:

  • example-audio_stream.rb: plays songs from Spotify with the plaything gem, using OpenAL.
  • example-console.rb: logs in to Spotfify, and initiates a pry session to allow experimentation with the spotify gem API.
  • example-listing_playlists.rb: list all playlists available for a certain user.
  • example-loading_object.rb: loads a track using polling and the spotify gem API.
  • example-random_related_artists.rb: looks up an artist and its similar artists on spotify, then it picks a similar artist at random and does the same to that artist, over and over. I have used this example file to test prolonged usage of the API.

Creating a Session, the first thing you should do

Almost all functions require you to have created a session before calling them. Forgetting to do so won’t work at best, and will segfault at worst. You'll also want to log in before doing things as well, or objects will never load.

See Spotify::API#session_create for how to create a session. See Spotify::API#session_login for logging in.

libspotify is an asynchronous library

When creating objects in libspotify they are not populated with data instantly, instead libspotify schedules them for download from the Spotify backend. For libspotify to do it's work with downloading content, you need to call Spotify::API#session_process_events regularly.

Facebook vs Spotify Classic

Users who signed up to Spotify with their Facebook account will have numeric IDs as usernames, so a link to their profile looks like spotify:user:11101648092. Spotify Classic users instead have their usernames as canonical name, so a link to their profile looks like spotify:user:burgestrand.

This matters, for example, when you use the function Spotify::API#session_publishedcontainer_for_user_create.

Callbacks can be dangerous

libspotify allows you to pass callbacks that will be invoked by libspotify when events of interest occur, such as being logged out, or receiving audio data when playing a track.

Callbacks can be very tricky. They must never be garbage collected while they are in use by libspotify, or you may get very weird bugs with your Ruby interpreter randomly crashing. Do use them, but be careful.

Opinions and the Spotify gem

The Spotify gem has very few opinions. It is build to closely resemble the libspotify C API, and has very little to aid you in terms of how to structure your application. It aims to make calling the libspotify C API frictionless, but not much more. It is up to you to decide your own path.

A note about gem versioning

Given a version X.Y.Z, each segment corresponds to:

  • X reflects supported libspotify version (12.1.45 => 12). There are no guarantees of backwards-compatibility!
  • Y is for backwards-incompatible changes.
  • Z is for backwards-compatible changes.

You should use the following version constraint: gem "spotify", "~> 12.5.3".

Manually installing libspotify

By default, Spotify uses the libspotify gem which means you do not need to install libspotify yourself. However, if your platform is not supported by the libspotify gem you will need to install libspotify yourself.

Please note, that if your platform is not supported by the libspotify gem I’d very much appreciate it if you could create an issue on libspotify gem issue tracker so I can fix the build for your platform.

Instructions on installing libspotify manually are in the wiki: How to install libspotify

More Repositories

1

Hallon

Hallon is currently **UNMAINTAINED**.
Ruby
135
star
2

hue-api

A fork of GitHub API v3, to describe the Philips Hue API.
Ruby
65
star
3

ruhue

Experimenting with the Philips Hue, documenting my progress.
Ruby
26
star
4

Library-of-Massive-Fun-And-Overjoy

Ruby bindings for a fictional C library
C
12
star
5

em-throttled_queue

A rate-limited Queue for EventMachine
Ruby
11
star
6

Dimma

A ruby library for the Beacon push REST API
Ruby
9
star
7

hallon-openal

An OpenAL audio driver for Hallon
C
9
star
8

hallon-heroku

An example Sinatra application showing how to get Hallon to work on Heroku.
Ruby
8
star
9

Funcy

A set of functionally useful functions for functional functional programming in PHP.
PHP
7
star
10

libspotify

Binary distribution for libspotify.
Ruby
6
star
11

plaything

Ruby
6
star
12

kotwig

Kohana v3 module for the Twig project
PHP
5
star
13

mellon

Speak, Friend, and enter.
Ruby
5
star
14

phplibs

A collection of clever and useful PHP snippets
PHP
4
star
15

vlad-nginx

NGiNX recipe for Vlad the Deployer
Ruby
2
star
16

kogitlog

a simple Git changelog for Kohana v3 based on glip
PHP
2
star
17

swift-hub

An statically typed event hub built on Swift generics and Apple's NotificationCenter.
Swift
2
star
18

twitterskylt

Projektsida för kandidatarbetet “Twitterskylt”.
C
2
star
19

functran

ƒunc(tran) website source code
2
star
20

milo-web-preview

A web-based tool to experiment with color choices of the 3D printed parts for the Milo CNC.
TypeScript
2
star
21

blox

Blox helps you write Ruby methods that accept multiple blocks
Ruby
1
star
22

STHLM-Swift-GraphQL

1
star
23

rails_wipe

Ruby
1
star
24

sinatra-base

Playing with Sinatra from time to time, I tend to do the setup in the same way.
Ruby
1
star
25

koxtend

A Kohana submodule providing some files I regularly use in all my projects
PHP
1
star
26

rack-json

A Rack middleware for turning responses into JSON
Ruby
1
star
27

livereload_rails

Easy livereloading for Rails 4+.
Ruby
1
star
28

burgestrand.github.io

CSS
1
star
29

couchrest-from_path

Adds a CouchRest::Document.from_path method
Ruby
1
star
30

vanilla-deploy

An example of a deployment system using CoffeeScript, SASS, Jammit, Vlad the Deployer and Git
Ruby
1
star