Linux (Ubuntu) for Python installation use the Mutagen module to get MP3 file information including the capture of the cover picture

Source: Internet
Author: User
Tags id3

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

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.