Class: Mp3::Renamer
- Inherits:
-
Object
- Object
- Mp3::Renamer
- Includes:
- Utils::Parser
- Defined in:
- lib/mp3/renamer.rb
Instance Attribute Summary collapse
-
#album ⇒ Object
Returns the value of attribute album.
-
#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.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Renamer
constructor
A new instance of Renamer.
-
#read_album(src_dir) ⇒ Object
initialize.
-
#rename_tracks ⇒ Object
read.
-
#update_id3_tags(dst_dir) ⇒ Object
read.
- #write_album(dst_dir) ⇒ Object
Methods included from Utils::Parser
#parse_args, #parse_array, #parse_hash
Constructor Details
#initialize(*args) ⇒ Renamer
Returns a new instance of Renamer.
21 22 23 24 25 |
# File 'lib/mp3/renamer.rb', line 21 def initialize(*args) @album_artist = nil @album_title = nil @album_year = nil end |
Instance Attribute Details
#album ⇒ Object
Returns the value of attribute album.
19 20 21 |
# File 'lib/mp3/renamer.rb', line 19 def album @album end |
#album_artist ⇒ Object
Returns the value of attribute album_artist.
16 17 18 |
# File 'lib/mp3/renamer.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/renamer.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/renamer.rb', line 18 def album_year @album_year end |
Instance Method Details
#read_album(src_dir) ⇒ Object
initialize
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 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 |
# File 'lib/mp3/renamer.rb', line 27 def read_album(src_dir) here = Dir.pwd Dir.chdir src_dir puts "you are here: \"#{Dir.pwd}\"" if $DEBUG @album_artist ||= File.basename(File.('..')) @album_title ||= File.basename(File.('.')) @album_year ||= '2008' @album = Mp3::Album.new(:artist => @album_artist, :title => @album_title, :year => @album_year) disc_number = 0 Dir['*'].sort.each do |e| next if not File.directory?(e) puts "\t#{e}" if $DEBUG disc_number += 1 disc = Mp3::Disc::new(:number => disc_number) here2 = Dir.pwd Dir.chdir e track_number = 0 Dir['*'].sort.each do |t| if t =~ /\.((mp3)|(mp4)|(aac))$/ track_number += 1 track = Mp3::Track::new(:number => track_number, :file => t, :path => File.(t)) end #puts "\t\t#{t}" disc.add(track) end Dir.chdir here2 @album.add(disc) end Dir.chdir here puts "Album artist : #{@album.album_artist}" puts "Album title : #{@album.album_title}" puts "Album year : #{@album.album_year}" puts "Number of disc(s) : #{@album.discs.size}" #pp(album) if $DEBUG end |
#rename_tracks ⇒ Object
read
70 71 72 |
# File 'lib/mp3/renamer.rb', line 70 def rename_tracks @album.rename end |
#update_id3_tags(dst_dir) ⇒ Object
read
74 75 76 77 |
# File 'lib/mp3/renamer.rb', line 74 def (dst_dir) dst_dir = File.join(dst_dir, @album.album_artist, @album.album_title) @album.(dst_dir) end |
#write_album(dst_dir) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/mp3/renamer.rb', line 79 def write_album(dst_dir) # # (1) create the output directory (if necessary) # (2) create the individual disc subdirs # (3) copy the track files per disc subdir # dst_dir = File.join(dst_dir, @album.album_artist, @album.album_title) if File.exists?(dst_dir) FileUtils.remove_dir(dst_dir, true) puts "Deleted output dir: #{dst_dir}" end puts "Created output dir: #{dst_dir}" File.makedirs(dst_dir) here = Dir.pwd Dir.chdir dst_dir @album.write(dst_dir) Dir.chdir here end |