Skip to content

Commit

Permalink
Merge pull request #29 from madslundt/empty_plex_trash
Browse files Browse the repository at this point in the history
Empty plex trash
  • Loading branch information
madslundt authored Nov 21, 2017
2 parents 87657c5 + 3b6ec83 commit b182898
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 4 deletions.
4 changes: 2 additions & 2 deletions INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ git clone "https://github.com/madslundt/cloud-media-scripts.git" "${mypwd}"
sed -i "s|INSERT_CONFIG_FILE|${mypwd}/config|g" "${mypwd}/scripts/"*
sed -i "s|INSERT_CONFIG_FILE|${mypwd}/config|g" "${mypwd}/setup.sh"
sed -i "s|INSERT_ROOT_DIR|${mypwd}|g" "${mypwd}/config"
sed -i "s|bash mount.remote|bash ${mypwd}/scripts/mount.remote|g" "${mypwd}/scripts/mountcheck"
sed -i "s|bash umount.remote|bash ${mypwd}/scripts/umount.remote|g" "${mypwd}/scripts/mountcheck"
sed -i "s|bash mount.remote|bash ${mypwd}/scripts/mount.remote|g" "${mypwd}/scripts/"*
sed -i "s|bash umount.remote|bash ${mypwd}/scripts/umount.remote|g" "${mypwd}/scripts/"*
sed -i "s|logs/|${mypwd}/logs/|g" "${mypwd}/cron"
sed -i "s|scripts/|${mypwd}/scripts/|g" "${mypwd}/cron"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ These should be inserted into `crontab -e`.
- Mount at boot.
- Upload to cloud daily.
- Check to remove local content weekly (this only remove files depending on the option 'space', 'time' or 'instant'*).
- Check every hour if mount folder is running and if not it will unmount and remount (this checks if files exist in mount folder and does not check if rclone or plexdrive service is running)
- Check every hour if mount folder is running and if not it will unmount and remount (this checks if files exist in mount folder and does not check if rclone or plexdrive service is running). If mount is running it will empty trash in Plex.

_If you have a small local disk you may change upload and remove local content to do it more often._

Expand Down
7 changes: 7 additions & 0 deletions config
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ rclone_local_endpoint="local-crypt:"
google_drive_media_directory="" # Empty means media files are in root


###############################################################################
# Plex (empty trash)
###############################################################################
plex_url="http://localhost:32400"
plex_token=""


###############################################################################
# MISC. CONFIG
###############################################################################
Expand Down
2 changes: 1 addition & 1 deletion cron
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@reboot scripts/mount.remote &>> logs/mount.log
@daily scripts/cloudupload &>> logs/cloudupload.log
@weekly scripts/rmlocal &>> logs/rmlocal.log
@hourly scripts/mountcheck &>> logs/status.log
@hourly scripts/empty.trash &>> logs/emptytrash.log
45 changes: 45 additions & 0 deletions scripts/empty.trash
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/bin/bash
. "INSERT_CONFIG_FILE"

getSections() {
if [ -z "${plex_url}" ]; then
echo "Fill in plex url and plex token to retrieve sections. Aborting..."
exit 02
fi

sections=$(curl -s -G -L "${plex_url}/library/sections?X-Plex-Token=${plex_token}" | xpath -e "/MediaContainer/Directory/@key" 2>&1 | sed -re 's/-- NODE --//g'$
echo $sections
}
emptyTrash() {
bash mountcheck
cloud_dir="${cloud_encrypt_dir}"
if [ "$encrypt_media" -eq "0" ]; then
cloud_dir="${cloud_decrypt_dir}"
fi
if mountpoint -q "$cloud_dir" && mountpoint -q "$cloud_decrypt_dir" && mountpoint -q "${local_media_dir}"; then
sections=$(getSections)
if [ -z "${sections}" ]; then
echo "Could not get sections from ${plex_url} with the inserted token. Aborting..."
exit 02
fi
IFS="," read -r -a arr <<< "$sections"
for i in "${arr[@]}"
do
if [[ ! -z "${i}" ]]; then
echo "${plex_url}/library/sections/${i}/emptyTrash"
curl -s -G -L "${plex_url}/library/sections/${i}/emptyTrash?X-Plex-Token=${plex_token}"
fi
done
exit 0
else
echo "Mount is not up after mountcheck. Aborting..."
exit 02
fi
}
emptyTrash
1 change: 1 addition & 0 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ sudo apt-get install screen -y
sudo apt-get install unzip -y
sudo apt-get install fuse -y
sudo apt-get install golang -y
sudo apt-get install libxml-xpath-perl -y

if [ ! -f "${rclone_bin}" ]; then
if [ ! -d "${rclone_dir}" ]; then
Expand Down

0 comments on commit b182898

Please sign in to comment.