Module: CultomePlayer::Player::Interface::Extended
- Included in:
- CultomePlayer::Player::Interface
- Defined in:
- lib/cultome_player/player/interface/extended.rb
Instance Method Summary collapse
-
#connect(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
-
#disconnect(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
-
#enqueue(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
-
#fb(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
-
#ff(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
-
#repeat(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
-
#search(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
-
#show(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
-
#shuffle(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
Instance Method Details
#connect(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/cultome_player/player/interface/extended.rb', line 99 def connect(cmd) path = cmd.params(:path).first name = cmd.params(:literal).first if path.nil? # with only literal parameter raise 'invalid parameter:missing parameters' if name.nil? # es una reconexion... drive = Drive.find_by(name: name.value) raise 'invalid name:the named drive doesnt exists' if drive.nil? if drive.connected failure("What you mean? Drive 'name.value' is connected.") else if drive.update_attributes({connected: true}) success(message: "Drive '#{name.value}' was reconnected.") else failure("Something went wrong and I couldnt reconnect drive '#{name.value}'. Try again later please.") end end else # with path and literal parameter raise 'invalid path:the directory is invalid' unless Dir.exist?(path.value) raise 'invalid name:name required' if name.nil? # es una creacion o actualizacion... # checamos si la unidad existe root_path = File.(path.value) drive = Drive.find_by(path: root_path) # la creamos si no existe... is_update = !drive.nil? drive = Drive.create!(name: name.value, path: root_path) unless is_update track_info = get_files_in_tree(root_path, file_types).each_with_object([]) do |filepath, acc| acc << extract_from_mp3(filepath, library_path: root_path) end # insertamos las nuevas y actualizamos las existentes updated = update_song(track_info) imported = insert_song(track_info) success(message: connect_response_msg(imported, updated), files_detected: track_info.size, files_imported: imported, files_updated: updated, drive_updated: is_update) end end |
#disconnect(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/cultome_player/player/interface/extended.rb', line 150 def disconnect(cmd) name = cmd.params(:literal).first.value drive = Drive.find_by(name: name) raise "Drive '#{name}' dont exist." if drive.nil? if drive.connected if drive.update(connected: false) success(message: "Drive '#{name}' is now disconnected.") else failure("I cant disconnect drive '#{name}', something weird happened. Maybe if you again later works.") end else failure("The drive '#{name}' is already disconnected.") end end |
#enqueue(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cultome_player/player/interface/extended.rb', line 70 def enqueue(cmd) songs = select_songs_with cmd if songs.empty? failure("No songs found with this criteria. Sorry, nothing was enqueued.") else playlists[:queue] << songs msg = "These songs were enqueued:\n" songs.each {|s,idx| msg << " #{s.to_s}\n"} success(message: msg, enqueued: songs) end end |
#fb(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/cultome_player/player/interface/extended.rb', line 180 def fb(cmd) fb_in_secs = 10 unless cmd.params(:number).empty? fb_in_secs = cmd.params(:number).first.value end fb_in_player fb_in_secs return success(message: "Fast Backwarded by #{fb_in_secs} secs") end |
#ff(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/cultome_player/player/interface/extended.rb', line 167 def ff(cmd) ff_in_secs = 10 unless cmd.params(:number).empty? ff_in_secs = cmd.params(:number).first.value end ff_in_player ff_in_secs return success(message: "Fast Forwarded by #{ff_in_secs} secs") end |
#repeat(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
193 194 195 196 |
# File 'lib/cultome_player/player/interface/extended.rb', line 193 def repeat(cmd) repeat_in_player return success(message: "Repeating " + current_song.to_s) end |
#search(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/cultome_player/player/interface/extended.rb', line 6 def search(cmd) songs = select_songs_with cmd if songs.empty? failure('It matches not even one') else playlists[:focus] <= songs success(songs: songs, response_type: :songs) end end |
#show(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cultome_player/player/interface/extended.rb', line 18 def show(cmd) if cmd.params.empty? if #mostramos la cancion actual msg = (playback_position, playback_length, 20, format_secs(playback_position), format_secs(playback_length)) return success(message: "#{current_song.to_s}\n#{msg}", song: current_song) else return failure("Nothing to show yet. Try with 'play' first.") end # with parameters else list_to_show = cmd.params(:object).reduce([]) do |acc, p| acc + case p.value when :playlist then current_playlist.to_a when :current then playlists[:current].to_a when :history then playlists[:history].to_a when :queue then playlists[:queue].to_a when :focus then playlists[:focus].to_a when :search then playlists[:search].to_a when :song then return success(message: current_song.to_s, song: current_song) when :artist then return success(message: current_artist.to_s, artist: current_song) when :album then return success(message: current_album.to_s, album: current_song) when :drives then Drive.all when :artists then return Artist.all when :albums then return Album.all when :genres then return Genre.all when :library then whole_library.to_a when :recently_added then [] # TODO implement when :recently_played then [] # TODO implement when :more_played then [] # TODO implement when :less_played then [] # TODO implement when :populars then [] # TODO implement else [] end end if list_to_show.empty? return failure("I checked and there is nothing there.") else playlists[:focus] <= list_to_show return success(list: list_to_show, response_type: :list) end end end |
#shuffle(cmd) ⇒ Object
For more information on this command refer to user manual or inline help in interactive mode.
84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/cultome_player/player/interface/extended.rb', line 84 def shuffle(cmd) if cmd.params.empty? if playlists[:current].shuffling? return success(message: "Everyday I'm shuffling!", shuffling: true) else return success(message: "No shuffling", shuffling: false) end else turn_on = cmd.params(:boolean).first.value turn_on ? playlists[:current].shuffle : playlists[:current].order return success(message: turn_on ? "Now we're shuffling!" : "Shuffle is now off") end end |