The first is the installation
: Https://pypi.python.org/pypi/mutagen
Installation:
TAR-ZXVF mutagen-1.29.tar.gz
CD mutagen-1.29
./setup.py Build
./setup.py Install
Use:
From Mutagen.mp3 import MP3, EasyMP3
From MUTAGEN.ID3 import EasyID3
From MUTAGEN.ID3 import COMM
#EasyMP3继承自MP3, it directly assigns ID3 to EasyID3, using EasyMP3 can be more convenient to obtain such as album name, singer name, song name and other tag information
Path = "~/home/yourself/workspace/music/test.mp3"
Mp3_info = EasyMP3 (path)
Album_name = mp3_info[' album ']
Singer_name = mp3_info[' artist ']
Song_name = mp3_info[' title ']
#但是有些信息是没有被封装成tag可以由mp3_info直接调用的
#例如想要获取专辑封面图片的url地址, you need to use MP3
Source_data = MP3 (path) #得到的source_data是可以迭代的
Mp3_turple = Source_data.items () #得到歌曲信息的元组, the tuple contains a variety of information
Comm = mp3_turple[-2][1] #得到的是一个COMM类, contains common song information, which is in Comm.text
Music = Comm.text[0] #歌曲信息是comm. The first element in the text list
#这时通过type (music) will get <type ' Unicode ' >,music is a dictionary form of string, we can intercept useful information into a dictionary
Music_info = eval (music[6:])
It contains the address of the "albumpic" corresponding to the cover picture.
Coverimgurl = music_info[' Albumpic ']
Print Coverimgurl
Linux (Ubuntu) for Python installation use the Mutagen module to get MP3 file information including the capture of the cover picture