Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Bash script to create .m3u playlist files for all mp3s in subdirectories
#!/bin/bash
#
# bash script to create playlist files in music subdirectories
#
# Steve Carlson (steve@scarlson.co)
find . -type d |
while read subdir
do
rm -f *.m3u
for filename in "$subdir"/*.mp3
do
echo "${filename##*/}" >> ./"$subdir"/"${subdir##*/}.m3u"
done
done
@Tint1974

This comment has been minimized.

Copy link

@Tint1974 Tint1974 commented Oct 17, 2017

Hello,
Thank you for sharing, it is to date the code that is best for me to create my playlists. However, I would have a question:
I can not modify it so that it also processes, in addition to .aiff, extensions .aif .mp3 .loss ....
Indeed I manage a 4TB discotheque containing mainly aiff, but some discs are in other formats.
I hope very much that you will answer me,
Thank you in advance,
Regards,

Valentin

@scarlson

This comment has been minimized.

Copy link
Owner Author

@scarlson scarlson commented Dec 28, 2017

@Tint1974

Please see updated gist. Best of luck.

@4lg0r1thm

This comment has been minimized.

Copy link

@4lg0r1thm 4lg0r1thm commented Mar 5, 2018

Great!,

Quite clever boy. Very useful script... at least for me that have a headless notebook 32bits running Slax 7 for playing music mainly with SMplayer.

Thank you for sharing this. :-)

@R4nch0X

This comment has been minimized.

Copy link

@R4nch0X R4nch0X commented Aug 27, 2018

I have this error

playlist.sh: 13: playlist.sh: Bad substitution

Could you help me?

@rmlrml

This comment has been minimized.

Copy link

@rmlrml rmlrml commented Mar 31, 2019

I have this error

playlist.sh: 13: playlist.sh: Bad substitution

Could you help me?

I had a similar error:

./playlist.sh: line 13: [: too many arguments

and so I applied the fixes for line 13 given by shellcheck.net, and it worked. I also applied the fix for line 8. Here's the whole script with fixes: https://gist.github.com/rmlrml/c8147c8a697d58bba2f252dd0fc3b0db

@alexandre1985

This comment has been minimized.

Copy link

@alexandre1985 alexandre1985 commented Apr 6, 2019

find . -type f \( -name '*.mp3' -o -name '*.flac' -o -name '*.loss' -o -name '*.aiff' -o -name '*.aif' \) -printf "%P\n" > playlist.m3u

or, to get a sorted m3u playlist alphabetically:

find . -type f \( -name '*.mp3' -o -name '*.flac' -o -name '*.loss' -o -name '*.aiff' -o -name '*.aif' \) -printf "%P\n" | sort > playlist.m3u

@TuxNuX

This comment has been minimized.

Copy link

@TuxNuX TuxNuX commented Jan 2, 2021

very simply method

find /home/user/music -type f -iname "*.ogg" > /home/user/Documents/playlist.m3u

then open xmms or similate classify in alpahabetic order if you want then save and here is a superb playlist

be careful put the entire paths

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment