video & music playlist scripts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

32 lines
1.9 KiB

#!/bin/bash
#automatically backup music playlists & make playlists for various devices from ampache
set -o pipefail
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
source ${DIR}/yml_prs.sh
create_variables ${DIR}/config.yaml
#prepare the directories & take the backup
[[ -d ${playlists4all_playlist_dir} ]] || mkdir -p ${playlists4all_playlist_dir}/{archive,ampache,desktop,laptop,windows}
find ${playlists4all_playlist_dir}/ampache -type f -delete
sudo -u www-data php ${playlists4all_ampache_dir}/bin/write_playlists.inc ${playlists4all_playlist_dir}/ampache > /dev/null
rename 's/ /_/g' ${playlists4all_playlist_dir}/ampache/*.m3u
#only move them over if they're newer
for playlist in $(ls ${playlists4all_playlist_dir}/ampache); do
newest_playlist=$(ls -t ${playlists4all_playlist_dir}/archive/ | grep ${playlist} | head -n1)
#copy & archive if there have been changes
if [[ -z ${newest_playlist} || -n $(diff ${playlists4all_playlist_dir}/ampache/${playlist} ${playlists4all_playlist_dir}/archive/${newest_playlist}) ]] ; then
#copy over the playlists to the dirs
for dir in desktop laptop windows; do
cp -f ${playlists4all_playlist_dir}/ampache/${playlist} ${playlists4all_playlist_dir}/${dir};
done
#modify the playlists for each system
sed -i -e 's.home2.home/danny/atomic.g' ${playlists4all_playlist_dir}/laptop/${playlist}
sed -i -e 's.home2.home/daniel/atomic.g' ${playlists4all_playlist_dir}/desktop/${playlist}
#move old playlist to archive with date
cp -f ${playlists4all_playlist_dir}/ampache/${playlist} ${playlists4all_playlist_dir}/archive/${playlist}-$(date --iso-8601)
##copy to Library dir
echo "$(date --iso-8601=m) : Update to playlist ${playlist}. Copy to directories successful" >> ${playlists4all_log}
else echo "$(date --iso-8601=m) : No update to playlist ${playlist} detected. Skipping." >> ${playlists4all_log}
fi
done