-
-
Save scarlson/944860 to your computer and use it in GitHub Desktop.
#!/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 |
Please see updated gist. Best of luck.
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. :-)
I have this error
playlist.sh: 13: playlist.sh: Bad substitution
Could you help me?
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
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
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
I am using a jellyfin server to play my media and it shows the newest playlists first.
I'm using this code, but I'm struggling to modify it, so that; if there is a pre-existing .m3u playlist that has previously been created by the scipt then it will skip that folder.
Thanks in advance
Ok - I re-read your code and hacked it like this
if [[ -f ./"$subdir"/"${subdir##/}.m3u" ]]
then
echo "File "$subdir"/.m3u already exists, skipping"
else
echo would build for $subdir
for filename in "$subdir"/*
do
if [ ${filename: -4} == ".mp3" ] || [ ${filename: -5} == ".flac" ] || [ ${filename: -5} == ".loss" ] || [ ${filename: -5} == ".aiff" ] || [ ${filename: -4} == ".aif" ]
then
echo "${filename##/}" >> ./"$subdir"/"${subdir##/}.m3u"
fi
Then final version of my hacked script is below
#!/bin/bash
#
# bash script to create playlist files in music subdirectories
#
# Steve Carlson (stevengcarlson@gmail.com)
find . -type d |
while read subdir
do
if [[ -f ./"$subdir"/"${subdir##*/}.m3u" ]]
then
echo "File "$subdir"/*.m3u already exists, skipping"
else
echo would build for $subdir
for filename in "$subdir"/*
do
if [ ${filename: -4} == ".mp3" ] || [ ${filename: -5} == ".flac" ] || [ ${filename: -5} == ".loss" ] || [ ${filename: -5} == ".aiff" ] || [ ${filename: -4} == ".aif" ]
then
echo "${filename##*/}" >> ./"$subdir"/"${subdir##*/}.m3u"
fi
done
fi
done
Thanks.
Hello everyone, based on this script and this other I created a function that wraps the main code and expect as arguments a flag [-r/-s] and a directory allowing it to have 2 modes: (-r) create one playlist per subdirectory and (-s) create a single playlist that includes all subdirectories' songs. With this script I maintain my playlists easily.
You can check it here: https://gitlab.com/-/snippets/2513870
Hello everyone, based on this script and this other I created a function that wraps the main code and expect as arguments a flag [-r/-s] and a directory allowing it to have 2 modes: (-r) create one playlist per subdirectory and (-s) create a single playlist that includes all subdirectories' songs. With this script I maintain my playlists easily. You can check it here: https://gitlab.com/-/snippets/2513870
i try to use your scripts, but i get an error message because the script goes to Homes/username/ Music. I want to change it to search in my music library which is not in the Home/username/Music directory. How can i change the script to search in whatever folder i want?
Hello everyone, based on this script and this other I created a function that wraps the main code and expect as arguments a flag [-r/-s] and a directory allowing it to have 2 modes: (-r) create one playlist per subdirectory and (-s) create a single playlist that includes all subdirectories' songs. With this script I maintain my playlists easily. You can check it here: https://gitlab.com/-/snippets/2513870
i try to use your scripts, but i get an error message because the script goes to Homes/username/ Music. I want to change it to search in my music library which is not in the Home/username/Music directory. How can i change the script to search in whatever folder i want?
give this a try https://github.com/mattiasghodsian/PhinellyPort
Hello everyone, based on this script and this other I created a function that wraps the main code and expect as arguments a flag [-r/-s] and a directory allowing it to have 2 modes: (-r) create one playlist per subdirectory and (-s) create a single playlist that includes all subdirectories' songs. With this script I maintain my playlists easily. You can check it here: https://gitlab.com/-/snippets/2513870
i try to use your scripts, but i get an error message because the script goes to Homes/username/ Music. I want to change it to search in my music library which is not in the Home/username/Music directory. How can i change the script to search in whatever folder i want?
give this a try https://github.com/mattiasghodsian/PhinellyPort
Thanks, Mattias
In the coming weeks, I will update my music library, and then I will try your script.
i will come back to you when I try it.
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