Python code to remove meta data from .mp3 files

 

 

How to remove meta data (ID tags) from .mp3 file with Python?

 

Meta data refers ID3 tags or extra information encoded into mp3 files such as title, artist s name, composer s details, release year, credits, rating and other information related to the album.

 

These meta data can be removed without altering the quality of the mp3 file, with this Python code.

 

Install mutagen via command prompt and run the code.

 

Directory of this program should be in the folder containing .mp3 files.

 

Most importantly, back-up your files before running this code.

 

Designed by,

Dr. M Kanagasabapathy

www.enote.page

 

 

Python code:

import os

import sys

import codecs

from mutagen.mp3 import MP3

TEXT_ENCODING = 'utf8'

 

if (len(sys.argv) > 1):

fpath = sys.argv[1]

else:

fpath = os.path.abspath(os.path.dirname(sys.argv[0]))

 

for fn in os.listdir(fpath):

 

fname = os.path.join(fpath, fn)

if fname.lower().endswith('.mp3'):

print(fn),

mp3 = MP3(fname)

try:

mp3.delete()

mp3.save()

except:

print ('no ID3 tag')

print (' ')

print ('Completed')

 

 

YouTube link