Skip to content

Instantly share code, notes, and snippets.

@emgeebee
Last active July 25, 2018 02:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emgeebee/73de596e14a0b86f0ff8f0adfd0d9d28 to your computer and use it in GitHub Desktop.
Save emgeebee/73de596e14a0b86f0ff8f0adfd0d9d28 to your computer and use it in GitHub Desktop.
OIFS="$IFS"
IFS=$'\t\n'
shopt -s extglob
FOLDER_ROOT=cds
function getPlaylists {
BASE=$1
GENRE=$2
PL_WILDCARD="${BASE} (*.m3u"
rm $PL_WILDCARD
find $GENRE -name "pl-new.txt" -print | while read FILE
do
echo ">> $FILE"
FILEBASE=`dirname "$FILE"`
cat $FILE | while read LINE; do
# echo "LINE $LINE"
NUMBER=`echo $LINE | tr '\t' ' ' | cut -d' ' -f2`
# echo "NUM $NUMBER"
TRACK=`ls ${FILEBASE}/@${NUMBER}*`
read -ra LISTS <<< `echo $LINE | tr '\t' ' ' | cut -d' ' -f1`
IFS=","
for LIST in ${LISTS[@]}; do
# echo "$LIST"
echo $TRACK
echo "${TRACK}" >> "${BASE} ($LIST).m3u"
done
IFS=$'\n'
done
done
}
for GENRE in ${FOLDER_ROOT}/* ; do
if [[ -d $GENRE ]]; then
echo "Sorting $GENRE"
BASE=`basename ${GENRE}`
# getPlaylists ${BASE} ${GENRE}
GENRE_ALL="${BASE} (All).m3u"
GENRE_LATEST="${BASE} (Latest).m3u"
find ${GENRE} -type f -name '*.mp3' -print0 | xargs -0 stat -f "%m %N" | sort -rn | head -100 | cut -f2- -d" " > "$GENRE_LATEST"
find ${GENRE} -type f -name '*.mp3' -print0 | xargs -0 stat -f "%m %N" | cut -f2- -d" " > "$GENRE_ALL"
fi
done
echo "Sorting ALL"
BASE="ALL"
getPlaylists ${BASE} ${FOLDER_ROOT}
GENRE_LATEST="${BASE} (Latest).m3u"
# find ${FOLDER_ROOT} -type f -name '*.mp3' -print0 | xargs -0 stat -f "%m %N" | sort -rn | head -100 | cut -f2- -d" " > "$GENRE_LATEST"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment