Module: Fargo::CLI::Downloads

Included in:
Console
Defined in:
lib/fargo/cli/downloads.rb

Instance Method Summary collapse

Instance Method Details

#download(index, search = nil) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/fargo/cli/downloads.rb', line 24

def download index, search = nil
  search ||= client.searches[0]

  if search.nil?
    puts "Nothing to download!"
    return
  end

  item = client.search_results(search)[index]

  if item.nil?
    puts 'That is not something to download!'
  else
    client.download item[:nick], item[:file], item[:tth], item[:size]
  end
end

#setup_consoleObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/fargo/cli/downloads.rb', line 5

def setup_console
  super

  add_completion(/^(download|get)\s+\d+,\s*[^\s]*$/) do
    client.searches
  end

  add_logger(:download_started) do |message|
    "Download of #{message[:download][:file]} " +
    "(#{humanize_bytes message[:length]}) " +
    "from #{message[:nick]} started"
  end

  add_logger(:download_finished) do |message|
    "Download of #{message[:download][:file]} " +
    "finished into #{message[:file]}"
  end
end

#transfersObject



41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/fargo/cli/downloads.rb', line 41

def transfers
  max_nick = client.current_downloads.keys.map(&:size).max
  client.current_downloads.each_pair do |nick, download|
    printf "%#{max_nick}s %10s (%.2f%%) -- %s\n", nick,
      humanize_bytes(download.size), 100 * download.percent,
      download.file
  end

  puts "Upload slots avail: " +
    "#{client.open_upload_slots}/#{client.config.upload_slots}  " +
    "Download slots avail: " +
    "#{client.open_download_slots}/#{client.config.download_slots}"
end