#!/bin/bash # ------------------------------------------------------------------------- # Jehsom's datearch v1.0 - Archives releases by dupe date or NFO date # Copyright (C) 2001 jehsom@jehsom.com # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # ------------------------------------------------------------------------- # # This is a really cool program. If you have lots of releases burned on CD, # or not in their dated directories, and you want to reorganize them into # dated subdirs in your archive directory, this program will first search # the dupelog to find the rls date, and if that doesn't work, it searches # the .nfo file and intelligently extracts a release date. It then moves # (or copies if it cannot move) the release into the proper dated dir. # # Your glftpd dupelog. DUPELOG="/glftpd/ftp-data/logs/dupelog" # The archive dir, under which the dated dirs should be created. ARCHDIR="/glftpd/site/Old_Archive" ####################### ### Ignore the rest ### ####################### startdir="$PWD" for i; do ( cd "$i" 2>/dev/null || { echo "Could not change to directory '$i'. Skipping." 1>&2 continue } name="$(basename "$i")" # echo "fgrep -i ' $name' '$DUPELOG' | head -1 | cut -c1-6" date="$(fgrep -i " $name" "$DUPELOG" | head -1 | cut -c1-6)" if [ -n "$date" ]; then date="${date#????}${date%??}" case $date in [01][0-9]????) date="20$date" ;; *) date="19$date" ;; esac echo -e "$(du -sh | cut -f1): \033[1;32m$name\033[0m -> \033[1;33m$date\033[0m" [ -d "$ARCHDIR/$date" ] || mkdir "$ARCHDIR/$date" cd $startdir mv "$i" "$ARCHDIR/$date" 2>/dev/null else nfo="$(ls *.nfo */*.nfo 2>/dev/null | head -1)" [ -z "$nfo" ] && { echo "$i: No NFO."; exit 1; } head -60 $nfo | grep -Ei "(rip|release|day|date|d.a.t.e|[0-9]{2}/[0-9]{2}|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)" | grep -Ei "(\b([0-9]{1,4}|[a-z]{3})[-/:.]([0-9]{1,4}|[a-z]{3})[-/:.]([0-9]{1,4}|[a-z]{3}\b)|date|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)" | tr -c -d -- '-\.:[:alnum:]/ \012' | tr -s '[:space:].' | sed 's/[jJ][aA][nN][a-zA-Z]*/01/g; s/[fF][eE][bB][a-zA-Z]*/02/g; s/[mM][aA][rR][a-zA-Z]*/03/g; s/[aA][pP][rR][a-zA-Z]*/04/g; s/[mM][aA][yY][a-zA-Z]*/05/g; s/[jJ][uU][nN][a-zA-Z]*/06/g; s/[jJ][uU][lL][a-zA-Z]*/07/g; s/[aA][uU][gG][a-zA-Z]*/08/g; s/[sS][eE][pP][a-zA-Z]*/09/g; s/[oO][cC][tT][a-zA-Z]*/10/g; s/[nN][oO][vV][a-zA-Z]*/11/g; s/[dD][eE][cC][a-zA-Z]*/12/g;' | while read line; do case $line in *[rR][iI][pP]*) case $line in *[dD][aA][tT][eE]*|*[dD]?[aA]?[tT]?[eE]*) score=9 ;; *) score=8 ;; esac ;; *[rR][eE][lL][eE][aA][sS][eE]*) case $line in *[dD][aA][tT][eE]*|*[dD]?[aA]?[tT]?[eE]*) score=7 ;; *) score=6 ;; esac ;; *[sS][tT][rR][eE][eE][tT]*) score=1 ;; *[dD][aA][tT][eE]*|*[dD]?[aA]?[tT]?[eE]*) score=5 ;; *[0-9][0-9][-/][0-9][0-9][-/][0-9][0-9]*) score=4 ;; *200[0123]*|19[89][0-9]*) score=3 ;; *[0-9][0-9][0-9][0-9]*) score=2 ;; *) score=0 ;; esac date="$(echo "$line" | sed 's/\([^0-9]\)\([0-9][^0-9]\)/\10\2/g; s/\([0-9]\)[-/. a-z]\{1,3\}\([0-9]\)/\1\2/g; s/^.*[^0-9]\([0-9]\{6,8\}\)[^0-9]\{0,1\}.*$/\1/;' )" case $date in ????[4-9][0-9]) year="19${date#????}" monthday="${date%??}" ;; [4-9][0-9]????) year="19${date%????}" monthday="${date#??}" ;; 19[2-9][0-9]????) year="${date%????}" monthday="${date#????}" ;; ????19[2-9][0-9]) year="${date#????}" monthday="${date%????}" ;; ????0[0123]) year="20${date#????}" monthday="${date%??}" ;; 0[0123]????) year="20${date%????}" monthday="${date#??}" ;; ????200[0-5]) year="${date#????}" monthday="${date%????}" ;; 200[0-5]????) year="${date%????}" monthday="${date#????}" ;; *) year="0000" monthday="0000" ;; esac month="${monthday%??}" day="${monthday#??}" [ "$month" -gt "12" ] && { tmp=$month; month=$day; day=$tmp; unset tmp; } { [ "$monthday" != "0000" ] && [ "$score" -gt "0" ]; } && echo "$score: $year$month$day ($line)" done | sort -rn | head -1 | while read dateline; do echo " $name: ${dateline#[0-9]: }" date="$(echo "$dateline" | cut -f2 -d ' ')" echo -e "$(du -sh | cut -f1): \033[1;32m$name\033[0m -> \033[1;33m$date\033[0m" [ -d "$ARCHDIR/$date" ] || mkdir "$ARCHDIR/$date" cd "$startdir" mv "$i" "$ARCHDIR/$date" 2>/dev/null done fi ); done