Class: Mp3::Track
- Inherits:
-
Object
- Object
- Mp3::Track
- 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
-
#album_artist ⇒ Object
Returns the value of attribute album_artist.
-
#album_title ⇒ Object
Returns the value of attribute album_title.
-
#album_year ⇒ Object
Returns the value of attribute album_year.
-
#file ⇒ Object
Returns the value of attribute file.
-
#path ⇒ Object
Returns the value of attribute path.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#separator ⇒ Object
Returns the value of attribute separator.
-
#suffix ⇒ Object
Returns the value of attribute suffix.
-
#track_number ⇒ Object
Returns the value of attribute track_number.
-
#track_title ⇒ Object
Returns the value of attribute track_title.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Track
constructor
A new instance of Track.
- #rename(disc_title, number_of_tracks) ⇒ Object
- #update_id3_tags ⇒ Object
- #write ⇒ Object
Methods included from Utils::Parser
#parse_args, #parse_array, #parse_hash
Methods included from Utils::Formatter
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_artist ⇒ Object
Returns the value of attribute album_artist.
16 17 18 |
# File 'lib/mp3/track.rb', line 16 def album_artist @album_artist end |
#album_title ⇒ Object
Returns the value of attribute album_title.
17 18 19 |
# File 'lib/mp3/track.rb', line 17 def album_title @album_title end |
#album_year ⇒ Object
Returns the value of attribute album_year.
18 19 20 |
# File 'lib/mp3/track.rb', line 18 def album_year @album_year end |
#file ⇒ Object
Returns the value of attribute file.
19 20 21 |
# File 'lib/mp3/track.rb', line 19 def file @file end |
#path ⇒ Object
Returns the value of attribute path.
20 21 22 |
# File 'lib/mp3/track.rb', line 20 def path @path end |
#prefix ⇒ Object
Returns the value of attribute prefix.
22 23 24 |
# File 'lib/mp3/track.rb', line 22 def prefix @prefix end |
#separator ⇒ Object
Returns the value of attribute separator.
21 22 23 |
# File 'lib/mp3/track.rb', line 21 def separator @separator end |
#suffix ⇒ Object
Returns the value of attribute suffix.
23 24 25 |
# File 'lib/mp3/track.rb', line 23 def suffix @suffix end |
#track_number ⇒ Object
Returns the value of attribute track_number.
14 15 16 |
# File 'lib/mp3/track.rb', line 14 def track_number @track_number end |
#track_title ⇒ Object
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_tags ⇒ Object
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 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 |
#write ⇒ Object
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 |