Created
June 29, 2022 04:47
-
-
Save glaszig/c90bf5463bf3b6e82846c56448ea2e2a to your computer and use it in GitHub Desktop.
generate m3u from directory
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
#!/usr/bin/env sh | |
# generates extended m3u for all media files in a directory. | |
# | |
# requirements: ffprobe (ffmpeg) | |
# usage: $0 path/to/media/files [playlist.m3u] | |
# author: [email protected] | |
# license: wtfpl - http://www.wtfpl.net/txt/copying/ | |
set -e | |
if [ ! -d "$1" ]; then | |
echo "first argument must be a directory" | |
echo "usage: $0 directory [index.m3u]" | |
exit 1 | |
fi | |
path="$1" | |
name=${2:-"index.m3u"} | |
m3u="$path/$name" | |
dotm3u="$path/.$name" | |
echo "#EXTM3U" > "$dotm3u" | |
echo "" >> "$dotm3u" | |
ls "$path" | while IFS= read -r f; do | |
if [ "$name" == "$f" ]; then continue; fi | |
i=$(ffprobe -v 0 -of json -show_format "$path/$f" | jq '.format') | |
a=$(echo "$i" | jq -r '.tags.artist') | |
t=$(echo "$i" | jq -r '.tags.title') | |
l=$(echo "$i" | jq -r '.duration | tonumber | ceil') | |
echo "#EXTINF:$l,$a - $t" >> "$dotm3u" | |
echo "$f" >> "$dotm3u" | |
echo "" >> "$dotm3u" | |
done | |
rm -f "$m3u" && mv "$dotm3u" "$m3u" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment