ruby on rails - how to get song cover art using TagLib -
here's code able song's picture/cover art.
taglib::mpeg::file.open("song_file_name.mp3") |file| tag = file.id3v2_tag cover = tag.frame_list('apic').first mime_type = cover.mime_type picture = cover.picture end
how can convert value of picture url or image's source?
you should store content of picture in file, save it, , make available on web server.
try like:
taglib::mpeg::file.open("song_file_name.mp3") |file| tag = file.id3v2_tag cover = tag.frame_list('apic').first mime_type = cover.mime_type picture = cover.picture extension = case cover.mime_type when 'image/jpeg', 'image/jpg' 'jpg' when 'image/gif' 'gif' else raise "mime not found" end file_name = "my_file.#{extension}" file.open(file_name, "w") |f| f.write(picture) end end
Comments
Post a Comment