mirror of
https://github.com/danbee/mpd-client
synced 2025-03-04 08:39:09 +00:00
Add more song info. Add album info.
This commit is contained in:
parent
c9ca3de472
commit
abe7ad7626
@ -14,7 +14,7 @@ class MPDClient < Sinatra::Base
|
|||||||
end
|
end
|
||||||
|
|
||||||
get '/artists/:artist' do
|
get '/artists/:artist' do
|
||||||
JSON mpd.albums(CGI.unescape(params[:artist]))
|
JSON get_albums_by_artist(CGI.unescape(params[:artist]))
|
||||||
end
|
end
|
||||||
|
|
||||||
get '/albums/:album' do
|
get '/albums/:album' do
|
||||||
@ -33,11 +33,25 @@ class MPDClient < Sinatra::Base
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def get_albums_by_artist(artist)
|
||||||
|
mpd.albums(artist).map { |album| album_info(album) }.sort { |a, b| a[:year] <=> b[:year] }
|
||||||
|
end
|
||||||
|
|
||||||
def get_songs_by_album(album)
|
def get_songs_by_album(album)
|
||||||
mpd.search(:album, album).map do |song|
|
mpd.search(:album, album).map { |song| song_info(song) }
|
||||||
{ tracknumber: song.track,
|
end
|
||||||
title: song.title }
|
|
||||||
end
|
def song_info(song)
|
||||||
|
{ disc: song.disc,
|
||||||
|
track: song.track,
|
||||||
|
title: song.title }
|
||||||
|
end
|
||||||
|
|
||||||
|
def album_info(album)
|
||||||
|
first_song = mpd.search(:album, album).first
|
||||||
|
{ title: first_song.album,
|
||||||
|
genre: first_song.genre,
|
||||||
|
year: first_song.date }
|
||||||
end
|
end
|
||||||
|
|
||||||
def mpd
|
def mpd
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user