Skip to content

Instantly share code, notes, and snippets.

@metaory
Last active July 4, 2025 21:18
Show Gist options
  • Save metaory/c0e0652e4afab9e6541f6c8ae6341a5f to your computer and use it in GitHub Desktop.
Save metaory/c0e0652e4afab9e6541f6c8ae6341a5f to your computer and use it in GitHub Desktop.
Anime File Organizer

anime-org

Automatically parses anime filenames

extract series names, cleans up the naming conventions

organizes files into properly structured directories

Usage

simply run it in a directory with anime files

bash ./anime-org

or

chmod +x ./anime-org
./anime-org
#!/bin/bash
command -v "detox" >/dev/null || {
echo -e "\e[33;1m detox command not found"
echo -e "\e[0m https://github.com/dharple/detox \n"
echo -e "\e[36m sudo pacman -S detox \e[0m\n"
exit 1
}
:> /tmp/anime-org_pre
:> /tmp/anime-org_pos
[ "$1" == "--dry" ] && DRY=1
((DRY)) || detox -r .
commands='
s/^.*/\L&/;
s/v[0-9]{1}//g;
s/(480|540|720|1080).*//;
s/s[0-9]{2}e[0-9]{2}//g;
s/[0-9]{1,2}//g;
s/(puyasubs|commie|deadfish|horriblesubs|subsplease|erai-raws|ember|sakuracircle|mkv|end|\.|--|__|,|#)//g;
s/-_|_-/-/g;
s/^[-_]|^e-|[-_]$//g;
s/[-_]+$//g;
'
count=0
while read -r file; do
file="${file#./*}"
read -r norm < <(sed -E "$commands" <<<"$file")
echo "$file" >> /tmp/anime-org_pre
echo "$norm" >> /tmp/anime-org_pos
echo
echo -e "\e[32m :: $((++count))"
echo -e "\e[33m := $file"
echo -e "\e[36m :> $norm"
[ -z "$norm" ] && continue
((DRY)) || mkdir -p "$norm" &>/dev/null || :
((DRY)) || mv "$file" "${norm}/${file}"
done < <(find . -maxdepth 1 \
-type f \
-name '*.mkv' \
-or \
-name '*.mp4')
# vim:ft=bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment