【问题标题】:how to get song cover art using TagLib如何使用 TagLib 获取歌曲封面
【发布时间】:2013-04-05 07:04:31
【问题描述】:

这是我能够获取歌曲图片/封面艺术的代码。

TagLib::MPEG::File.open("song_file_name.mp3") do |file|
    tag = file.id3v2_tag

    cover = tag.frame_list('APIC').first
    mime_type = cover.mime_type
    picture = cover.picture
end

如何将图片的值转换为url或图片的来源?

【问题讨论】:

    标签: ruby-on-rails taglib


    【解决方案1】:

    您应该将图片的内容存储在一个文件中,保存它,并使其在网络服务器上可用。

    尝试做类似的事情:

    TagLib::MPEG::File.open("song_file_name.mp3") do |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") do |f|
          f.write(picture)
        end
    
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多