Tag Archives: copy

Sync or copy playlist (.m3u) files

sync_playlist.sh

#!/bin/bash

PLAYLISTS=( rock_tracks.m3u jazz_songs.m3u shazam_01.m3u best_albums.m3u )
ROOTDIR=/home/user/Music/Playlists
DSTDIR=/home/user/Board
CMD="/usr/bin/rsync --progress -u"
TMP=`pwd`/.temp

mkdir $TMP

for i in "${PLAYLISTS[@]}"
do
 grep -v "^#" $ROOTDIR/$i | while read tracks; do du -k "${tracks}" >> $TMP/${i}.sum; done
done

cd $TMP
for i in *.sum
do
 FILE=`echo ${i} | sed s/.sum//g`
 SUM=`cat ${i} | awk '{total=total+$1} END {print total}' | awk '{ human = $1 / 1024} END {print human" M"}'`
 echo -e "$FILE == >> $SUM"
done
cd ..

echo -e "Do you want to synchronize the playlists? (y/n)"
read answer

if [ $answer = y ]
then
 for i in ${PLAYLISTS[@]}
 do
 DIRNAME=`echo ${i} | sed s/.m3u//g`
 mkdir -p $DSTDIR/"${DIRNAME}"
 grep -v "^#" $ROOTDIR/$i | while read tracks; do $CMD "${tracks}" $DSTDIR/"${DIRNAME}"; done
 ls -tr $DSTDIR/"${DIRNAME}" > $TMP/${i}
 mv $TMP/${i} $DSTDIR/"${DIRNAME}"
 done
fi

if [ $answer = n ]
then
 echo -e "OK"
fi

rm -r $TMP
Advertisements