Skip to content

Instantly share code, notes, and snippets.

@x011
Created May 16, 2020 22:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save x011/4321c4f9010733f715d769590ea1f39b to your computer and use it in GitHub Desktop.
Save x011/4321c4f9010733f715d769590ea1f39b to your computer and use it in GitHub Desktop.
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'
print(playlist_path)
#continue
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:
f.write(m3u)
print(f"wrote {playlist_path}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment