import os from mutagen.flac import FLAC from mutagen.oggopus import OggOpus from mutagen.oggvorbis import OggVorbis def get_music_location(): possible_paths = [ '/mnt/sdcard/Music', '/storage/emulated/0/Music', '/sdcard/Music', os.path.join(os.environ.get('HOME', ''), 'Music'), os.path.join(os.environ.get('HOME', ''), 'Multimedia', 'Music'), os.path.join(os.getcwd(), 'music') ] for path in possible_paths: if os.path.exists(path): return path default_path = os.path.join(os.getcwd(), 'music') os.makedirs(default_path, exist_ok=True) return default_path def process_audio_file(file_path): try: file_ext = os.path.splitext(file_path)[1].lower() if file_ext == '.flac': audio = FLAC(file_path) elif file_ext == '.opus': audio = OggOpus(file_path) elif file_ext == '.ogg': audio = OggVorbis(file_path) else: return False current_album = audio.get('album', [''])[0].strip() if current_album != '': return False audio['album'] = 'Music' audio.save() return True except Exception as e: print(f"Error: {os.path.basename(file_path)} - {str(e)}") return False def update_album_info(): music_folder = get_music_location() updated_files = 0 for root, _, files in os.walk(music_folder): for filename in files: full_path = os.path.join(root, filename) if process_audio_file(full_path): updated_files += 1 print(f"Fixed: {filename}") print(f"\nSuccessfully updated {updated_files} files with empty album tags") if __name__ == "__main__": print("Empty Album Fixer") update_album_info()