Last active
August 26, 2019 19:03
-
-
Save hazcod/97b64f048158e165a25a to your computer and use it in GitHub Desktop.
Uploader script to upload media to acd_cli via cron
This file contains hidden or 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 | |
#set -e | |
#set -x | |
# where to log | |
log="/var/log/uploader.log" | |
# where to keep our PIDs | |
tmp="/tmp/uploader" | |
# where is the unencrypted encfs | |
input_uncrypt="/home/media/data/uploadme" | |
# where is the encrypted encfs | |
input="/home/media/data/uploading" | |
# where is the media located (encrypted) | |
media_crypt="/tmp/.media" | |
movies="xxxxxxxxxxxxxxxxx" | |
series="xxxxxxxxxxxxxxxxx" | |
music="xxxxxxxxxxxxxxxxx" | |
mkdir -p "$tmp" | |
type="" | |
if (($(($(ps -aux | grep uploader.sh | wc -l)-1)) > 4)); then | |
echo "Waiting for scripts to finish.." | tee -a "$log" | |
exit 1 | |
fi | |
case "$1" in | |
movies) | |
type="$movies" | |
;; | |
series) | |
type="$series" | |
;; | |
music) | |
type="$music" | |
;; | |
*) | |
echo "Usage: uploader.sh (movies|series|music)" | |
exit 1 | |
esac | |
if [ ! "$2" == "0" ]; then | |
echo "Downloading subs" | tee -a "$log" | |
/usr/local/bin/subliminal download -l nl "$input_uncrypt/$1" 2>&1 | tee -a "$log" | |
fi | |
for dir in `find "$input/$type/" -mindepth 1 -maxdepth 1 -type d`; do | |
echo "Starting uploader" | tee -a "$log" | |
echo "Dir: $dir" | tee -a "$log" | |
find "$input/$type/." -type f -exec rename -v -f 's/\(\d\)+//g' {} \; | |
if [ "$1" == "series" ]; then | |
show="$dir" | |
showname=$(basename "$show") | |
echo "Looking at show $showname" | tee -a "$log" | |
for season in `find "$dir" -mindepth 1 -maxdepth 1 -type d`; do | |
season_name=$(basename "$season") | |
echo "Looking at season $season_name" | tee -a "$log" | |
for epi in `find "$season" -mindepth 1 -maxdepth 1 -type f`; do | |
sha=$(echo "$epi" | sha1sum | awk '{print $1}') | |
echo "Looking at episode $epi ($sha)" | tee -a "$log" | |
if [ ! -f "$tmp/$sha" ]; then | |
touch "$tmp/$sha" | |
if [ ! -d "$media_crypt/$series/$showname" ]; then | |
echo "Creating show directory on server" | tee -a "$log" | |
/usr/local/bin/acdcli mkdir "/$series/$showname" | |
fi | |
if [ ! -d "$media_crypt/$series/$showname/$season_name" ]; then | |
echo "Creating season directory on server" | tee -a "$log" | |
/usr/local/bin/acdcli mkdir "/$series/$showname/$season_name" | |
fi | |
epi_name=$(basename "$epi") | |
if /usr/local/bin/acdcli upload -o "$epi" "/$type/$showname/$season_name/"; then | |
echo "Uploaded $season_name/$epi_name for $showname" | tee -a "$log" | |
rm "$epi" | |
else | |
echo "Failed uploading $showname/$season_name/$epi_name" | tee -a "$log" | |
fi | |
rm "$tmp/$sha" | |
else | |
echo "skip" | |
fi | |
done | |
done | |
# Check if there are big files left | |
smallfiles=$(find "$dir" -type f -size +100k -print) | |
bigfiles=$(find "$dir" -type f -size +500M -print) | |
if [ ! -z "$smallfiles" ] && [ -z "$bigfiles" ]; then | |
echo "No more media files for $showname , removing metadata from disk.." | tee -a "$log" | |
find "$dir" -type f -exec rm {} \; | |
fi | |
else | |
echo "Looking at $dir" | tee -a "$log" | |
sha=$(echo "$dir" | sha1sum | awk '{print $1}') | |
echo "Hash: $sha" | tee -a "$log" | |
if [ ! -f "$tmp/$sha" ]; then | |
echo "Processing, no pid found" | tee -a "$log" | |
touch "$tmp/$sha" | |
if /usr/local/bin/acdcli upload -o "$dir" "/$type"; then | |
echo "Uploaded successfully! Removing $dir" | tee -a "$log" | |
rm -r "$dir" | |
fi | |
echo "Removing $tmp/$sha and syncing.." | tee -a "$log" | |
rm "$tmp/$sha" | |
else | |
echo "Skipping" | tee -a "$log" | |
fi | |
fi | |
done |
Hey @zjpleau,
- This assumes that your encfs mount on $input (="/home/media/data/uploading") is indeed the encrypted view
- Exactly
- What does /var/log/uploader.log say? You movie should be like $input/Moviename/Movie.mp4, it goes 1 folder deep for movies and two folders deep for series.
How many parallel transfers is it doing?
i tryd this
#!/bin/bash
FOLDER="/root/Daten"
inotifywait -r -m $FOLDER -e close_write -e moved_to |
while read path action file; do
(
acd_cli ul -x 4 -r 4 -f -rsf $FOLDER/ /
) &
done
But it try allways to upload all files 4 times, not 4 different files at the same time
i see you call every file on its own, maybe a better way
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey, I have some questions about the usage of your script.
Thanks!