1. import mutagen
  2. from mutagen.mp3 import MP3
  3. from mutagen.oggvorbis import OggVorbis
  4. from mutagen.flac import FLAC
  5. from mutagen.wav import WAV
  6. from mutagen.id3 import ID3
  7. from mutagen.easel import Easel
  8. def strip_metadata_from_lists(data_list):
  9. """
  10. Strips metadata from a list of audio files.
  11. Args:
  12. data_list: A list of file paths to audio files.
  13. Returns:
  14. A list of file paths with metadata stripped. Returns empty list if input is invalid.
  15. """
  16. if not isinstance(data_list, list):
  17. return [] # Return empty list if input is not a list
  18. stripped_list = []
  19. for file_path in data_list:
  20. try:
  21. # Determine file type and strip metadata accordingly
  22. if file_path.lower().endswith(".mp3"):
  23. audio = MP3(file_path)
  24. audio.delete("TPE1") # Artist
  25. audio.delete("TALB") # Album
  26. audio.delete("TIT2") # Title
  27. audio.delete("TCON") # Composer
  28. audio.delete("TDRC") # Disc Number
  29. audio.delete("TID3") # ID3 tag
  30. audio.save()
  31. stripped_list.append(file_path)
  32. elif file_path.lower().endswith(".ogg"):
  33. audio = OggVorbis(file_path)
  34. audio.delete("artist")
  35. audio.delete("album")
  36. audio.delete("title")
  37. audio.save()
  38. stripped_list.append(file_path)
  39. elif file_path.lower().endswith(".flac"):
  40. audio = FLAC(file_path)
  41. audio.delete("artist")
  42. audio.delete("album")
  43. audio.delete("title")
  44. audio.save()
  45. stripped_list.append(file_path)
  46. elif file_path.lower().endswith(".wav"):
  47. audio = WAV(file_path)
  48. audio.delete("Artist")
  49. audio.delete("Album")
  50. audio.delete("Title")
  51. audio.save()
  52. stripped_list.append(file_path)
  53. elif file_path.lower().endswith(".m4a"):
  54. audio = MP3(file_path) #M4A is often MP3 encoded
  55. audio.delete("TPE1") # Artist
  56. audio.delete("TALB") # Album
  57. audio.delete("TIT2") # Title
  58. audio.delete("TCON") # Composer
  59. audio.delete("TDRC") # Disc Number
  60. audio.delete("TID3") # ID3 tag
  61. audio.save()
  62. stripped_list.append(file_path)
  63. else:
  64. stripped_list.append(file_path) #If we can't process it, just add it to the list. Could add more file types.
  65. except Exception as e:
  66. print(f"Error processing {file_path}: {e}")
  67. stripped_list.append(file_path) # Add the file path even if there's an error.
  68. return stripped_list

Add your comment