diff options
-rw-r--r-- | Gemfile | 1 | ||||
-rw-r--r-- | bass_player.rb | 32 |
2 files changed, 24 insertions, 9 deletions
@@ -5,3 +5,4 @@ gem "qml" gem "sequel" gem "rake" gem "sqlite3" +gem "ruby-audioinfo" diff --git a/bass_player.rb b/bass_player.rb index 4796d61..6cb73c4 100644 --- a/bass_player.rb +++ b/bass_player.rb @@ -1,4 +1,5 @@ require 'qml' +require 'audioinfo' require './models' module BassPlayer @@ -18,7 +19,6 @@ module BassPlayer def initialize super() Song.all.each do |song| - p song model << { title: song.title, duration: ms_to_time(song.duration) @@ -27,20 +27,35 @@ module BassPlayer end def add(file_url, duration, metadata) - item = { - title: file_url, - duration: duration - } - p item - model << item + path = file_url.split('file://').last + AudioInfo.open(path) do |info| + title = if info.title.empty? + File.basename(path) + else + info.title + end + song = Song.create( + title: title, + duration: info.length * 1000, + path: file_url + ) + + item = { + title: song.title, + duration: ms_to_time(song.duration) + } + model << item + end end def song_selected(song) + puts "Selected song: #{song}" unless song.nil? self.current_song = model[song][:title] + puts "Setting current song to #{self.current_song}" end part_model.clear - parts = Part.join(:songs, title: current_song).all.map do |part| + parts = Song.first(title: self.current_song).parts.map do |part| { name: part.name, from: ms_to_time(part.from), @@ -64,7 +79,6 @@ module BassPlayer def ms_to_time(ms) retval = Time.at(ms/1000).utc.strftime("%H:%M:%S") - p "ms: '#{ms}' - Time: #{retval}" return retval end end |