Module: Keenser::Music
Instance Method Summary collapse
- #all ⇒ Object
- #import(name, path) ⇒ Object
- #list(name) ⇒ Object
- #show ⇒ Object
- #status ⇒ Object
- #tag(name) ⇒ Object
Instance Method Details
#all ⇒ Object
57 58 59 60 61 |
# File 'lib/keenser/music.rb', line 57 def all puts "Playing all songs" `echo "set play_library=true\nplayer-next" | cmus-remote` show end |
#import(name, path) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/keenser/music.rb', line 43 def import name, path n = 0 t = Tag.find_or_create name: name File.read(path).split(/[\r\n]/).each do |line| next unless line.include? Computer.local.music # TODO: parse artist and title? s = Song.find_or_create path: line.sub(/^#{Computer.local.music}\/?/, '') SongTag.find_or_create song_id: s.id, tag_id: t.id n += 1 end t.export! "Imported #{n} songs" end |
#list(name) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/keenser/music.rb', line 35 def list name t = Tag.where(name: name.to_s).first t.export! raise Error.new "Cannot find tag '#{t}'" unless t `echo "load -p #{t.playlist}\nset play_library=false\nplayer-next" | cmus-remote` "'#{name}' now playing" end |
#show ⇒ Object
17 18 19 |
# File 'lib/keenser/music.rb', line 17 def show .to_s end |
#status ⇒ Object
6 7 8 9 10 11 12 13 14 15 |
# File 'lib/keenser/music.rb', line 6 def status expect "tmux" expect "cmus-remote" if `cmus-remote -Q 2>/dev/null` =~ /status (.*)/ $1.capitalize else "Cmus is not running" end end |
#tag(name) ⇒ Object
29 30 31 32 33 |
# File 'lib/keenser/music.rb', line 29 def tag name .tag name puts "Tagging #{} as #{name}" "#{name} ← #{}" end |