Skip to content

labzero/mopidy

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

57 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mopidy Travis Coveralls Hex.pm Deps Status Inline docs

A Mopidy client library for Elixir.

Installation

Add mopidy to your list of dependencies in mix.exs:

def deps do
  [{:mopidy, "~> 0.3.0"}]
end

Ensure mopidy is started before your application:

def application do
  [applications: [:mopidy]]
end

Within your application you will need to configure the Mopidy API URL. You do not want to put this information in your config.exs file! Either put it in a {prod,dev,test}.secret.exs file which is sourced by config.exs, or read the values in from the environment:

config :mopidy,
  api_url: System.get_env("MOPIDY_API_URL")

If you want to be able to receive events via websockets you will also need to set websocket_api_url

Usage

The online documentation for the Mopidy HTTP API will give you a general idea of the modules and available functionality. Where possible the namespacing has been matched.

iex> {:ok, search_results} = Mopidy.Library.search(%{artist: "radiohead"}, ["spotify:"])
iex> search_results.artists
[%Mopidy.Artist{__model__: "Artist",
  name: "Radiohead Tribute Band",
  uri: "spotify:artist:0ADkBHZhR2cVfANgK5gHQO"},
 %Mopidy.Artist{__model__: "Artist", name: "Radiohead",
  uri: "spotify:artist:4Z8W4fKeB5YxbusRsdQVPb"}]

To receive events:

iex> Mopidy.Events.create_stream |> Enum.each(&IO.inspect/1)
{:ok,
 %{"event" => "playback_state_changed", "new_state" => "playing",
   "old_state" => "paused"}}
{:ok,
 %{event: "track_playback_resumed", time_position: 1819,
   tl_track: %Mopidy.TlTrack{__model__: "TlTrack", tlid: 658,
    track: %Mopidy.Track{__model__: "Track",
     album: %Mopidy.Album{__model__: "Album",
      name: "It'll End In Tears (Remastered)",
      uri: "spotify:album:6D6C7jGsJdzJpcEaMcxswR"},
     artists: [%Mopidy.Artist{__model__: "Artist", name: "This Mortal Coil",
       uri: "spotify:artist:5OK8j1JnhoBlivN32G7yOO"}],
     name: "Song To The Siren (Remastered)",
     uri: "spotify:track:0BPTTsnnfz44XmZn3EE0oo"}}}}

License

MIT License, see LICENSE for details.

About

A Mopidy client library for Elixir

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Elixir 100.0%