Python extract mp3 album pictures

Source: Internet
Author: User
Tags id3 id3 tag

Now download the mp3 online, put it in the computer many times you can see the MP3 file will show the album Pictures,

Like this:

In this effect, some songs have no, some have,

Baidu Encyclopedia Such introduction to:

ID3 Label
ID3 is a metadata container that is used in MP3-formatted audio files. It can store related song name, artist, album, track number and other information in the MP3 file.
The ID3 tag is an additional piece of song in the MP3 music archive that can be added to the MP3 to add music performers, authors, and other categories of information to facilitate the management of a wide range of music. Missing ID3 tags does not affect MP3 playback, but if not, managing music files can be quite cumbersome. If you downloadMP3 on the Internet, there are probably already written ID3 messages. If you want to clear the reset, use the "Alt + 3" Hotkey in Winamp to modify the ID3 tag in the MP3 file.
Id3tags
In addition, ID3 is Id3tags, in which the "tag" in the English noun means "label", so "id3tags" is the meaning of "MP3 file track label".
In some places the abbreviation "ID3" to represent the "Id3tags", the two are essentially the same.
Development of standards
If there is no ID3, then people can only judge a song according to the name of what it is, and even if you hear what song, its singer, album name you may not be able to back down, so to MP3 file add built-in tag is a matter of course. Interestingly, the MP3 label does not have an ISO international standard, and the various versions of ID3 are just a near-de-facto criterion, and no one is forcing the player or coding program to support it.


Bloggers, I don't know anything about these internal structures of MP3.

Recently in a player, I want to show the current playing the thumbnail of the song, the first thought of a very stupid way, is to take this song to a music site search, and then grab the picture,

Found that this is still difficult to do, after the song to click on the playback will be asynchronous to download the album pictures, to analyze the Web page JS code, Trouble, casually looked at a bit did not see what the clue,

Then I changed my mind, a lot of songs are built-in album map, if you can extract it is not better, also do not have to network, and I found that many players are doing so, not any song can search out album map.

Then I searched the Internet, Id3 extract album Pictures. Sure enough, a practical not found, a lot of articles are said its principle, specific how to extract but did not say, Baidu does not work, or changed Google to try A,

At the same time, change the search keyword to english (I searched this way: How to get the picture from MP3 file. Bo Master English sucks, do not joke, just give everyone a train of thought, indeed in a foreign very fire it question and answer community see I want. (Recommended, this site is really good, solve my many problems: http://stackoverflow.com)

From mutagen Import fileafile = File (' Some.mp3 ') # Mutagen can automatically detect format and type of tagsartwork = Afile . tags[' apic:e '].data # access APIC frame and grab the Imagewith open (' image.jpg ', ' WB ') as Img:img.write (artwork) # Write Artwork to New image

Using print afile.tags You can see all the tags in this file, and then extract what you want,

I use open ("Src/temp.jpg", "W"). Write (afiles.tags[' apic:e '].data) extract the data from the picture, save it to a new picture, and have to say that the Python class library is very rich

There are many other ways that the module can be researched on its own;

The above solves my problem,

The universal method of extracting the Internet is to read the MP3 as a binary file, intercept the specified length of the content, as for the interception of that part of the data can refer to ID3 structure of the introduction


Python extract mp3 album pictures

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.