#!/bin/sh

IFS=$'\n';

rm /c/download/##New/*.mkv
rm /c/download/##New/*.avi
rm /c/download/##New/Last/*.mkv
rm /c/download/##New/Last/*.avi
rm /c/download/##New/Serials/*.mkv
rm /c/download/##New/Serials/*.avi

for file in `find /c/download/#Films/*.avi \
                  /c/download/#Films/*.mkv \
                  /c/download/#Films_HDTV/*.avi \
                  /c/download/#Films_HDTV/*.mkv \
                  /c/download/#Мультики/*.avi \
                  /c/download/#Мультики/*.mkv \
                  -mtime +0 -mtime -120`; do
   filename=`basename "$file"`;

   day=`stat $file | grep "Change" | awk '{ print $2 }'`;

#   echo "$filename"
   if [ ! -f "/c/download/##New/$day $filename" ]; then
     ln -s "$file" "/c/download/##New/$day $filename"
   fi
done


for file in `find /c/download/#Films/*.avi \
                  /c/download/#Films/*.mkv \
                  /c/download/#Films_HDTV/*.avi \
                  /c/download/#Films_HDTV/*.mkv \
                  /c/download/#Мультики/*.avi \
                  /c/download/#Мультики/*.mkv \
                  -mtime +0 -mtime -30`; do
   filename=`basename "$file"`;

   day=`stat $file | grep "Change" | awk '{ print $2 }'`;

#   echo "$day - $filename";
   if [ ! -f "/c/download/##New/Last/$day $filename" ]; then
     ln -s "$file" "/c/download/##New/Last/$day $filename"
   fi
done

for file in `find /c/download/#Serials_HDTV/*/*.avi \
                  /c/download/#Serials_HDTV/*/*.mkv \
                  -mtime +0 -mtime -30`; do
   filename=`basename "$file"`;

   day=`stat $file | grep "Change" | awk '{ print $2 }'`;

#   echo "$day - $filename";
   if [ ! -f "/c/download/##New/Serials/$filename" ]; then
     ln -s "$file" "/c/download/##New/Serials/$filename"
   fi
done

