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::Playlist.play
To pause:
Mopidy::Playlist.pause
To resume:
Mopidy::Playlist.resume
To stop:
Mopidy::Playlist.stop
To get the playback state:
Mopidy::Playlist.state
To get the current time position:
Mopidy::Playlist.time_position
To seek to a time position:
time_position = 1000 # Time position in milliseconds
Mopidy::Playlist.seek(time_position)
To get the currently playing track:
Mopidy::Playlist.current_track
To skip to the next track:
Mopidy::Playlist.next
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.