Created
December 10, 2023 16:33
-
-
Save rahul-gill/27e6014e294b210ad653b4d6030cbf8c to your computer and use it in GitHub Desktop.
Create playlist from nested directories of music
This file contains 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
@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% |
This file contains 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
#!/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