#!/bin/bash
# Checks to make sure all videos off of phone have been copied to the Originals directory
# If they are missing, it means Nextcloud missed them somehow. Copy them to New Memories then.
+# 1) First connect the phone to a computer with USB debugging turned on.
+# Authorize the connection
+# 2) Execute the command "adb tcpip 5555"
+# 3) Run the script, authorize the connection
+# 4) Run the script again
+# You should now be able to connect to the device wirelessly
dcim_path="/storage/emulated/0/DCIM/Camera"
originals="/naspool/dropbox/Originals"
+organized_logs="/var/log/organize"
new_memories="/naspool/dropbox/New Memories"
adb connect 192.168.0.23
for i in $mp4s_on_phone; do
echo "$mp4s_in_originals" | grep -q $i
- if [[ $? == 1 ]]; then
- echo "mp4 not found in originals: $i"
- adb -e pull "$dcim_path/$i" "$new_memories"
- fi
+ if [[ $? != 0 ]]; then
+ zgrep -q $i $organized_logs/organize_videos*
+ if [[ $? != 0 ]]; then
+ echo "mp4 not found in originals or organize logs: $i"
+ if [[ ! -e "$new_memories/$i" ]]; then
+ adb -e pull "$dcim_path/$i" "$new_memories"
+ else
+ echo "mp4 already copied into $new_memories"
+ fi
+ else
+ echo "mp4 found in originals or organize logs: $i"
+ fi
+ else
+ echo "mp4 found in originals or organize logs: $i"
+ fi
done
print "$mencoder $encode_options_pass2 -o ./$encoded_dir/$current_output_file -idx $current_file\n";
}
if(!$opt_s) {
- $tempfile = `tempfile`; chomp($tempfile);
+ $tempfile = `mktemp`; chomp($tempfile);
system("$mencoder $encode_options_pass1 -o ./$encoded_dir/$current_output_file -idx $current_file 2>$tempfile");
system("$mencoder $encode_options_pass2 -o ./$encoded_dir/$current_output_file -idx $current_file 2>>$tempfile");
if(! -e "./$encoded_dir/$current_output_file") {
# 3) Create a chapter file for each destination video file
# tmp chapter file used by handbrake when creating mkv, but remove the 0 byte file it creates, we'll create it if we need it
-my $chapter_file = `tempfile`; chomp($chapter_file); unlink "$chapter_file";
+my $chapter_file = `mktemp`; chomp($chapter_file); unlink "$chapter_file";
foreach my $key (keys %merge_videos) {
# Create the chapters file for each output mkv file.
####################################################################################################
# Configuration parameters - CHANGE THESE TO SUITE YOUR NEEDS
my $ffmpeg=`which ffmpeg`; chomp($ffmpeg);
-my $tmpfile = `tempfile`; chomp($tmpfile);
+my $tmpfile = `mktemp`; chomp($tmpfile);
####################################################################################################
####################################################################################################
$video_files_found=`$find_cmd_with_mkv`;
if(!$video_files_found) { exit 0; }
-# Only proceed if no files have changed in the past $cmin minutes
-if(! $opt_f) {
- $changed_files_found=`$find_changed_cmd`;
- if($changed_files_found) { exit 0; }
+# Only proceed if we are skipping this check or if the $srcpathname dir hasn't been modified in the last $minage minutes
+if(! $opt_f && ((time - (stat("$srcpathname"))->mtime) < ($minage * 60))) {
+ exit 0;
}
# Only one instance of this script running at a time
if(is_folder_empty($srcdir)) {
print "-> Subdir detected for videos ($srcdir != $srcpathname)\n" if($opt_v);
if(! defined $opt_t) {
- $tmpdir=`tempfile`;
+ $tmpdir=`mktemp`;
system("rm $tmpdir");
system("cp -R \"$srcdir\" $tmpdir > /dev/null 2>/dev/null");
system("rm -rf \"$srcdir\"");
# This is done to ensure that all videos from a given upload from a camera have completed prior to looking for videos to merge
$minage = "+60";
-# What command should be used to find files that have changed (are at least $minage old)
-$find_changed_cmd = "find \"$srcpathname/\" -not -cmin $minage -a \\( $movie_file_ext \\)";
+# What command should be used to find files by move_videos_from_watchdir that have changed (are at least X minutes old)
+$find_changed_cmd = "find \"$srcpathname/\" -not -cmin +5 -a \\( $movie_file_ext \\)";
# What command should be used to find all movie files
$find_cmd = "find \"$srcpathname/\" $movie_file_ext";
$find_mkv = "find \"$srcpathname/\" -iregex \".*\.mkv\"";
# Set the tmpfile to use, but remove the 0 byte file it creates, we'll create it if we need it
-$tmpfile = `tempfile`; chomp($tmpfile); unlink "$tmpfile";
+$tmpfile = `mktemp`; chomp($tmpfile); unlink "$tmpfile";
# Set the timezone to use
$timezone = `cat /etc/timezone`; chomp($timezone);