import os
def create_m3u_for_folder(folder_path, audio_extensions):
# Get the list of all audio files in the folder (case insensitive)
audio_files = [f for f in os.listdir(folder_path) if f.lower().endswith(tuple(audio_extensions))]
if not audio_files:
return # No audio files in this folder, skip creating the m3u file
# Sort the audio files to maintain order
audio_files.sort()
# Create the .m3u file
m3u_file_path = os.path.join(folder_path, 'playlist.m3u')
with open(m3u_file_path, 'w', encoding='utf-8') as m3u_file:
for audio_file in audio_files:
m3u_file.write("{}\n".format(audio_file))
print("Created playlist: {}".format(m3u_file_path))
def create_m3u_for_all_subfolders(root_folder, audio_extensions):
for root, dirs, files in os.walk(root_folder):
create_m3u_for_folder(root, audio_extensions)
# Usage
root_folder = r'D:\Musica' # Update this path
audio_extensions = ['.mp3', '.wav', '.flac', '.aac', '.wma'] # Add more extensions if needed
create_m3u_for_all_subfolders(root_folder, audio_extensions)