Module: Quiyo::Status

Included in:
Quiyo
Defined in:
lib/quiyo/status.rb

Instance Method Summary collapse

Instance Method Details

#_print(key, value) ⇒ Object



19
20
21
22
23
24
# File 'lib/quiyo/status.rb', line 19

def _print(key, value)
  print "%-20s %s\n" % [
                        colorize(key.capitalize + ":", CONF["colors"]["info_key"]),
                        colorize(value,                CONF["colors"]["info_value"])
                       ]
end

#infoObject



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
# File 'lib/quiyo/status.rb', line 18

def info
  def _print(key, value)
    print "%-20s %s\n" % [
                          colorize(key.capitalize + ":", CONF["colors"]["info_key"]),
                          colorize(value,                CONF["colors"]["info_value"])
                         ]
  end

  s = @mpd.status
  sid = @mpd.song_with_id(s[:songid])

  # Get current song
  %w{artist title album date file}.each { |k|
    _print(k, sid[k])
  }
  _print "DURATION", time(sid["time"])
  print colorize(CONF["separator"], CONF["colors"]["separator"]), "\n"

  # Get MPD Status
  %w{volume repeat random playlistlength xfade}.each { |k|
    _print(k, s[k])
  }
  print colorize(CONF["separator"], CONF["colors"]["separator"]), "\n"

  s = @mpd.stats

  # Get MPD Stats
  %w{artists albums songs}.each { |k| 
    _print(k, s[k])
  }
  print colorize(CONF["separator"], CONF["colors"]["separator"]), "\n"

  # Get MPD Times
  %w{uptime playtime db_playtime}.each { |k,v|
    _print(k, time(s[k]))
  }
end

#nowplayingObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/quiyo/status.rb', line 3

def nowplaying
  song = @mpd.current_song
  print "%s by %s on %s [%s]\n" % [
                                   colorize(song["title"],  CONF["colors"]["title"]),
                                   colorize(song["artist"], CONF["colors"]["artist"]),
                                   colorize(song["album"],  CONF["colors"]["album"]),
                                   colorize(song["date"],   CONF["colors"]["year"])
                                  ]
rescue
  print "%s playing right now, stoopid %s\n" % [
                                                colorize("Nothing", CONF["colors"]["error"]),
                                                colorize(":(",      CONF["colors"]["smiley_frown"])
                                               ]
end

#promptObject



69
70
71
72
73
74
75
76
77
78
# File 'lib/quiyo/status.rb', line 69

def prompt
  return CONF["prompt"]
    .gsub(/%(\d+)/, "\001\e[38;5;\\1m\002")
    .gsub("%n", "\001\e[0m\002")
    .gsub("$state", @mpd.status["state"])
    .gsub("$flags",
          (@mpd.status["repeat"] == "1" ? "r" : "") +
          (@mpd.status["random"] == "1" ? "z" : "") +
          (@mpd.status["xfade"] != "0" ? "x" : "")) + " "
end

#time(sec) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/quiyo/status.rb', line 56

def time(sec)
  string = ""
  time = sec.to_i
  days = (time/86400)
  hours = (time/3600 - days * 24)
  minutes = (time/60 - (hours * 60 + days * 1440))
  seconds = (time - (minutes * 60 + hours * 3600 + days * 86400))
  { "d" => days, "h" => hours, "m" => minutes, "s" => seconds}.each { |k,v|
    string += "%02d%s " % [v, k] if v > 0
  }
  return string
end