Skip to content

Instantly share code, notes, and snippets.

@rahul-gill
Created December 10, 2023 16:33
Show Gist options
  • Save rahul-gill/27e6014e294b210ad653b4d6030cbf8c to your computer and use it in GitHub Desktop.
Save rahul-gill/27e6014e294b210ad653b4d6030cbf8c to your computer and use it in GitHub Desktop.
Create playlist from nested directories of music
@echo off
if "%~2"=="" (
echo Usage: %0 ^<directory^> ^<playlist_name^>
exit /B 1
)
set "directory=%1"
set "playlist_name=%2"
if not exist "%directory%" (
echo Directory not found: %directory%
exit /B 1
)
set "audio_file_types=mp3 flac ogg wav m4a"
set "playlist_file=%directory%\%playlist_name%.m3u"
type nul > "%playlist_file%"
for %%i in (%audio_file_types%) do (
for /r "%directory%" %%f in (*%%i) do (
rem Calculate the relative path of the audio file
set "relative_path=%%~nf%%~xf"
setlocal enabledelayedexpansion
set "relative_path=!relative_path:%directory%\=!"
endlocal
rem Append the relative path to the playlist file
echo !relative_path!>> "%playlist_file%"
)
)
echo Playlist created: %playlist_file%
#!/bin/bash
if [ $# -lt 2 ]; then
echo "Usage: $0 <directory> <playlist_name>"
exit 1
fi
directory="$1"
playlist_name="$2"
if [ ! -d "$directory" ]; then
echo "Directory not found: $directory"
exit 1
fi
audio_file_types=("mp3" "flac" "ogg" "wav" "m4a")
playlist_file="${directory}/${playlist_name}.m3u"
touch "$playlist_file"
for audio_type in "${audio_file_types[@]}"; do
find "$directory" -type f -iname "*.${audio_type}" | while read -r audio_file; do
# Calculate the relative path of the audio file
relative_path="${audio_file#$directory/}"
# Append the relative path to the playlist file
echo "$relative_path" >> "$playlist_file"
done
done
echo "Playlist created: $playlist_file"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment