lib/audioinfo.rb in ruby-audioinfo-0.1.3 vs lib/audioinfo.rb in ruby-audioinfo-0.1.4

- old
+ new

@@ -28,11 +28,11 @@ "trackid" => "Track Id" } SUPPORTED_EXTENSIONS = %w{mp3 ogg mpc wma mp4 aac m4a flac} - VERSION = "0.1.3" + VERSION = "0.1.4" attr_reader :path, :extension, :musicbrainz_infos, :tracknum, :bitrate, :vbr attr_reader :artist, :album, :title, :length, :date # "block version" of #new() @@ -181,30 +181,39 @@ end # set the title of the file def title=(v) - @needs_commit = true - @title = v + if @title != v + @needs_commit = true + @title = v + end end # set the artist of the file def artist=(v) - @needs_commit = true - @artist = v + if @artist != v + @needs_commit = true + @artist = v + end end # set the album of the file def album=(v) - @needs_commit = true - @album = v + if @album != v + @needs_commit = true + @album = v + end end # set the track number of the file def tracknum=(v) - @needs_commit = true - @tracknum = v.to_i + v = v.to_i + if @tracknum != v + @needs_commit = true + @tracknum = v + end end # hash-like access to tag def [](key) @hash[key] @@ -218,17 +227,17 @@ # close the file and commits changes to disk def close if @needs_commit case @info when Mp3Info - Mp3Info.open(@path) do |info| + Mp3Info.open(@path, :encoding => @encoding) do |info| info.tag.artist = @artist info.tag.title = @title info.tag.album = @album info.tag.tracknum = @tracknum end when OggInfo - OggInfo.open(@path, "utf-8") do |ogg| + OggInfo.open(@path, @encoding) do |ogg| { "artist" => @artist, "album" => @album, "title" => @title, "tracknumber" => @tracknum}.each do |k,v| ogg.tag[k] = v