【问题标题】:Using python to get images from an mp3 file使用 python 从 mp3 文件中获取图像
【发布时间】:2020-06-29 06:23:49
【问题描述】:

我发现这个使用 eyed3 的命令在将找到的图像写入目录 DIR 的 mp3 文件上工作正常

eyeD3 --write-images=DIR  file.mp3

但我想在 python 程序中使用它,谁能给我一个例子 关于如何做到这一点。

这个 sn-p 工作正常

audiofile = eyed3.load("file.mp3")
        print(audiofile.tag.album)
        print(audiofile.tag.artist) 
        print(audiofile.tag.title)  
        print(audiofile.tag.track_num)  

【问题讨论】:

    标签: python image mp3


    【解决方案1】:

    应该这样做。 我也添加了图像类型,因为单个 MP3 文件中可以有多个图像,而您没有指定需要哪一个。对于大多数文件,这将是专辑封面。

    import eyed3
    
    audio_file = eyed3.load("test.mp3")
    album_name = audio_file.tag.album
    artist_name = audio_file.tag.artist
    for image in audio_file.tag.images:
        image_file = open("{0} - {1}({2}).jpg".format(artist_name, album_name, image.picture_type), "wb")
        print("Writing image file: {0} - {1}({2}).jpg".format(artist_name, album_name, image.picture_type))
        image_file.write(image.image_data)
        image_file.close()
    

    【讨论】:

    • 嗨,SteveMany,感谢您的完美工作,我对此很陌生,所以
    • -你能告诉我如何提取实际的 .jpg 参考,以便我可以在我的 gui 中显示它 - 非常感谢!特里
    • 抱歉回复晚了。最近真的很忙。您应该可以使用 image.image_data 作为参考
    • 您好,感谢您提供的信息,但我仍然遇到问题,因为我想使用 QPixmap 将图像直接加载到 Qlabel 中。如果我按照您上面的建议编写文件并使用 image = QPixmap(fileName) 将其读回,然后使用 setPixmap,则此方法有效。但我确信有一种更优雅的方法可以做到这一点?非常感谢您提供任何进一步的帮助
    猜你喜欢
    • 1970-01-01
    • 2016-12-12
    • 1970-01-01
    • 2019-03-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-05-16
    • 1970-01-01
    相关资源
    最近更新 更多