0

我正在使用 taglib-ruby 从 mp3 文件中读取和写入标签数据。一切正常,但是当我添加图像时,它会添加它并保留原始图像。我正在寻找替换现有图像,所以只有一个。您如何删除并重新填充或替换?这是我的更新方式。

    TagLib::MPEG::File.open(active_storage_disk_service.send(:path_for, @song.file.blob.key)) do |fileref|
            tag = fileref.id3v2_tag
            # properties = fileref.audio_properties

          albumart = TagLib::ID3v2::AttachedPictureFrame.new
            albumart.mime_type = "image/jpg"
            albumart.description = "Media"
            albumart.type = TagLib::ID3v2::AttachedPictureFrame::Media
            albumart.picture = File.open("download.jpg", 'r') { |f| f.read }

            tag.add_frame(albumart)
            tag.title = @song.title
            tag.artist = @song.artist
            tag.album = @song.album
            tag.year = @song.year.to_i
            tag.track = @song.track.to_i
            tag.genre = @song.genre

            fileref.save
        end
4

0 回答 0