module CultomePlayer::Plugins::Gestures
Public Instance Methods
init_plugin_gestures()
click to toggle source
# File lib/cultome_player/plugins/gestures.rb, line 7 def init_plugin_gestures register_listener(:after_command){|cmd, res| check_gesture(cmd) } end
Private Instance Methods
actions_history()
click to toggle source
# File lib/cultome_player/plugins/gestures.rb, line 13 def actions_history @history ||= [] end
check_gesture(cmd)
click to toggle source
# File lib/cultome_player/plugins/gestures.rb, line 17 def check_gesture(cmd) if cmd.history? actions_history << [cmd, Time.new] check_looking_for_something end end
check_looking_for_something()
click to toggle source
# File lib/cultome_player/plugins/gestures.rb, line 28 def check_looking_for_something if recents(60).count{|cmd, time| cmd.action == "next"} >= 5 delete_from_history "next" suggest_songs end end
delete_from_history(cmd)
click to toggle source
# File lib/cultome_player/plugins/gestures.rb, line 35 def delete_from_history(cmd) actions_history.delete_if {|cmd, time| cmd.action == "next"} end
get_suggestions()
click to toggle source
# File lib/cultome_player/plugins/gestures.rb, line 51 def get_suggestions id = select_suggestion if (1..7).cover?(id) criteria = case id when 1 # los que tienen mas puntos "points desc" when 2 # los que tienen menos puntos "points" when 3 # las mas tocadas "plays desc" when 4 # los menos tocados "plays" when 5 # los agregados recientemente "created_at desc" when 6 # los recientemente tocados "last_played_at" when 7 # los recientemente tocados "points desc, plays desc" end return Song.order(criteria).limit(5).to_a else # mas complejos case (id) when 8 # Por artista popular artist = Artist.order("points desc").limit(5).sample(1).first return [] if artist.nil? return artist.songs.sample(5) when 9 # Por album popular album = Album.order("points desc").limit(5).sample(1).first return [] if album.nil? return album.songs.sample(5) else return Song.all.sample(5) end end end
recents(secs)
click to toggle source
# File lib/cultome_player/plugins/gestures.rb, line 24 def recents(secs) return actions_history.select{|cmd, time| time >= Time.new - secs} end
select_suggestion()
click to toggle source
# File lib/cultome_player/plugins/gestures.rb, line 47 def select_suggestion return (1..10).to_a.sample(1).first end
suggest_songs()
click to toggle source
# File lib/cultome_player/plugins/gestures.rb, line 39 def suggest_songs display "Hey! cant find anything? Try one of these:" suggestions = get_suggestions display to_display_list(suggestions) playlists[:focus] <= suggestions return suggestions end