split configs into two systems...
This commit is contained in:
153
workstation/scripts/manage-library.sh
Executable file
153
workstation/scripts/manage-library.sh
Executable file
@@ -0,0 +1,153 @@
|
||||
#! /usr/bin/env nix-shell
|
||||
#! nix-shell -i bash -p bash gum fd ripgrep exa trashy zip unzip
|
||||
|
||||
root_directories=(
|
||||
~/Multimedia/Library/Comics
|
||||
~/Multimedia/Library/Manga
|
||||
~/Multimedia/Library/Webtoons
|
||||
)
|
||||
|
||||
newname() {
|
||||
echo "$1" | sed -E "s/$2/$3/g"
|
||||
}
|
||||
|
||||
separator() {
|
||||
gum style --foreground 7 _________________________
|
||||
}
|
||||
announce_changes() {
|
||||
echo "Renaming:"
|
||||
gum style --foreground 1 "$1"
|
||||
echo "Into:"
|
||||
gum style --foreground 2 "$2"
|
||||
separator
|
||||
}
|
||||
|
||||
rename_file() {
|
||||
while IFS= read -r file; do
|
||||
local original_name
|
||||
original_name=$(basename "$file")
|
||||
local new_name
|
||||
new_name=$(newname "$(basename "$file")" "$2" "$3")
|
||||
|
||||
announce_changes "$original_name" "$new_name"
|
||||
command mv -n "$(dirname "$file")"/{"$original_name","$new_name"}
|
||||
done < <(fd "$1" --absolute-path -tf -s "${root_directories[@]}")
|
||||
}
|
||||
|
||||
rename_directory() {
|
||||
while IFS= read -r dir; do
|
||||
local new_name
|
||||
new_name=$(newname "$(basename "$dir")" "$2" "$3")
|
||||
local new_dir
|
||||
new_dir=$(dirname "$dir")/$new_name
|
||||
|
||||
announce_changes "$dir" "$new_dir"
|
||||
echo "Processing..."
|
||||
if [ ! -d "$new_dir" ]; then
|
||||
echo "$(basename "$new_dir") doesn't exist. Creating it."
|
||||
command mkdir -p "$new_dir"
|
||||
fi
|
||||
if [ -d "$new_dir" ]; then
|
||||
echo "$(basename "$new_dir") has been created!, moving the following files:"
|
||||
exa "$dir"
|
||||
fd . "$dir" -x mv -n {} "$(realpath "$new_dir")"
|
||||
fi
|
||||
separator
|
||||
done < <(fd "$1" --absolute-path -td -s "${root_directories[@]}")
|
||||
}
|
||||
|
||||
# Capitalize Special words
|
||||
words=(special tpb full annual)
|
||||
Words=(Special TPB Full Annual)
|
||||
counter=0
|
||||
for word in "${words[@]}"; do
|
||||
while IFS= read -r file; do
|
||||
new_name=$(newname "$(basename "$file")" "$word" "${Words[$counter]}")
|
||||
echo "Inproper capitalization of the word"
|
||||
gum style --foreground 1 "$word"
|
||||
echo "adjusting it into"
|
||||
gum style --foreground 2 "${Words[$counter]}"
|
||||
announce_changes "$(basename "$file")" "$new_name"
|
||||
command mv -n "$(dirname "$file")"/{"$(basename "$file")","$new_name"}
|
||||
done < <(fd "$word" --absolute-path -tf -s "${root_directories[@]}")
|
||||
counter=$((counter + 1))
|
||||
done
|
||||
|
||||
# Rename Year files
|
||||
# set regex_year_grep "\([[:digit:]]{4}\)"
|
||||
# set regex_year_string "(\()(\d{4})(\))"
|
||||
# rename_directory $regex_year_grep $regex_year_string \$2
|
||||
# rename_file $regex_year_grep $regex_year_string \$2
|
||||
|
||||
# Rename #_ downloads
|
||||
regex_hashtag="#_"
|
||||
rename_directory $regex_hashtag $regex_hashtag "#"
|
||||
rename_file $regex_hashtag $regex_hashtag "#"
|
||||
|
||||
rename_keywords() {
|
||||
# Followed by digit
|
||||
local regex_digit_fd="$1 \d+"
|
||||
local regex_digit="($1 )([[:digit:]]+)"
|
||||
rename_directory "$regex_digit_fd" "$regex_digit" "\1#\2"
|
||||
rename_file "$regex_digit_fd" "$regex_digit" "\1#\2"
|
||||
# Without digit
|
||||
regex="#$1"
|
||||
rename_directory "$regex" "$regex" "$1"
|
||||
rename_file "$regex" "$regex" "$1"
|
||||
}
|
||||
|
||||
rename_keywords TPB
|
||||
rename_keywords Special
|
||||
rename_keywords Annual
|
||||
|
||||
# Rename #Full
|
||||
rename_directory " #Full" " #Full" ""
|
||||
rename_file " #Full" " #Full" ""
|
||||
|
||||
# Rename double space
|
||||
rename_directory " " " " " "
|
||||
rename_file " " " " " "
|
||||
|
||||
# Fix names
|
||||
wrongnames=(
|
||||
"Dr. Stone"
|
||||
i-dont-want-this-kind-of-hero
|
||||
pure-of-heart
|
||||
scoob-and-shag
|
||||
stick-n-poke
|
||||
"Houseki no Kuni"
|
||||
"Gantz E"
|
||||
"Gantz G"
|
||||
)
|
||||
rightname=(
|
||||
"Dr. STONE"
|
||||
"I DON'T WANT THIS KIND OF HERO"
|
||||
"Pure of Heart"
|
||||
"Scoob and Shag"
|
||||
"Stick n' Poke"
|
||||
"Land of the Lustrous"
|
||||
"Gatz:E"
|
||||
"Gantz:G"
|
||||
)
|
||||
counter=0
|
||||
for wrongname in "${wrongnames[@]}"; do
|
||||
rename_directory "$wrongname" "$wrongname" "${rightname[$counter]}"
|
||||
rename_file "$wrongname" "$wrongname" "${rightname[$counter]}"
|
||||
counter=$((counter + 1))
|
||||
done
|
||||
|
||||
# Merge TPB (Part X) files
|
||||
while IFS= read -r file; do
|
||||
new_name=$(newname "$(basename "$file" .cbz)" "TPB \(Part [[:digit:]]+\)" TPB)
|
||||
extract_dir=$(realpath "$(dirname "$file")"/"$new_name")
|
||||
if [ ! -d "$extract_dir" ]; then
|
||||
mkdir -p "$extract_dir"
|
||||
fi
|
||||
unzip "$file" -d "$extract_dir"/"$(basename "$file" .cbz)"
|
||||
cd "$extract_dir" || exit
|
||||
zip -r "$(realpath "$(dirname "$file")")"/"$new_name"\.cbz ./
|
||||
trash "$file"
|
||||
trash "$extract_dir"/"$(basename "$file" .cbz)"
|
||||
done < <(fd "Part \d+" --absolute-path -tf -s "${root_directories[@]}")
|
||||
|
||||
fd . --absolute-path -td -te "${root_directories[@]}" -x trash {}
|
||||
Reference in New Issue
Block a user