Add 'anime_scripts/jellyfin-namer-new.sh'
This commit is contained in:
parent
b652d20591
commit
97f898a603
65
anime_scripts/jellyfin-namer-new.sh
Normal file
65
anime_scripts/jellyfin-namer-new.sh
Normal file
@ -0,0 +1,65 @@
|
||||
#!/bin/bash
|
||||
|
||||
#Check if requests is installed, and if not install it
|
||||
python -c "import requests"
|
||||
if [[ "$?" == "1" ]]; then
|
||||
apt update
|
||||
apt install python-requests
|
||||
fi
|
||||
|
||||
#Gets the last part of the current directory
|
||||
function get_bottom_dir() {
|
||||
IFS='/';
|
||||
read -ra ADDR <<< "$PWD";
|
||||
echo "${ADDR[-1]}";
|
||||
IFS=' ';
|
||||
}
|
||||
|
||||
#Removes braces, parenteres along with everything in them and strips leading and trailing whitespace
|
||||
function name_clean() {
|
||||
local _out=$(echo "$1" | sed -e 's/\[[^][]*\]//g');
|
||||
_out=$(echo "$_out" | sed -e 's/([^()]*)//g');
|
||||
_out=$(echo "$_out" | sed 's/_/ /g');
|
||||
echo $(echo "$_out" | xargs);
|
||||
}
|
||||
|
||||
function get_series() {
|
||||
local sanitized_name=$(name_clean "$1");
|
||||
local output=$(python /scripts/seasons.py "$sanitized_name");
|
||||
if [[ "$?" != "0" ]]; then
|
||||
return 1;
|
||||
fi
|
||||
|
||||
IFS="|";
|
||||
read -ra STR <<< "$output"
|
||||
|
||||
TITLE_ROMAJI="${STR[0]}";
|
||||
TITLE_ENGLISH="${STR[1]}";
|
||||
SEASON="${STR[2]}";
|
||||
IFS=" ";
|
||||
return 0;
|
||||
}
|
||||
cd "$1";
|
||||
|
||||
bottom_dir=$(get_bottom_dir);
|
||||
cleaned_bottom_dir=$(name_clean "$bottom_dir");
|
||||
get_series "$cleaned_bottom_dir";
|
||||
if [[ "$?" == "0" ]]; then
|
||||
if [[ -d "$JF_DIR/$TITLE_ROMAJI" ]]; then
|
||||
cleaned_dir="$TITLE_ROMAJI/Season $SEASON";
|
||||
elif [[ -d "$JF_DIR/$TITLE_ENGLISH" ]]; then
|
||||
cleaned_dir="$TITLE_ENGLISH/Season $SEASON";
|
||||
else
|
||||
cleaned_dir="$TITLE_ROMAJI/Season $SEASON";
|
||||
fi
|
||||
else
|
||||
cleaned_dir="$cleaned_bottom_dir";
|
||||
fi
|
||||
mkdir -p "$JF_DIR/$cleaned_dir";
|
||||
|
||||
for i in *; do
|
||||
cleaned_name=$(name_clean "$i");
|
||||
ln "$PWD/$i" "$JF_DIR/$cleaned_dir/$cleaned_name" >/dev/null 2>/dev/null;
|
||||
done;
|
||||
|
||||
echo "$JF_DIR/$cleaned_dir";
|
Loading…
x
Reference in New Issue
Block a user