Skip to content

Commit 360bd88

Browse files
author
dafoxia
committed
fix seek-bug, better stats display
1 parent 400613e commit 360bd88

1 file changed

Lines changed: 22 additions & 27 deletions

File tree

plugins/mpd.rb

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def handle_chat(msg,message)
201201

202202
if message == 'seek'
203203
# seek command without a value...
204-
channelmessage( "Now on position #{timedecode @@bot[:mpd].status[:time][0]}/#{timedecode @@bot[:mpd].status[:time][1]}.")
204+
privatemessage("Now on position #{timedecode @@bot[:mpd].status[:time][0]}/#{timedecode @@bot[:mpd].status[:time][1]}.")
205205
end
206206

207207
if message[0..3] == 'seek'
@@ -245,7 +245,6 @@ def handle_chat(msg,message)
245245
# mpd is old and knows no seek commands
246246
puts "[mpd-plugin] [error] seek without success, maybe mpd version < 0.17 installed"
247247
end
248-
status = @@bot[:mpd].status
249248
channelmessage( "Now on position #{timedecode @@bot[:mpd].status[:time][0]}/#{timedecode @@bot[:mpd].status[:time][1]}.")
250249
end
251250

@@ -333,22 +332,29 @@ def handle_chat(msg,message)
333332
out = ""
334333
@@bot[:mpd].songs.each do |song|
335334
if block >= 50
336-
#messageto(msg.actor, out.to_s)
337335
privatemessage(out.to_s)
338336
out = ""
339337
block = 0
340338
end
341339
out << "<br/>" + song.file.to_s
342340
block += 1
343341
end
344-
#messageto(msg.actor, out.to_s)
345342
privatemessage(out.to_s)
346343
end
347344

348345
if message == 'stats'
349346
out = "<table>"
350347
@@bot[:mpd].stats.each do |key, value|
351-
out << "<tr><td>#{key}</td><td>#{value}</td></tr>"
348+
case
349+
when key.to_s == 'uptime'
350+
out << "<tr><td>#{key}</td><td>#{timedecode(value)}</td></tr>"
351+
when key.to_s == 'playtime'
352+
out << "<tr><td>#{key}</td><td>#{timedecode(value)}</td></tr>"
353+
when key.to_s == 'db_playtime'
354+
out << "<tr><td>#{key}</td><td>#{timedecode(value)}</td></tr>"
355+
else
356+
out << "<tr><td>#{key}</td><td>#{value}</td></tr>"
357+
end
352358
end
353359
out << "</table>"
354360
privatemessage( out)
@@ -499,7 +505,7 @@ def handle_chat(msg,message)
499505
# out << "<tr><td>Current playlist:</td><td>#{value}</td></tr>"
500506
#end
501507
when key.to_s == 'playlistlength'
502-
out << "<tr><td>Song count in current queue/playlist:</td><td valign='bottom'>#{value}</td></tr>"
508+
out << "<tr><td>Song count in current queue/playlist:</td><td valign='bottom'>#{timedecode(value)}</td></tr>"
503509
when key.to_s == 'mixrampdb'
504510
out << "<tr><td>Mixramp db:</td><td>#{value}</td></tr>"
505511
when key.to_s == 'state'
@@ -530,25 +536,9 @@ def handle_chat(msg,message)
530536
#out << "<tr><td>Current songid:</td><td>#{current_song}</td></tr>"
531537
out << "<tr><td>Current songid:</td><td>#{value}</td></tr>"
532538
when key.to_s == 'time'
533-
begin
534-
#Code from https://stackoverflow.com/questions/19595840/rails-get-the-time-difference-in-hours-minutes-and-seconds
535-
now_mm, now_ss = value[0].divmod(60) #Minutes and seconds of current time within the song.
536-
now_hh, now_mm = now_mm.divmod(60)
537-
total_mm, total_ss = value[1].divmod(60) #Minutes and seconds of total time of the song.
538-
total_hh, total_mm = total_mm.divmod(60)
539-
540-
now = "%02d:%02d:%02d" % [now_hh, now_mm, now_ss]
541-
total = "%02d:%02d:%02d" % [total_hh, total_mm, total_ss]
542-
543-
out << "<tr><td>Current position:</td><td>#{now}/#{total}</td></tr>"
544-
rescue
545-
out << "<tr><td>Current position:</td><td>Unknown stream position.</td></tr>"
546-
end
539+
out << "<tr><td>Current position:</td><td>#{timedecode(now)}/#{timedecode(total)}</td></tr>"
547540
when key.to_s == 'elapsed'
548-
now_mm, now_ss = value.divmod(60) #Minutes and seconds of current time within the song.
549-
now_hh, now_mm = now_mm.divmod(60)
550-
now = "%02d:%02d:%02d" % [now_hh, now_mm, now_ss]
551-
out << "<tr><td>Elapsed:</td><td>#{now}</td></tr>"
541+
out << "<tr><td>Elapsed:</td><td>#{timedecode(now)}</td></tr>"
552542
when key.to_s == 'bitrate'
553543
out << "<tr><td>Current song bitrate:</td><td>#{value}</td></tr>"
554544
when key.to_s == 'audio'
@@ -705,10 +695,15 @@ def handle_chat(msg,message)
705695
def timedecode(time)
706696
begin
707697
#Code from https://stackoverflow.com/questions/19595840/rails-get-the-time-difference-in-hours-minutes-and-seconds
708-
now_mm, now_ss = time.divmod(60)
698+
now_mm, now_ss = time.to_i.divmod(60)
709699
now_hh, now_mm = now_mm.divmod(60)
710-
now = "%02d:%02d:%02d" % [now_hh, now_mm, now_ss]
711-
rescue
700+
if ( now_hh < 24 )
701+
now = "%02d:%02d:%02d" % [now_hh, now_mm, now_ss]
702+
else
703+
now_dd, now_hh = now_hh.divmod(24)
704+
now = "%04d days %02d:%02d:%02d" % [now_dd, now_hh, now_mm, now_ss]
705+
end
706+
rescue
712707
now "unknown"
713708
end
714709
end

0 commit comments

Comments
 (0)