Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Generate m3u playlists from folders
import glob
all_dirs = glob.glob("/path/to/dir/with/subfolders/*/") # path to dir containing subdirs with musics
for mdir in all_dirs:
dir_name = mdir.split("/")[-2]
playlist_path = f'{mdir}{dir_name}.m3u'
m3u = "#EXTM3U\n"
for music in glob.iglob(f'{mdir}/*.*') :
music_name = music.split("/")[-1]
item = f"""#EXTINF:-1, {music_name}\n{music}\n"""
m3u += item
with open(playlist_path, 'w') as f:
print(f"wrote {playlist_path}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment