Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added ability to save album art

  • Loading branch information...
commit 4891c24db2dace409c12f8bf783bc6325bf2c9d7 1 parent 1fe54e7
Daniel Westendorf authored
Showing with 44 additions and 3 deletions.
  1. +44 −3 lib/mp3info.rb
View
47 lib/mp3info.rb
@@ -87,7 +87,8 @@ class Mp3Info
"year" => "TYE",
"tracknum" => "TRK",
"comments" => "COM",
- "genre_s" => "TCO"
+ "genre_s" => "TCO",
+ "album_artist" => 'TPE2'
}
# for id3v2.3 and 2.4
@@ -98,7 +99,8 @@ class Mp3Info
"year" => "TYER",
"tracknum" => "TRCK",
"comments" => "COMM",
- "genre_s" => "TCON"
+ "genre_s" => "TCON",
+ "album_artist" => 'TPE2'
}
# http://www.codeproject.com/audio/MPEGAudioInfo.asp
@@ -173,6 +175,45 @@ def self.hastag2?(filename)
f.read(3) == "ID3"
}
end
+
+ def get_image_data
+ image_data = @tag2['APIC']
+ if image_data
+ image_data = image_data.unpack("c Z* c Z* a*")
+ else
+ raise "No Image Data Found!"
+ end
+ @image_mime_type = image_data[1]
+ @binary_image_data = image_data[4]
+ return nil
+ end
+
+ def get_binary_image_data
+ get_image_data unless @binary_image_data
+ if @binary_image_data.length < 1
+ raise "No Image Data Found"
+ else
+ return @binary_image_data
+ end
+ end
+
+ def get_image_mime_type
+ get_image_data unless @image_mime_type
+ if @image_mime_type.length < 1
+ raise "No Image Data Found"
+ else
+ return @image_mime_type.split("/")[1]
+ end
+ end
+
+ def save_image(path_to_image, filename)
+ mime_type = self.get_image_mime_type
+ image_data = self.get_binary_image_data
+ f = File.open(path_to_image + filename + "." + mime_type , 'wb')
+ f.write(image_data)
+ f.close
+ return true
+ end
# Remove id3v1 tag from +filename+
def self.removetag1(filename)
@@ -494,7 +535,7 @@ def flush
def to_s
s = "MPEG #{@mpeg_version} Layer #{@layer} #{@vbr ? "VBR" : "CBR"} #{@bitrate} Kbps #{@channel_mode} #{@samplerate} Hz length #{@length} sec. header #{@header.inspect} "
s << "tag1: "+@tag1.inspect+"\n" if hastag1?
- s << "tag2: "+@tag2.inspect+"\n" if hastag2?
+ #s << "tag2: "+@tag2.inspect+"\n" if hastag2?
s
end

0 comments on commit 4891c24

Please sign in to comment.
Something went wrong with that request. Please try again.