module MusicMetaFixer::TagEditor

Public Class Methods

change_tag_info(music_path, song_info) click to toggle source
# File lib/music_meta_fixer/tag_editor.rb, line 18
def self.change_tag_info(music_path, song_info)
  TagLib::FileRef.open(music_path) do |fileref|
    unless fileref.null?
      tag = fileref.tag
      tag.title = song_info.name unless song_info.name == tag.title
      tag.artist = song_info.artist unless song_info.artist == tag.artist
      tag.album = song_info.album unless tag.album == song_info.album
      tag.genre = song_info.genre unless tag.genre == song_info.genre
      tag.year = song_info.year.to_i unless tag.year == song_info.year.to_i
      fileref.save
    end
  end
end
get_song_info(music_path) click to toggle source
# File lib/music_meta_fixer/tag_editor.rb, line 3
def self.get_song_info(music_path)
  current_song_info = nil
  TagLib::FileRef.open(music_path) do |fileref|
    unless fileref.null?
      tag = fileref.tag
      current_song_info = Song.new(tag.title)
      current_song_info.artist = tag.artist
      current_song_info.album = tag.album
      current_song_info.genre = tag.genre
      current_song_info.year = tag.year
    end
  end
  current_song_info
end