Guest User

Untitled

a guest
Jul 17th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # Script for organize movies.
  4. # Put all movies in one folders using this format for the movi folder
  5. # /<YYYY> - <MOVIE NAME>/
  6. #
  7. # Ex:
  8. #
  9. # /All movies/1999 - Matrix
  10. # /All movies/2003 - Matrix Reloaded
  11. #
  12. # Author : Enderson Maia <endersonmaia _AT- gmail -DOT_ com>
  13. #
  14. # TODO - use sed istead of cut
  15.  
  16. # Configureation
  17. PWD=$(pwd)
  18. ALL_PATH="All movies"
  19. BY_YEAR_PATH="By year"
  20. BY_LETTER_PATH="By letter"
  21.  
  22. ##############################################################################
  23. # BEGIN
  24.  
  25. YEARS=$(ls -1 $ALL_PATH | grep '^[0-9]' | cut -d- -f1 | sort -u)
  26. LETTERS=$(ls -1 $ALL_PATH | grep '^[0-9]' | cut -d- -f2 | sed 's/\ *//g' | cut -c1 | sort -u | tr a-z A-Z)
  27.  
  28. rm -rf "$BY_YEAR_PATH"/
  29.  
  30. for year in $YEARS; do
  31. mkdir -p "$BY_YEAR_PATH/$year"
  32. while read movie; do
  33. movie_name=$(echo $movie | cut -d- -f2 | sed 's/^ *\(.*\)/\1/g' )
  34. ln -s \
  35. "$PWD/$ALL_PATH/$movie" \
  36. "$BY_YEAR_PATH/$year/$movie_name"
  37. done < <(ls -1 $ALL_PATH | grep "^$year - .*")
  38.  
  39. done
  40.  
  41. rm -rf "$BY_LETTER_PATH"/
  42.  
  43. for L in $LETTERS; do
  44. mkdir -p "$BY_LETTER_PATH/$L"
  45. l=$(echo $L | tr A-Z a-z) # lower-case
  46.  
  47. # movies starting with $L
  48. while read movie; do
  49. movie_name=$(echo $movie | cut -d- -f2 | sed 's/^ *\(.*\)/\1/g' )
  50. ln -s \
  51. "$PWD/$ALL_PATH/$movie" \
  52. "$BY_LETTER_PATH/$L/$movie_name"
  53. done < <(ls -1 $ALL_PATH/ | grep "^[0-9]* - [$l$L]")
  54. done
  55.  
  56. # END
  57. ##############################################################################
Add Comment
Please, Sign In to add comment