Class: Mp3::Track

Inherits:
Object
  • Object
show all
Includes:
Utils::Formatter, Utils::Parser
Defined in:
lib/mp3/track.rb

Constant Summary

Constants included from Utils::Formatter

Utils::Formatter::FORMAT_FOR_OTHERS, Utils::Formatter::FORMAT_FOR_X, Utils::Formatter::FORMAT_FOR_XX, Utils::Formatter::FORMAT_FOR_XXX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::Parser

#parse_args, #parse_array, #parse_hash

Methods included from Utils::Formatter

#format

Constructor Details

#initialize(*args) ⇒ Track

Returns a new instance of Track.



25
26
27
28
29
30
31
# File 'lib/mp3/track.rb', line 25

def initialize(*args)
    @track_title = ''
    @separator   = '.'
    @prefix      = 'T'
    @suffix      = ''
    parse_args(nil, args)
end

Instance Attribute Details

#album_artistObject

Returns the value of attribute album_artist.



16
17
18
# File 'lib/mp3/track.rb', line 16

def album_artist
  @album_artist
end

#album_titleObject

Returns the value of attribute album_title.



17
18
19
# File 'lib/mp3/track.rb', line 17

def album_title
  @album_title
end

#album_yearObject

Returns the value of attribute album_year.



18
19
20
# File 'lib/mp3/track.rb', line 18

def album_year
  @album_year
end

#fileObject

Returns the value of attribute file.



19
20
21
# File 'lib/mp3/track.rb', line 19

def file
  @file
end

#pathObject

Returns the value of attribute path.



20
21
22
# File 'lib/mp3/track.rb', line 20

def path
  @path
end

#prefixObject

Returns the value of attribute prefix.



22
23
24
# File 'lib/mp3/track.rb', line 22

def prefix
  @prefix
end

#separatorObject

Returns the value of attribute separator.



21
22
23
# File 'lib/mp3/track.rb', line 21

def separator
  @separator
end

#suffixObject

Returns the value of attribute suffix.



23
24
25
# File 'lib/mp3/track.rb', line 23

def suffix
  @suffix
end

#track_numberObject

Returns the value of attribute track_number.



14
15
16
# File 'lib/mp3/track.rb', line 14

def track_number
  @track_number
end

#track_titleObject

Returns the value of attribute track_title.



15
16
17
# File 'lib/mp3/track.rb', line 15

def track_title
  @track_title
end

Instance Method Details

#rename(disc_title, number_of_tracks) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/mp3/track.rb', line 33

def rename(disc_title, number_of_tracks)
    print '.'; $stdout.flush
    
    @track_title = disc_title + '-' + format(@prefix, @separator, @suffix, @track_number, number_of_tracks)
    
    #print @track_title + "/"; $stdout.flush
    
end

#update_id3_tagsObject



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/mp3/track.rb', line 42

def update_id3_tags
    print '.'; $stdout.flush
    track_filename = "#{@track_title}.mp3"
    $track_number += 1
    if $DEBUG
        print "\n\ttrack source file = #{@path}"
        print "\n\ttrack filename    = #{track_filename}"
        print "\n\t@track number     = #{@track_number}"
        print "\n\t$track number     = #{$track_number}"
    end
    Mp3Info.open(track_filename) do |mp3|
        #
        # ID3v1 tags
        #
        mp3.tag.tracknum = $track_number # @track_number.to_i
        mp3.tag.title    = @track_title
        mp3.tag.artist   = @album_artist
        mp3.tag.album    = @album_title
        mp3.tag.year     = @album_year
        mp3.tag.genre_s  = 'speech'
        mp3.tag.comments = "Renamed on #{Time.now}"
        
        #
        # ID3v2 tags
        #
        mp3.tag2.TRK = $track_number # @track_number.to_i
        mp3.tag2.TT2 = @track_title
        mp3.tag2.TP2 = @album_artist
        mp3.tag2.TAL = @album_title
        mp3.tag2.TYE = @album_year
        mp3.tag2.TCO = mp3.tag.genre_s
        mp3.tag2.COM = mp3.tag.comments
    end
end

#writeObject



77
78
79
80
81
82
83
84
85
# File 'lib/mp3/track.rb', line 77

def write
    print '.'; $stdout.flush
    track_filename = "#{@track_title}.mp3"
    if $DEBUG
        print "\n\ttrack source file = #{@path}"
        print "\n\ttrack filename    = #{track_filename}"
    end
    File.copy(@path, track_filename, false)
end