获取歌曲信息歌曲详细信息
发布日期:2021-06-24 15:21:56 浏览次数:2 分类:技术文章

本文共 1430 字,大约阅读时间需要 4 分钟。

# -*- coding: utf-8 -*-from mutagen.mp3 import MP3import osclass GetMp3Info():    '''获取歌曲信息'''    def __init__(self, path):        songFile = MP3(path)        self.getTitle(songFile, path)        self.getArtist(songFile)        self.getAlbum(songFile)        self.getLength(songFile)    def getTitle(self, songFile, path):        '''获取歌曲名        songFile:文件对象        path:文件地址        '''        try:            self.title = str(songFile.tags['TIT2'])        except:            filename = os.path.basename(path)  # 从地址中获取文件名            self.title = filename.split('.')[0]  # 去掉文件名后缀    def getArtist(self,songFile):        '''获取歌手名        songFile:文件对象        '''        try:            self.artist=str(songFile.tags['TPE1'])        except:            self.artist=''    def getAlbum(self,songFile):        '''获取专辑名        songFile:文件对象        '''        try:            self.album=str(songFile.tags['TALB'])        except:            self.album=''    def getLength(self,songFile):        '''获取文件播放时时长'''        timeLength = int(songFile.info.length)        mintime = timeLength//60  #转换为分钟        sectime = timeLength % 60 #剩余的转换为秒        if sectime < 10:            sectime='0'+ str(sectime)        else:            sectime=str(sectime)        self.length=str(mintime)+":"+sectimeif __name__=='__main__':    path="E:\\KwDownload\\song\\Jarico.mp3"    song = GetMp3Info(path)    print(song.title,song.artist,song.album,song.length)

在这里插入图片描述

在这里插入图片描述

转载地址:https://blog.csdn.net/weixin_33595571/article/details/109587977 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:Python 获取歌曲详细信息 歌手 专辑 时长
下一篇:java Android studio 71 字符串截取 split()

发表评论

最新留言

路过,博主的博客真漂亮。。
[***.116.15.85]2024年04月07日 08时15分51秒