Skip to content

Instantly share code, notes, and snippets.

@doob187
Created August 3, 2020 15:08
Show Gist options
  • Save doob187/05cc7d3154f12d4185619ced1b94eac9 to your computer and use it in GitHub Desktop.
Save doob187/05cc7d3154f12d4185619ced1b94eac9 to your computer and use it in GitHub Desktop.
remove unwanted
#!/usr/bin/with-contenv bash
# shellcheck shell=bash
# Copyright (c) 2020, MrDoob
# All rights reserved.
######## FUNCTIONS ##########
## adjust the folder downloadpath=/move
## adjust the line TARGET_FOLDER ;)
downloadpath=/move
cleaning() {
while true; do
garbage
sleep 10
done
}
function garbage() {
#################
# script by pho #
#################
# basic settings
TARGET_FOLDER="${downloadpath}/{nzb,torrent,sabnzbd,nzbget,qbittorrent,rutorrent,deluge,jdownloader2}/"
# find files in this folders
FIND_SAMPLE_SIZE='-size -188M'
# advanced settings
FIND=$(which find)
FIND_BASE_CONDITION_WANTED='-type f -amin +600'
FIND_BASE_CONDITION_UNWANTED='-type f'
FIND_MINDEPTH='-mindepth 2'
FIND_ADD_NAME='-o -iname'
FIND_DEL_NAME='! -iname'
FIND_ACTION='-not -path "**_UNPACK_**" -delete > /dev/null 2>&1'
command="${FIND} ${TARGET_FOLDER} ${FIND_MINDEPTH} ${FIND_BASE_CONDITION_WANTED} ${FIND_SAMPLE_SIZE} ${FIND_ACTION}"
eval "${command}"
WANTED_FILES=(
'*.mkv'
'*.mpg'
'*.mpeg'
'*.avi'
'*.mp4'
'*.mp3'
'*.flac'
'*.srt'
'*.idx'
'*.sub'
'*.mp4'
)
UNWANTED_FILES=(
'*.m2ts'
'abc.xyz.*'
'*.m3u'
'Top Usenet Provider*'
'house-of-usenet.info'
'*.html~'
'*KLICK IT*'
'Click.rar'
'*.1'
'*.2'
'*.3'
'*.4'
'*.5'
'*.6'
'*.7'
'*.8'
'*.9'
'*.0'
'*.10'
'*.11'
'*.12'
'*.13'
'*.14'
'*.15'
'*.gif'
'*sample.*'
'*.sh'
'*.pdf'
'*.doc'
'*.docx'
'*.xls'
'*.xlsx'
'*.xml'
'*.html'
'*.htm'
'*.exe'
'*.nzb'
)
#Folder Setting
condition="-iname '${UNWANTED_FILES[0]}'"
for ((i = 1; i < ${#UNWANTED_FILES[@]}; i++))
do
condition="${condition} ${FIND_ADD_NAME} '${UNWANTED_FILES[i]}'"
done
command="${FIND} ${TARGET_FOLDER} ${FIND_MINDEPTH} ${FIND_BASE_CONDITION_UNWANTED} \( ${condition} \) ${FIND_ACTION}"
eval "${command}"
for ((i = 0; i < ${#WANTED_FILES[@]}-1; i++))
do
condition2="${condition2} ${FIND_DEL_NAME} '${WANTED_FILES[i]}'"
done
command="${FIND} ${TARGET_FOLDER} ${FIND_MINDEPTH} ${FIND_BASE_CONDITION_WANTED} \( ${condition2} \) ${FIND_ACTION}"
eval "${command}"
}
# keeps the function in a loop
skrapball=0
while [[ "$skrapball" == "0" ]]; do cleaning; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment