Thought i'd share some of my scripts I use to organise my movie collection into easier to navigate sub-folders.
Note that these scripts are for BASH only, and are used solely on a Synology NAS running DSM 5.1 with ipkg installed (running bash & java 8). They symlink the files so you might need to configure permissions for CIFS or others.
BE AWARE THAT THESE SCRIPTS MAY EXECUTE RM -RF AT CERTAIN POINTS. DO NOT RUN THESE BLINDLY! READ THE SCRIPT FIRST AND BE SURE YOU UNDERSTAND WHAT IT IS DOING.
Sort movies into "By Year" and "By Name" folders
this code assumes your movies are inside folders with the format Movie (Year), eg. Avatar (2009)/Avatar - 2009.mkv.
Code: Select all
#/opt/bin/bash
collections="/volume1/collections"
by_year="By Year"
by_name="By Name"
#rm -rf "$collections/$by_year/"
#rm -rf "$collections/$by_name/"
CURRENT_YEAR=`date +%Y`
for YEAR in `seq 1900 $CURRENT_YEAR`
do
find /volume1/movies -mindepth 1 -maxdepth 1 -iname \*\($YEAR\)\* -type d | while read MOVIE; do
if [ ! -d "$collections/$by_year/$YEAR" ]; then mkdir -p "$collections/$by_year/$YEAR"; fi
ALPHA=`basename "$MOVIE" | cut -c1 | tr '[:lower:]' '[:upper:]'`
NONALPHA=`echo $ALPHA | grep -q '[a-zA-Z]'`
if [ ! $? = 0 ]; then ALPHA='#'; fi
if [ ! -d "$collections/$by_name/$ALPHA" ]; then mkdir -p "$collections/$by_name/$ALPHA"; fi
ln -s "$MOVIE" "$collections/$by_name/$ALPHA/"
ln -s "$MOVIE" "$collections/$by_year/$YEAR/"
done #movie
done #year
LAST_YEAR=$(($CURRENT_YEAR-1))
#rm -f "$collections/This Year" "$collections/Last Year"
ln -s "$collections/$by_year/$LAST_YEAR" "$collections/Last Year"
ln -s "$collections/$by_year/$CURRENT_YEAR" "$collections/This Year"
Great for Marathons! Has basic script for genres, currently looking into how i can split a single movie into multiple genre folders.
Code: Select all
#!/bin/sh
FILEBOT=/usr/local/bin/filebot
collections="/volume1/collections"
by_collection="By Collection"
by_genre="By Genre"
#rm -rf "$collections/$by_collection/"
#rm -rf "$collections/$by_genre/"
# by collection
$FILEBOT -rename --action symlink \
--db themoviedb -non-strict \
--format "$collections/$by_collection/{collection.replaceTrailingBrackets().sortName()}/{y} - {n}" \
-r "/volume1/movies/"
# by genre
$FILEBOT -rename --action symlink \
--db themoviedb -non-strict \
--format "$collections/$by_genre/{genre.replaceTrailingBrackets().sortName()}/{y} - {n}" \
-r "/volume1/movies/"
# clean up the erroneus files
#find "$collections/$by_collection/" -type l -maxdepth 1 -delete
#find "$collections/$by_collection/" -type l ! \( -iname \*.m\* \) -delete
#find "$collections/$by_collection/" -type d \
# -maxdepth 1 \
# -exec sh -c 'set -- "$0"/*; [ $# -le 1 ];' {} \; \
# -print0 | xargs -0 rm -rf
# clean up the erroneus files
#find "$collections/$by_genre/" -type l -maxdepth 1 -delete
#find "$collections/$by_genre/" -type l ! \( -iname \*.m\* \) -delete
#find "$collections/$by_genre/" -type d \
# -maxdepth 1 \
# -exec sh -c 'set -- "$0"/*; [ $# -le 1 ];' {} \; \
# -print0 | xargs -0 rm -rf