Created
May 16, 2020 22:27
-
-
Save x011/4321c4f9010733f715d769590ea1f39b to your computer and use it in GitHub Desktop.
Generate m3u playlists from folders
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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