mirror of
https://github.com/danbee/mpd-client
synced 2025-03-04 08:39:09 +00:00
Now list artists, albums and songs.
This commit is contained in:
parent
5767f5efe8
commit
c9ca3de472
1
Gemfile
1
Gemfile
@ -1,6 +1,7 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem 'sinatra'
|
||||
gem 'sinatra-contrib'
|
||||
gem 'foreman'
|
||||
|
||||
gem 'ruby-mpd'
|
||||
|
||||
12
Gemfile.lock
12
Gemfile.lock
@ -1,15 +1,19 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
backports (3.3.3)
|
||||
daemons (1.1.9)
|
||||
dotenv (0.8.0)
|
||||
eventmachine (1.0.3)
|
||||
foreman (0.63.0)
|
||||
dotenv (>= 0.7)
|
||||
thor (>= 0.13.6)
|
||||
multi_json (1.7.9)
|
||||
rack (1.5.2)
|
||||
rack-protection (1.5.0)
|
||||
rack
|
||||
rack-test (0.6.2)
|
||||
rack (>= 1.0)
|
||||
ruby-mpd (0.2.4)
|
||||
shotgun (0.9)
|
||||
rack (>= 1.0)
|
||||
@ -17,6 +21,13 @@ GEM
|
||||
rack (~> 1.4)
|
||||
rack-protection (~> 1.4)
|
||||
tilt (~> 1.3, >= 1.3.4)
|
||||
sinatra-contrib (1.4.1)
|
||||
backports (>= 2.0)
|
||||
multi_json
|
||||
rack-protection
|
||||
rack-test
|
||||
sinatra (~> 1.4.0)
|
||||
tilt (~> 1.3)
|
||||
thin (1.5.1)
|
||||
daemons (>= 1.0.9)
|
||||
eventmachine (>= 0.12.6)
|
||||
@ -32,4 +43,5 @@ DEPENDENCIES
|
||||
ruby-mpd
|
||||
shotgun
|
||||
sinatra
|
||||
sinatra-contrib
|
||||
thin
|
||||
|
||||
@ -1,14 +1,49 @@
|
||||
require 'sinatra'
|
||||
require "sinatra/namespace"
|
||||
require 'json'
|
||||
require 'ruby-mpd'
|
||||
require 'cgi'
|
||||
|
||||
class MPDClient < Sinatra::Base
|
||||
before do
|
||||
@mpd = MPD.new
|
||||
@mpd.connect
|
||||
register Sinatra::Namespace
|
||||
|
||||
namespace '/api' do
|
||||
|
||||
get '/albums' do
|
||||
JSON mpd.albums
|
||||
end
|
||||
|
||||
get '/artists/:artist' do
|
||||
JSON mpd.albums(CGI.unescape(params[:artist]))
|
||||
end
|
||||
|
||||
get '/albums/:album' do
|
||||
JSON get_songs_by_album(CGI.unescape(params[:album]))
|
||||
end
|
||||
|
||||
get '/artists/:artist/:album' do
|
||||
JSON get_songs_by_album(CGI.unescape(params[:album]))
|
||||
end
|
||||
|
||||
get '/artists' do
|
||||
JSON mpd.artists
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
get '/api/albums' do
|
||||
@mpd.albums
|
||||
private
|
||||
|
||||
def get_songs_by_album(album)
|
||||
mpd.search(:album, album).map do |song|
|
||||
{ tracknumber: song.track,
|
||||
title: song.title }
|
||||
end
|
||||
end
|
||||
|
||||
def mpd
|
||||
@mpd ||= MPD.new
|
||||
@mpd.connect unless @mpd.connected?
|
||||
@mpd
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user