Created
December 16, 2010 00:55
-
-
Save endersonmaia/742861 to your computer and use it in GitHub Desktop.
Organize movie's folder.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 | |
############################################################################## |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment