Module: CultomePlayer::Player::Interface::Extended

Includes:
Objects, Helper
Included in:
CultomePlayer::Player::Interface
Defined in:
lib/cultome_player/player/interface/extended.rb

Constant Summary

Constants included from Helper

Helper::VALID_SONG_ATTR

Instance Method Summary collapse

Methods included from Helper

#connect_response_msg, #format_secs, #get_files_in_tree, #get_from_playlists, #get_progress_bar, #get_progress_bar_with_labels, #insert_song, #play_inline?, #play_queue, #player_object, #process_for_search, #search_songs_with, #select_songs_with, #update_song, #whole_library

Instance Method Details

#connect(cmd) ⇒ Object

For more information on this command refer to user manual or inline help in interactive mode.



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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/cultome_player/player/interface/extended.rb', line 112

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.expand_path(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)
    display "" # para insertar un salto de linea despues de las barras de progreso

    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.



164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
# File 'lib/cultome_player/player/interface/extended.rb', line 164

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.



83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/cultome_player/player/interface/extended.rb', line 83

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.



194
195
196
197
198
199
200
201
202
203
204
# File 'lib/cultome_player/player/interface/extended.rb', line 194

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.



181
182
183
184
185
186
187
188
189
190
191
# File 'lib/cultome_player/player/interface/extended.rb', line 181

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.



207
208
209
210
# File 'lib/cultome_player/player/interface/extended.rb', line 207

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.



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/cultome_player/player/interface/extended.rb', line 10

def search(cmd)
  songs = select_songs_with cmd

  if songs.empty?
    failure('It matches not even one')
  else
    playlists[:focus] <= songs
    playlists[:search] <= 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.



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
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/cultome_player/player/interface/extended.rb', line 23

def show(cmd)
  if cmd.params.empty?
    if playing?
      #mostramos la cancion actual
      progress_bar = get_progress_bar_with_labels(playback_position, playback_length, 20, format_secs(playback_position), format_secs(playback_length))
      return success(message: "#{current_song.to_s}\n#{c7(progress_bar)}", 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_artist)
        when :album then return success(message: current_album.to_s, album: current_album)
        when :genre then return success(message: current_song.genres.map{|g| g.name}.join(", "), genres: current_song.genres)

        when :drives then Drive.all
        when :artists then Artist.all
        when :albums then Album.all
        when :genres then Genre.all

        when :library then whole_library.to_a

        when :recently_added then
          low_time, high_time = get_recently_added_criteria_limit
          Song.where({created_at: low_time..high_time}).to_a

        when :recently_played then
          low_time, high_time = get_recently_played_criteria_limit
          Song.where({last_played_at: low_time..high_time}).to_a

        when :most_played then Song.where("plays >= ?", get_most_played_criteria_limit).to_a
        when :less_played then Song.where("plays <= ?",  get_less_played_criteria_limit).to_a
        when :populars then
          low_time, up_time, low_count = get_popular_criteria_limits
          Song.where("last_played_at between ? and ? and plays >= ?", low_time, up_time, low_count)
        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.



97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/cultome_player/player/interface/extended.rb', line 97

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