m3u8.sh (1100B)
1 #!/bin/sh 2 3 cwd=$(pwd) 4 playlist="${cwd##*/}" 5 test -e "$playlist.m3u8" && echo "$playlist.m3u8 already exists." 1>&2 && exit 1 || true 6 printf "#EXTM3U\r\n" > "$playlist".m3u8 7 songs=$(find "$cwd" -type f -name "*wav" -or -name "*mp3" -or -name "*m4a" -or -name "*ogg" -or -name "*aac" -or -name "*flac" | sort -u) 8 while read -r songname; do 9 song="${songname##*/}" 10 duration=$(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 "${song}" | sed "s|0*$||g" | sed "s|\.$||g") 11 artist=$(ffprobe -v error -show_entries format_tags=artist -of default=noprint_wrappers=1:nokey=1 "${song}") 12 [ -z "$artist" ] && artist="Unknown Artist" 13 title=$(ffprobe -v error -show_entries format_tags=title -of default=noprint_wrappers=1:nokey=1 "${song}") 14 [ -z "$title" ] && title="Unknown Title" 15 printf "#EXTINF:%s,%s - %s\r\n$song\r\n" "$duration" "$artist" "$title" >> "$playlist".m3u8 16 done <<< "$songs" 17 for cover in folder.jpg folder.png cover.jpg cover.png; do 18 test -e "$cover" && printf "#EXTIMG: front cover\r\nfolder.jpg\r\n" >> "$playlist.m3u8" && exit 0 || true 19 done