Files

176 lines
4.3 KiB
Bash
Raw Permalink Normal View History

2026-04-14 23:55:21 +02:00
#!/bin/bash
IFS=$'\n'; set -f
STUFF="/torrent/multimedia/Filme/New/"
ASSUMEYES=false
FILTER_MODE=false
FILE_PATH="/torrent/complete/"
usage() {
printf "Usage:
-y\ty Mode
-m\tmega Mode
-v\tCopy to ~/Videos
-help\tDisplay this\n"
}
get_config() {
while [[ ${1:0:1} == - ]]; do
echo "Param: $1"
[[ $1 == -help ]] && {
echo "Help"
usage;
exit;
};
2026-07-16 10:42:30 +02:00
[[ $1 == -f ]] && {
echo "Dest: /torrent/Films"
STUFF="/torrent/Films/"
shift 1
continue
};
2026-04-14 23:55:21 +02:00
[[ $1 == -v ]] && {
echo "Dest: Videos"
STUFF="/data/Videos/"
shift 1
continue
};
[[ $1 == -y ]] && {
echo "y Mode"
ASSUMEYES=true
shift 1
continue
};
[[ $1 == -m ]] && {
echo "mega Mode"
FILE_PATH="/torrent/mega/"
shift 1
continue
};
[[ $1 == -l ]] && {
echo "List Mode"
LIST_MODE=true
shift 1
continue
};
[[ $1 == -f ]] && {
echo "Filter Mode"
FILTER_MODE=true
shift 1
continue
};
echo "Parameter $1 discarded"
usage
exit
done
}
get_config "$@"
LIST=($(sudo /home/lucas/scripts/serverhost/deluge_user_cmd.sh ls ${FILE_PATH}))
if [ ${#LIST[@]} -eq 0 ]; then
echo "Nothing to Copy/Delete"
exit
fi
if [ "${LIST_MODE}" == "true" ]; then
for i in "${!LIST[@]}"; do
files=${LIST[$i]}
echo "Copy? ${files} (y/*)"
read -n 10 ans
if [ "$ans" != "y" ]; then
echo "Dont copy $files"
unset 'LIST[i]'
fi
done
echo "NEW LIST:"
echo "${LIST[*]}"
fi
if [ ${#LIST[@]} -eq 0 ]; then
echo "Nothing to Copy/Delete"
exit
fi
if [ "${ASSUMEYES}" == "false" ]; then
echo "Copy? (y/*)"
echo "${LIST[*]}"
read -n 10 ans
else
echo "Copy to Films:"
echo "${LIST[*]}"
ans="y"
fi
if [ "$ans" == "y" ]; then
for files in ${LIST[@]}; do
#sudo /home/lucas/scripts/serverhost/deluge_user_cmd.sh cp -dr ${FILE_PATH}$(printf "%q" "$files") "${STUFF}"
sudo /home/lucas/scripts/serverhost/deluge_user_cmd.sh cp -dr --no-preserve=mode ${FILE_PATH}${files} ${STUFF}
if [ $? -ne 0 ]; then fail=true; echo "Copy Failure"; exit; fi
done
printf "Torrents Copied\n"
else
printf "Nothing Copied\n"
fi
if [ "${ASSUMEYES}" == "false" ]; then
echo "Rename? (y/*)"
echo "${LIST[*]}"
read -n 10 ans
else
ans="y"
fi
printf "Change Ownership\n"
sudo /home/lucas/Documents/Dokumente/Projekte/Server/scripts/serverhost/chown_tv.sh
if [ "$ans" == "y" ]; then
for files in ${LIST[@]}; do
echo "Rename $files"
filepath="${STUFF}${files}"
if [ -e "${filepath}" ]; then
echo "${filepath} exists"
sudo /home/lucas/scripts/serverhost/tvbitch_user_cmd.sh chmod -R 777 "${filepath}"
/home/lucas/.venv_general/bin/python3 /home/lucas/scripts/rename_episodes.py -d -rep -p "${filepath}"
else
echo "${filepath} neither Directory nor regular file"
fi
done
printf "Rename Complete\n"
else
printf "Nothing Renamed\n"
fi
if [ "${FILTER_MODE}" == "true" ]; then
for files in ${LIST[@]}; do
echo "Filter $files"
filepath="${STUFF}${files}"
if [ -e "${filepath}" ]; then
echo "Filter Video? (y/*)"
echo "${files}"
read -n 10 ans
if [ "$ans" == "y" ]; then
echo "Filter ${files}"
sudo /home/lucas/scripts/serverhost/tvbitch_user_cmd.sh chmod -R 777 "${filepath}"
if /home/lucas/.venv_general/bin/python3 /home/lucas/scripts/ffmpeg_handling.py filter-audio ${filepath} -o \
"${STUFF}_${files}" ; then
echo "Filter sucessfull"
mv "${STUFF}_${files}" "${STUFF}${files}"
fi
fi
else
echo "${filepath} neither Directory nor regular file"
fi
done
printf "Filter Complete\n"
fi
if [ "${ASSUMEYES}" == "false" ]; then
echo "Delete? (y/*)"
echo "${LIST[*]}"
read -n 10 ans
else
ans="y"
fi
if [ "$ans" == "y" ]; then
for files in ${LIST[@]}; do
echo "Delete $files"
sudo /home/lucas/scripts/serverhost/deluge_user_cmd.sh rm -dr ${FILE_PATH}${files}
done
printf "Torrents Removed\n"
else
printf "Nothing Removed\n"
fi
unset IFS; set +f
syncNC -m -del