Class: FilterRename::AudioFilename

Inherits:
Filename
  • Object
show all
Defined in:
lib/filter_rename/filetype/audio_filename.rb

Overview

Mp3 files tags handling.

Instance Attribute Summary

Attributes inherited from Filename

#original

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Filename

#!=, #calculate_hash, #custom?, #exists?, #filename, #full_filename, #full_path, #get_string, #pretty_size, #set_string, #target?, #targets, #values, #writable?

Constructor Details

#initialize(fname, cfg) ⇒ AudioFilename

Returns a new instance of AudioFilename.



14
15
16
17
18
# File 'lib/filter_rename/filetype/audio_filename.rb', line 14

def initialize(fname, cfg)
  super

  load_audio_data(fname) if cfg.
end

Class Method Details

.writable_tags? ⇒ Boolean

Returns:



10
11
12
# File 'lib/filter_rename/filetype/audio_filename.rb', line 10

def self.writable_tags?
  true
end

Instance Method Details

#==(other) ⇒ Object



20
21
22
23
24
25
# File 'lib/filter_rename/filetype/audio_filename.rb', line 20

def ==(other)
  super &&
    ([@title, @artist, @album, @track, @comment, @year, @genre] ==
     [other.get_string(:title), other.get_string(:artist), other.get_string(:album), other.get_string(:track),
      other.get_string(:comment), other.get_string(:year), other.get_string(:genre)])
end

#diff(dest) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/filter_rename/filetype/audio_filename.rb', line 51

def diff(dest)
  super + "
   Title:    #{Differ.diff_by_word(dest.get_string(:title).to_s, @title.to_s)}
   Artist:   #{Differ.diff_by_word(dest.get_string(:artist).to_s, @artist.to_s)}
   Album:    #{Differ.diff_by_word(dest.get_string(:album).to_s, @album.to_s)}
   Track:    #{Differ.diff_by_word(dest.get_string(:track).to_s, @track.to_s)}
   Comments: #{Differ.diff_by_word(dest.get_string(:comment).to_s, @comment.to_s)}
   Year:     #{Differ.diff_by_word(dest.get_string(:year).to_s, @year.to_s)}
   Genre:    #{Differ.diff_by_word(dest.get_string(:genre).to_s, @genre.to_s)}
   "
end

#rename!(dest) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/filter_rename/filetype/audio_filename.rb', line 27

def rename!(dest)
  old_data = super

  TagLib::FileRef.open(full_filename) do |audio|
    old_data.merge!({ title: audio.tag.title, artist: audio.tag.artist, album: audio.tag.album,
                      track: audio.tag.track, comment: audio.tag.comment, year: audio.tag.year,
                      genre: audio.tag.genre })

    audio.tag.title = dest.get_string(:title)
    audio.tag.artist = dest.get_string(:artist)
    audio.tag.album = dest.get_string(:album)
    audio.tag.track = dest.get_string(:track)
    audio.tag.comment = dest.get_string(:comment).to_s
    audio.tag.year = dest.get_string(:year)
    audio.tag.genre = dest.get_string(:genre)

    audio.save
  end

  load_audio_data(full_filename)

  old_data
end