Skip to content

Commit

Permalink
Merge pull request #117 from Drazzilb08/nohl_bash-fixes
Browse files Browse the repository at this point in the history
Nohl bash fixes
  • Loading branch information
Drazzilb08 authored Mar 12, 2024
2 parents d2b737e + fa9d5cb commit 8cfac13
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 26 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.1.12
0.1.13
3 changes: 2 additions & 1 deletion config/config.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ poster_cleanarr:
ignore_collections:
- "Random Collection in assets you want to keep"
# If using poster_renamer with border_replacer, include the tmp folder that border_replacer uses
# This will double output in the logs but
source_dirs:
- /path/to/assets

Expand Down Expand Up @@ -454,6 +453,8 @@ bash_scripts:
include:
-
-
# Exclude certain movie/series folders from being searched
# NOTE: It must be exactly as the folder is listed in your file system
exclude:
-
-
Expand Down
55 changes: 31 additions & 24 deletions scripts/nohl_bash.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,6 @@
# License: MIT License
# ====================================================

# Define variables
source_dir='/path/to/media/'
log_dir=''

# Define folders inside your source_dir to include in the search
include=(
#"Media directories"
#"Movies"
#"TV Shows"
#"Anime"
)

# Define folders inside your source_dir to exclude from the search
exclude=(
#"Show Name"
#"Show Name"
#"Show Name"
)

# Define variables for webhook notifications
webhook=false
webhook=''
Expand Down Expand Up @@ -101,7 +82,7 @@ log_file() {
if [ -n "$DOCKER_ENV" ]; then
log_dir="${LOG_DIR/nohl_bash:-$parent_dir/logs/nohl_bash}"
else
log_dir="${log_dir:-$parent_dir/logs/nohl_bash}"
log_dir="${log_dir:-$parent_dir/logs}"
fi
# remove trailing slash from source_dir if it exists
source_dir=${source_dir%%/}
Expand Down Expand Up @@ -144,12 +125,32 @@ check_hardlinks() {
# Construct the find command to search for files with hard link count of 1
# Exclude folders listed in 'exclude_folders' and 'exclude'
# Include specific file extensions listed in 'file_extensions'
find "${source_dir}/${include[$i]}" -type d \( -name "${exclude_folders[*]}" -o -name "${exclude[*]}" \) -prune -o -type f -links 1 \( -iname "*.${file_extensions[0]}" -o -iname "*.${file_extensions[1]}" -o -iname "*.${file_extensions[2]}" -o -iname "*.${file_extensions[3]}" -o -iname "*.${file_extensions[4]}" -o -iname "*.${file_extensions[5]}" \) -printf "%P\n" | tee -a "$log_file"

# Use awk and sed to remove unwanted characters from the file name and print it to /tmp/nohl.tmp
find "${source_dir}/${include[$i]}" -type d \( -name "${exclude_folders[*]}" -o -name "${exclude[*]}" \) -prune -o -type f -links 1 \( -iname "*.${file_extensions[0]}" -o -iname "*.${file_extensions[1]}" -o -iname "*.${file_extensions[2]}" -o -iname "*.${file_extensions[3]}" -o -iname "*.${file_extensions[4]}" -o -iname "*.${file_extensions[5]}" \) -printf "%f\n" | awk -F"[" '{print $1}' | sed $'s/[^[:print:]\t]//g' | tee -a /tmp/nohl.tmp >/dev/null
done
find_command="find \"$source_dir/${include[$i]}\" -type f -links 1 \( "

for l in "${file_extensions[@]}"; do
find_command+=" -name '*.$l' -o"
done

# Remove the trailing '-o' from the find command and close the parentheses
find_command=${find_command%-o}
find_command+=" \)"

for j in "${exclude_folders[@]}"; do
find_command+=" -not -path '*/$j/*'"
done

for k in "${exclude[@]}"; do
find_command+=" -not -path '*/$k/*'"
done

# Print the find command to the console
# echo "Find command: $find_command" | tee -a "$log_file"

# Execute the find command and store the output in a temporary file
eval "$find_command" > /tmp/nohl.tmp
eval "$find_command" | tee -a "$log_file"
done
}

# Function to send notification
Expand Down Expand Up @@ -331,6 +332,12 @@ handle_options() {
:) echo "Option -$OPTARG requires an argument." >&2; display_help; exit 1 ;;
esac
done
# Update exclude array with -e option
# Add string to exclude array seperated by comma
# shellcheck disable=SC2128
if [ -n "$exclude" ]; then
IFS=',' read -r -a exclude <<< "$exclude"
fi
}

# Call the function
Expand Down

0 comments on commit 8cfac13

Please sign in to comment.