本文實例講述了python獲取mp3文件信息的方法。分享給大家供大家參考。具體如下:
將代碼生成.py文件放在目錄下運行,可以獲取該目錄的所有mp3文件的信息,需要使用ID3庫
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
import os, sys from ID3 import * files = os.listdir(os.getcwd()) for f in files: x = os.path.splitext(f) if x[ 1 ] = = '.mp3' : n = x[ 0 ].split( ' - ' ) author = n[ 0 ] title = n[ 1 ] id3info = ID3(f) id3info[ 'ARTIST' ] = author id3info[ 'TITLE' ] = title print f + ' id3 tagged.' print 'Done!' |
希望本文所述對大家的Python程序設計有所幫助。