包含了作者,作曲,专辑等信息,长度为128BYTE。
也就是说,根据TAG_V2(ID3V2),音频数据,TAG_V1(ID3V1)三结构中的开头信息,便可以判断出是不是mp3编码的文件。
2.python代码
# coding: utf-8 ''' @author: BigFengFeng @time: 16/12/21 下午6:10 @license: Apache Licence @description: ''' import os #mp3filePath是否是mp3格式的 def isMp3Format(mp3filePath): #读取文件内字符串 f = open(mp3filePath, "r"); fileStr = f.read(); f.close(); head3Str = fileStr[:3]; #判断开头是不是ID3 if head3Str == "ID3": return True; #判断结尾有没有TAG last32Str = fileStr[-32:]; if last32Str[:3] == "TAG": return True; #判断第一帧是不是FFF开头, 转成数字 # fixme 应该循环遍历每个帧头,这样才能100%判断是不是mp3 ascii = ord(fileStr[:1]); if ascii == 255: return True; return False; #遍历folderPath看看是不是都是mp3格式的, #是就true,不是就是false, 并返回是mp3的list,不是MP3的list def isMp3FolderTraverse(folderPath): mp3List = []; notMp3List = []; isAllMpFormat = True; for dirpath, dirnames, filenames in os.walk(folderPath): for filename in filenames: path = dirpath + os.sep + filename; isMp3 = isMp3Format(path); #判断是不是mp3结尾的 并且 是mp3格式的 if isMp3 == False and str.endswith(path, ".mp3") == True: # print("--warning: file " + path + " is not mp3 format!--"); notMp3List.append(path); isAllMpFormat = False; else: mp3List.append(path); return isAllMpFormat, mp3List, notMp3List; if __name__ == '__main__': isMp3Format("s_com_click1.mp3"); isAllMp3, mp3List, notMp3List = isMp3FolderTraverse("sound"); print isAllMp3; print mp3List; print notMp3List;
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持PHP中文网。
更多详解python进行mp3格式判断相关文章请关注PHP中文网!
查看更多关于详解python进行mp3格式判断的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did86017