Created
July 26, 2019 04:44
-
-
Save rkok/08ccd04790cf38ec815d235d8d1dd33f to your computer and use it in GitHub Desktop.
Extended m3u generator
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 | |
################################################################# | |
# mkem3u.sh - Extended m3u generator | |
# Usage: | |
# ./mkm3u.sh | |
# Setup: | |
# 1. Install dependencies: | |
# mp3info - http://ibiblio.org/mp3info/ | |
# id3tool - http://nekohako.xware.cx/id3tool/ | |
# 2. Supply INPATHS. Paths which are relative to | |
# this script will result in relative paths in the m3u | |
# 3. (Optional) Edit file extensions "mp3|flac|xm|s3m|mod|it" | |
################################################################# | |
INPATHS=' | |
path1 | |
path2 | |
' | |
TMPFILE='all.m3u.tmp' | |
OUTFILE='all.m3u' | |
FILES= | |
echo -e "#EXTM3U\n" > $TMPFILE | |
for INPATH in $INPATHS; do | |
echo "[$(date)] Finding mp3/flac/etc in $INPATH ..." | |
FILES="$FILES"$'\n'"$(find $INPATH | grep -iE '\.(mp3|flac|xm|s3m|mod|it)$')" | |
done | |
echo "Processing files ..." | |
NFILES="$(echo "$FILES" | wc -l)" | |
CURFILENO=0 | |
IFS=$'\n'; for FILE in $FILES; do | |
CURFILENO=$((CURFILENO+1)) | |
echo -ne "$CURFILENO/$NFILES\r" | |
if [[ "$FILE" != *mp3 ]]; then | |
continue | |
fi | |
DURATION="$(mp3info -p %S "$FILE" 2>/dev/null)" | |
ARTIST_TITLE="$(id3tool "$FILE" 2>/dev/null | head -3 | tail -2 | grep -vE '^(Filename|No ID3 Tag)' | sed -r 's/.*\t+(.*)/\1 @@@/g' | sed -r 's/ {2,}//g' | tr -d '\n' | sed -r 's/(.*) ?@@@(.*) ?@@@/\2 - \1/g')" | |
echo "#EXTINF:$DURATION,$ARTIST_TITLE" >> $TMPFILE | |
echo -e "$FILE\n" >> $TMPFILE | |
done | |
echo | |
echo "[$(date)] Saving to $OUTFILE" | |
mv $TMPFILE $OUTFILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment