fastdial page updated
[cinan.git] / skripty / mpdr.rb
blob6cb02e95ba487768e9ff03499f23b16d7140a45b
1 #Ruby MPD wrapper
3 require 'rubygems'
4 require 'librmpd'
6 HOST = "localhost"
7 PORT = 6600
9 mpd = MPD.new HOST, PORT
11 mpd.connect
12 #mpd.password('mypassword')
13 if mpd.stopped?
14     mpd.play
15 end
16 song = mpd.current_song
18 #Time calculation
19 time = mpd.status["time"]
20 time = time.split(':')
21 elapsed = time[0].to_i
22 el_min = elapsed / 60
23 el_sec = elapsed % 60
24 elapsed = "#{el_min}:#{el_sec}"
26 total = time[1].to_i
27 tot_min = total / 60
28 tot_sec = total % 60
29 total = "#{tot_min}:#{tot_sec}"
31 #time = "#{elapsed}/#{total}"
32 time = ""
35 #Adjusting output of Artist
36 artist = "#{song.artist}"
37 artist.gsub!(/ & /, '/')
39 #Adjusting output of Title
40 title = "#{song.title}"
41 title.gsub!(/_/, ' ')
42 title.gsub!(/ & /, '/')
43 title.gsub!(/feat/i, 'Ft')
44 title.gsub!(/remix/i, 'rmx')
46 #Some hacky to get correct output if id3tags are strange
47 if artist.empty?
48     puts "[#{song.file} ]"
49 elsif title.empty?
50     puts "[#{song.file} ]"
51 elsif artist =~ /artist/i
52     puts "[#{song.file} ]"
53 elsif title =~ /track/i
54     puts "[#{song.file} ]"
55 else
56     puts "[#{artist} - #{title}]"
57 end
59 mpd.disconnect