module Quiyo::Status

Public Instance Methods

_print(key, value) click to toggle source
# 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
info() click to toggle source
# 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
nowplaying() click to toggle source
# 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
prompt() click to toggle source
# 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) click to toggle source
# 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