--- /dev/null
+#!/bin/bash
+
+DROPBOX="/naspool/dropbox/New Movies"
+MOVIEDIR="/naspool/movies"
+MOVIE="$1"
+CATEGORY="$2"
+
+if [[ -z "$MOVIE" ]]; then
+ echo "Usage: $0 <movie.mkv|Children|Collection|Holiday|Family|Church|Mobile> <Children|Collection|Holiday|Family|Church|Mobile>"
+ exit 1
+fi
+
+if [[ "$MOVIE" == *mkv ]] && [[ "$MOVIE" != /* ]]; then
+ MOVIE="$PWD/$MOVIE"
+fi
+
+if [[ "$MOVIE" == *mp4 ]] && [[ "$MOVIE" != /* ]]; then
+ MOVIE="$PWD/$MOVIE"
+fi
+
+function link_movie {
+ MOVIEFILENAME=`basename "$1"`
+ MOVIEFILENAMENOEXT=`basename "${1%.*}"`
+ CATEGORY=$2
+ if [[ ! -e "$MOVIEDIR/Mobile/$CATEGORY/$MOVIEFILENAMENOEXT.mkv" ]]; then
+ echo "-> Linking $1 to $DROPBOX/Mobile/$CATEGORY/$MOVIEFILENAME for mobile version creation"
+ if [[ ! -e "$DROPBOX/Mobile/$CATEGORY/$MOVIEFILENAME" ]]; then
+ ln -s "$1" "$DROPBOX/Mobile/$CATEGORY/$MOVIEFILENAME"
+ fi
+ else
+ echo "-> $MOVIEFILENAMENOEXT already exists under $MOVIEDIR/Mobile/$CATEGORY"
+ fi
+}
+
+if [[ -f "$MOVIE" ]]; then
+ link_movie "$MOVIE" "$CATEGORY"
+elif [[ -d "$MOVIEDIR/$MOVIE" ]]; then
+ CATEGORY=$MOVIE
+ shopt -s nullglob
+ for MOVIE in $MOVIEDIR/$CATEGORY/*.mkv $MOVIEDIR/$CATEGORY/*.avi
+ do
+ link_movie "$MOVIE" "$CATEGORY"
+ done
+else
+ echo "-E- Unable to find movie or category $MOVIE"
+ exit 1
+fi
+
--- /dev/null
+#!/usr/bin/perl
+# Author: Alan J. Pippin
+# Description: Find movies from a temporary dropbox location and compress and move them into their final destination.
+
+use File::Copy;
+use File::Basename;
+use Getopt::Std;
+use File::stat;
+use Time::localtime;
+use File::Pid;
+
+####################################################################################################
+# Configuration parameters
+my $movie_src_dir = "/naspool/dropbox/New Movies";
+my $mobile_movie_src_dir = "/naspool/dropbox/New Movies/Mobile";
+my $movie_dst_dir = "/naspool/movies";
+my $mobile_movie_dst_dir = "/naspool/movies/Mobile";
+my $movie_done_dir = "/naspool/dropbox/Encoded";
+my $log = "/var/log/organize/organize_movies.log";
+my $encode_log = "/var/log/organize/organize_movies_encode.log";
+my $minage = 1; #in minutes
+my $now = time;
+my $quality = 18;
+my $mailto = "admin\@pippins.net";
+
+####################################################################################################
+# Find the movies to encode
+
+# Only one instance of this script should be running at a time
+my $pidfile = File::Pid->new({file => "$pid_file", pid => "$$"});
+exit if $pidfile->running();
+$pidfile->write();
+
+# Encode the movies
+encode_movies($mobile_movie_src_dir, $mobile_movie_dst_dir);
+encode_movies($movie_src_dir, $movie_dst_dir);
+
+sub encode_movies {
+ my ($movie_src_dir, $movie_dst_dir) = @_;
+
+ # Search the $movie_src_dirs for movies to encode
+ $date = `date`; print "$date";
+ print "-> Searching $movie_src_dir for movies to encode to $movie_dst_dir\n";
+ opendir(SRC_DIR, $movie_src_dir) || die "-E- Unable to open $movie_src_dir\n";
+ while(my $category = readdir(SRC_DIR)) {
+ next if ! -d "$movie_src_dir/$category";
+ next if $category =~ /^\.+$/;
+ print "-> Found category $category\n";
+ opendir(CAT_DIR,"$movie_src_dir/$category") || die "-E- Unable to open $movie_src_dir/$category\n";
+ while(my $filename = readdir(CAT_DIR)) {
+ next if $filename =~ /^\.+$/;
+ next if $filename =~ /\.FAILED$/;
+ my $movie = "$movie_src_dir/$category/$filename";
+ next if ((! -f $movie) && (! -l $movie));
+ next if -e "$movie.FAILED";
+ my $stat = stat("$movie");
+ if($stat->mtime < ($now - $minage*60)) {
+ my ($base, $dir, $ext) = fileparse($movie,'\..*');
+ my $output = "$movie_dst_dir/$category/$base.mkv";
+ print "-> Encoding $movie => $output\n";
+ my $date = `date`; chomp $date;
+ open LOG, ">>$log" || die "-E- Unable to open logfile $log\n";
+ print LOG "$date: started $movie => $output\n";
+ my $cmd = "HandBrakeCLI";
+ $cmd .= " -i \"$movie\" -o \"$output\"";
+ $cmd .= " -f mkv --loose-anamorphic --denoise=\"weak\" -e x264";
+ $cmd .= " -a 1,1";
+ $cmd .= " -x b-adapt=2:rc-lookahead=50 -v 2";
+ if($category =~ /Mobile/i || $movie_src_dir =~ /Mobile/i || $movie_dst_dir =~ /Mobile/i) {
+ $cmd .= " --preset=\"Android Tablet\" -2 -B 256";
+ } else {
+ $cmd .= " -q $quality";
+ $cmd .= " -6 6ch";
+ $cmd .= " -E copy:ac3";
+ $cmd .= " --preset=\"High Profile\"";
+ }
+ print " $cmd\n";
+ my $errno = system("$cmd > $encode_log 2>&1");
+ if($errno == 0) {
+ if(-l "$movie") {
+ unlink "$movie";
+ } else {
+ system("mv \"$movie\" \"$movie_done_dir\"");
+ }
+ } else {
+ system("mailx $mailto -s \"Encoding failed: $movie\" < $encode_log");
+ system("touch \"$movie.FAILED\"");
+ }
+ $date = `date`; chomp $date;
+ print LOG "$date: finished $movie => $output\n";
+ close LOG;
+ }
+ }
+ closedir(CAT_DIR);
+ }
+ closedir(SRC_DIR);
+}
+
+####################################################################################################