Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # Script for organize movies.
- # Put all movies in one folders using this format for the movi folder
- # /<YYYY> - <MOVIE NAME>/
- #
- # Ex:
- #
- # /All movies/1999 - Matrix
- # /All movies/2003 - Matrix Reloaded
- #
- # Author : Enderson Maia <endersonmaia _AT- gmail -DOT_ com>
- #
- # TODO - use sed istead of cut
- # Configureation
- PWD=$(pwd)
- ALL_PATH="All movies"
- BY_YEAR_PATH="By year"
- BY_LETTER_PATH="By letter"
- ##############################################################################
- # BEGIN
- YEARS=$(ls -1 $ALL_PATH | grep '^[0-9]' | cut -d- -f1 | sort -u)
- LETTERS=$(ls -1 $ALL_PATH | grep '^[0-9]' | cut -d- -f2 | sed 's/\ *//g' | cut -c1 | sort -u | tr a-z A-Z)
- rm -rf "$BY_YEAR_PATH"/
- for year in $YEARS; do
- mkdir -p "$BY_YEAR_PATH/$year"
- while read movie; do
- movie_name=$(echo $movie | cut -d- -f2 | sed 's/^ *\(.*\)/\1/g' )
- ln -s \
- "$PWD/$ALL_PATH/$movie" \
- "$BY_YEAR_PATH/$year/$movie_name"
- done < <(ls -1 $ALL_PATH | grep "^$year - .*")
- done
- rm -rf "$BY_LETTER_PATH"/
- for L in $LETTERS; do
- mkdir -p "$BY_LETTER_PATH/$L"
- l=$(echo $L | tr A-Z a-z) # lower-case
- # movies starting with $L
- while read movie; do
- movie_name=$(echo $movie | cut -d- -f2 | sed 's/^ *\(.*\)/\1/g' )
- ln -s \
- "$PWD/$ALL_PATH/$movie" \
- "$BY_LETTER_PATH/$L/$movie_name"
- done < <(ls -1 $ALL_PATH/ | grep "^[0-9]* - [$l$L]")
- done
- # END
- ##############################################################################
Add Comment
Please, Sign In to add comment