import mutagen
from mutagen.mp3 import MP3
from mutagen.oggvorbis import OggVorbis
from mutagen.flac import FLAC
from mutagen.wav import WAV
from mutagen.id3 import ID3
from mutagen.easel import Easel
def strip_metadata_from_lists(data_list):
"""
Strips metadata from a list of audio files.
Args:
data_list: A list of file paths to audio files.
Returns:
A list of file paths with metadata stripped. Returns empty list if input is invalid.
"""
if not isinstance(data_list, list):
return [] # Return empty list if input is not a list
stripped_list = []
for file_path in data_list:
try:
# Determine file type and strip metadata accordingly
if file_path.lower().endswith(".mp3"):
audio = MP3(file_path)
audio.delete("TPE1") # Artist
audio.delete("TALB") # Album
audio.delete("TIT2") # Title
audio.delete("TCON") # Composer
audio.delete("TDRC") # Disc Number
audio.delete("TID3") # ID3 tag
audio.save()
stripped_list.append(file_path)
elif file_path.lower().endswith(".ogg"):
audio = OggVorbis(file_path)
audio.delete("artist")
audio.delete("album")
audio.delete("title")
audio.save()
stripped_list.append(file_path)
elif file_path.lower().endswith(".flac"):
audio = FLAC(file_path)
audio.delete("artist")
audio.delete("album")
audio.delete("title")
audio.save()
stripped_list.append(file_path)
elif file_path.lower().endswith(".wav"):
audio = WAV(file_path)
audio.delete("Artist")
audio.delete("Album")
audio.delete("Title")
audio.save()
stripped_list.append(file_path)
elif file_path.lower().endswith(".m4a"):
audio = MP3(file_path) #M4A is often MP3 encoded
audio.delete("TPE1") # Artist
audio.delete("TALB") # Album
audio.delete("TIT2") # Title
audio.delete("TCON") # Composer
audio.delete("TDRC") # Disc Number
audio.delete("TID3") # ID3 tag
audio.save()
stripped_list.append(file_path)
else:
stripped_list.append(file_path) #If we can't process it, just add it to the list. Could add more file types.
except Exception as e:
print(f"Error processing {file_path}: {e}")
stripped_list.append(file_path) # Add the file path even if there's an error.
return stripped_list
Add your comment