Mopidy

A lightweight wrapper around the Mopidy music server API.

Installation

Add this line to your application's Gemfile:

gem 'mopidy'

And then execute:

$ bundle

Or install it yourself as:

$ gem install mopidy

Usage

The gem is divided into modules that reflect the controllers in the Mopidy core API. Currently, the supported modules are Library, Playback, Playlist, and Tracklist.

Configuration

To configure the url that the gem makes requests to:

Mopidy.configure do |config|
  config.mopidy_url = 'http://localhost:6680/mopidy/rpc' # This is the default
end

Tracklist

This is the module that interfaces with Mopidy's tracklist controller

To get the tracks in the tracklist:

Mopidy::Tracklist.tracks

To get the index of the currently playing track:

Mopidy::Tracklist.index

To get the tracks in the tracklist as TLTRacks

Mopidy::Tracklist.tl_tracks

To add a track to the tracklist:

Mopidy::Tracklist.add(uri: 'example-track-uri')

To get the length of the tracklist:

Mopidy::Tracklist.length

To clear the tracks from the tracklist:

Mopidy::Tracklist.clear

Library

This is the module that interfaces with Mopidy's Library controller

To search for tracks, artists, playlists, and albums using a keyword:

Mopidy::Library.search('queen')

To search for tracks by artist, album, or track:

Mopidy::Library.search_tracks('bicycle')

To lookup a track by it's uri:

Mopidy::Library.lookup('example-uri')

Playlist

This is the module that interfaces with Mopidy's Playlist controller

To get a list of playlists:

Mopidy::Playlist.as_list

To lookup a playlist by it's uri

Mopidy::Playlist.lookup('playlist-uri')

Playback

This is the module that interfaces with Mopidy's Playback controller

To play:

Mopidy::Playback.play

To pause:

Mopidy::Playback.pause

To resume:

Mopidy::Playback.resume

To stop:

Mopidy::Playback.stop

To get the playback state:

Mopidy::Playback.state

To get the current time position:

Mopidy::Playback.time_position

To seek to a time position:

time_position = 1000 # Time position in milliseconds
Mopidy::Playback.seek(time_position)

To get the currently playing track:

Mopidy::Playback.current_track

To skip to the next track:

Mopidy::Playback.next

Mixer

To get the current volume

Mopidy::Mixer.volume.body # => 100

To set the volume to 50

Mopidy::Mixer.volume(50)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/khisakuni/mopidy.

License

The gem is available as open source under the terms of the MIT License.