From d9eacbda3c5bc3b6d3a7c15f8c47a0657ef7e683 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 14 Dec 2015 02:11:11 +0000 Subject: player: show "tracklist" hash with summary info with "current" This allows clients to quickly query tracklist size/position/shuffle/random info. --- lib/dtas/player/client_handler.rb | 1 + lib/dtas/tracklist.rb | 13 +++++++++---- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'lib/dtas') diff --git a/lib/dtas/player/client_handler.rb b/lib/dtas/player/client_handler.rb index 17cd6c3..a27e4f5 100644 --- a/lib/dtas/player/client_handler.rb +++ b/lib/dtas/player/client_handler.rb @@ -312,6 +312,7 @@ module DTAS::Player::ClientHandler # :nodoc: h end end + tmp['tracklist'] = @tl.to_hsh(false) io.emit(tmp.to_yaml) end diff --git a/lib/dtas/tracklist.rb b/lib/dtas/tracklist.rb index 7366799..726a46a 100644 --- a/lib/dtas/tracklist.rb +++ b/lib/dtas/tracklist.rb @@ -13,7 +13,6 @@ class DTAS::Tracklist # :nodoc: attr_accessor :max # integer TL_DEFAULTS = { - 'list' => [], 'pos' => -1, 'repeat' => false, 'max' => 20_000, @@ -24,7 +23,7 @@ class DTAS::Tracklist # :nodoc: obj = new obj.instance_eval do list = hash['list'] and @list.replace(list.map { |s| new_track(s) }) - %w(pos repeat max).each do |k| + SIVS.each do |k| instance_variable_set("@#{k}", hash[k] || TL_DEFAULTS[k]) end @@ -39,10 +38,16 @@ class DTAS::Tracklist # :nodoc: obj end - def to_hsh + def to_hsh(full_list = true) h = ivars_to_hash(SIVS) h.delete_if { |k,v| TL_DEFAULTS[k] == v } - list = h['list'] and h['list'] = list.map(&:to_path) + unless @list.empty? + if full_list + h['list'] = @list.map(&:to_path) + else + h['size'] = @list.size + end + end if @shuffle h['shuffle'] = true h['pos'] = _idx_of(@list, @shuffle[@pos].track_id) if @pos >= 0 -- cgit v1.2.3-24-ge0c7