From: Alan J. Pippin Date: Fri, 18 Nov 2011 03:01:35 +0000 (-0700) Subject: Various changes/updates X-Git-Url: http://git.pippins.net/embedvideo/.git/static/images/%7Bdelete%7D?a=commitdiff_plain;h=be9a9d1914a8f80b031631f902c9daae0b8f6d90;p=videoscripts%2F.git Various changes/updates Added newly created mkv video creation scripts --- diff --git a/create_merge_videos b/create_merge_videos deleted file mode 100644 index aaa1c9a..0000000 --- a/create_merge_videos +++ /dev/null @@ -1 +0,0 @@ -make_home_video.pl -m -d diff --git a/dump_raw_video_files_from_camera b/dump_raw_video_files_from_camera deleted file mode 100755 index d540dd7..0000000 --- a/dump_raw_video_files_from_camera +++ /dev/null @@ -1 +0,0 @@ -/usr/bin/dvgrab --autosplit --timestamp --format dv2 --opendml --size 22000 home_video_ diff --git a/em b/em deleted file mode 100755 index 90b80f1..0000000 --- a/em +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash -/usr/bin/emacs -fn 8x13 $* & - diff --git a/fix_video_names b/fix_video_names deleted file mode 100644 index 266f312..0000000 --- a/fix_video_names +++ /dev/null @@ -1 +0,0 @@ -rn 's/\.00\.avi/-00_xvid2500\.avi/' * diff --git a/homevideo_random.pl b/homevideo_random.pl new file mode 100755 index 0000000..4e5a81a --- /dev/null +++ b/homevideo_random.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl + +use List::Util 'shuffle'; + +my $dir = "/naspool/videos/HomeVideos"; +my $plsfile = "$dir/Random.pls"; +my $avifiles = "????/????-??-??.avi"; + +chdir $dir || die "Couldn't change directory!\n"; +system "rm -f $plsfile"; +@files = `ls -1 $avifiles`; +@shuffled = shuffle(@files); +open (FILE, ">$plsfile") || die "Couldn't open $plsfile!\n"; +print FILE @shuffled; +close (FILE); + diff --git a/make_home_videos.cmd b/make_home_videos.cmd index ce6b266..4c19b7e 100755 --- a/make_home_videos.cmd +++ b/make_home_videos.cmd @@ -8,8 +8,8 @@ # USAGE: make_home_videos.cmd # EXAMPLE: make_home_videos.cmd Dec06-Apr07 -SERVER="/mnt/server/videos/HomeVideos" -MAKE_VIDEOS="/mnt/server/videos/bin/make_home_videos.pl" +SERVER="/naspool/videos/HomeVideos" +MAKE_VIDEOS="/naspool/videos/bin/make_home_videos.pl" $MAKE_VIDEOS -e -c -m -p -a -n $* @@ -68,5 +68,6 @@ popd > /dev/null echo "-> Rebooting the system in 10 seconds... Press CTRL-C to abort..." sleep 10 echo "-> Rebooting now..." +# chmod u+s /sbin/reboot if you can't run the below command without being root /sbin/reboot diff --git a/make_home_videos.cmd.nocapture b/make_home_videos.cmd.nocapture new file mode 100755 index 0000000..2895f42 --- /dev/null +++ b/make_home_videos.cmd.nocapture @@ -0,0 +1,67 @@ +#!/bin/bash +# DESCRIPTION: +# Wrapper script around make_home_videos.pl script that +# facilitates copying over the daily_clips to another +# linux server location, properly merging the clips +# created with the existing clips and playlists on +# the remote server. +# USAGE: make_home_videos.cmd +# EXAMPLE: make_home_videos.cmd Dec06-Apr07 + +SERVER="/naspool/videos/HomeVideos" +MAKE_VIDEOS="/naspool/videos/bin/make_home_videos.pl" + +$MAKE_VIDEOS -e -m -p -a -n $* + +# Copy the daily clips over to the main file server +pushd "$*/daily_clips" > /dev/null +lastyear="" +for i in `/bin/ls -1 *.avi`; +do + filename=`echo "$i" | sed 's/.avi//g'` + year=`echo "$filename" | awk --field-separator - '{print $1}'` + month=`echo "$filename" | awk --field-separator - '{print $2}'` + day=`echo "$filename" | awk --field-separator - '{print $3}'` + + # set lastyear if we haven't done so yet + if [[ -z "$lastyear" ]]; + then + lastyear="$year" + fi + + # if we have changed year directories, remake the playlists for lastyear + if [[ "$year" != "$lastyear" ]]; + then + pushd "$SERVER/$lastyear" > /dev/null + $MAKE_VIDEOS -p -d . + popd > /dev/null + fi + + # make the destination directory if it is missing + if [[ ! -d "$SERVER/$year" ]]; + then + mkdir "$SERVER/$year" + fi + + # don't overwrite existing filenames + basefilename="$filename" + num=0 + while [[ -f "$SERVER/$year/$filename.avi" ]]; + do + ((num++)) + filename="$basefilename.$num" + done + + echo "Copying $i to $SERVER/$year/$filename.avi" + cp "$i" "$SERVER/$year/$filename.avi" + + lastyear=$year +done + +# remake the playlists for year +pushd "$SERVER/$year" > /dev/null +$MAKE_VIDEOS -p -d . +popd > /dev/null + +popd > /dev/null + diff --git a/make_home_videos.cmd.noreboot b/make_home_videos.cmd.noreboot index a34a1a5..4966652 100755 --- a/make_home_videos.cmd.noreboot +++ b/make_home_videos.cmd.noreboot @@ -8,8 +8,8 @@ # USAGE: make_home_videos.cmd # EXAMPLE: make_home_videos.cmd Dec06-Apr07 -SERVER="/mnt/server/videos/HomeVideos" -MAKE_VIDEOS="/mnt/server/videos/bin/make_home_videos.pl" +SERVER="/naspool/videos/HomeVideos" +MAKE_VIDEOS="/naspool/videos/bin/make_home_videos.pl" $MAKE_VIDEOS -e -c -m -p -a -n $* diff --git a/make_home_videos.pl b/make_home_videos.pl index 33c0c0d..6963175 100755 --- a/make_home_videos.pl +++ b/make_home_videos.pl @@ -6,6 +6,7 @@ # 2) mencoder : http://www.mplayerhq.hu/homepage/design7/dload.html # 3) transcode : vi sources.list; deb ftp://ftp.nerim.net/debian-marillat sarge main # apt-get install transcode +# 4) avimerge : apt-get install transcode-utils use Getopt::Std; @@ -21,7 +22,7 @@ $encoded_dir = "xvid_clips"; $merge_dir = "daily_clips"; $default_tape_name = "home_video"; $playlist_extension = "pls"; -$dvgrab = "/usr/local/bin/dvgrab"; +$dvgrab = "/usr/bin/dvgrab"; $mencoder = "/usr/bin/mencoder"; $mplayer = "/usr/bin/mplayer"; $avimerge = "/usr/bin/avimerge"; @@ -34,8 +35,10 @@ $max_dv_clip_size_in_mb = "1023"; #I had to keep it at this size to avoid errors #$max_dv_clip_size_in_mb = "22000"; #avisplit still doesn't seem to do things right for large clips # max_tape_grab_time=7200 Allows Max time of 2 hours to allow a tape to be dumped (good for 90 min tape) # max_tape_grab_time=5400 Allows Max time of 1.5 hours to allow a tape to be dumped (good for 60 min tape) -$max_tape_grab_time = 5400; -$dvgrab_options = "--autosplit --timestamp --format dv2 --opendml --buffers 2048 --rewind"; +$max_tape_grab_time = 7200; +#$dvgrab_options = "--autosplit --timestamp --format dv2 --opendml --buffers 2048 --rewind"; +#$dvgrab_options = "-autosplit -timestamp -format dv2 -opendml -buffers 2048 -rewind"; +$dvgrab_options = "-autosplit -timestamp -format dv2 -opendml -rewind"; $encode_options_pass1 = "-mc 0 -oac mp3lame -lameopts cbr:cbr=128 -ffourcc XVID -fps 29.97 -ovc lavc "; $encode_options_pass1.= "-lavcopts vcodec=mpeg4:vhq:vbitrate=$bitrate:keyint=15:vpass=1 -vf pp=ci"; $encode_options_pass2 = "-mc 0 -oac mp3lame -lameopts cbr:cbr=128 -ffourcc XVID -fps 29.97 -ovc lavc "; diff --git a/make_mkv b/make_mkv new file mode 100755 index 0000000..ea3b50c --- /dev/null +++ b/make_mkv @@ -0,0 +1,130 @@ +#!/usr/bin/perl +# Author: Alan J. Pippin +# Description: Take a list of video files and create a single mkv video file from them + +# Pre-requisites: +# mkvtoolnix - http://www.bunkus.org/videotools/mkvtoolnix/ +# ffmpeg + +########################### +# Includes +use File::Copy; +use File::Basename; +use Getopt::Std; +use File::stat; +use DateTime; +use DateTime::Duration; +use DateTime::Format::Duration; + +########################### +# Configuration parameters +my $mkvmerge=`which mkvmerge`; chomp($mkvmerge); +my $ffmpeg=`which ffmpeg`; chomp($ffmpeg); +my $tmpfile = `tempfile`; chomp($tmpfile); +my $chapter_file = $tmpfile; +my $input_file_options = "-S"; +my $output_file_options = "--chapters $chapter_file"; + +########################### +# Options +getopts("st:o:i:h"); + +if(! -x $mkvmerge) { die "-E- Unable to find required program: mkvmerge\n"; } +if(! -x $ffmpeg) { die "-E- Unable to find required program: ffmpeg\n"; } +if(! defined $opt_t) { &usage(); die "-E- Missing required title: -t \n"; } +if(! defined $opt_o) { &usage(); die "-E- Missing required argument output video names: -o <output.mkv>\n"; } +if(! defined $opt_i) { &usage(); die "-E- Missing required argument input video names: -i <input,input,...>\n"; } + +sub usage { + print "usage: $0 -t <title> -o <output.mkv> -i <input,input,...>\n"; + print " -t <title> Sets the general title for the output video file\n"; + print " -o <output.mkv> Sets the name of the output mkv file\n"; + print " -i <input,input,...> Sets the name of the input files to make into an mkv file\n"; + print " -s Simulate mode. Don't actually make the video, but tell us what you will do\n"; + print "\n"; + return 1; +} + +########################### +# Helper Subroutines +sub epoch_to_date { + my ($epoch) = @_; + my $mtime = DateTime->from_epoch(epoch => $epoch); + return sprintf("%4d",$mtime->year)."-".sprintf("%02d",$mtime->month)."-".sprintf("%02d",$mtime->day)." ".$mtime->hms; +} + +########################### +# MAIN + +# Turn the list of input videos into a hash with a value equal to the modification time in epoch seconds +my %videos; +foreach $video (split(/,/, $opt_i)) { + if(! -r "$video") { die "-E- Unable to read input video file: $video\n"; } + my $mtime_epoch = stat("$video")->mtime; + my $mdate = epoch_to_date($mtime_epoch); + $videos{$video} = $mtime_epoch; +} + +# Create the chapters file for the mkv file. +# Make each video file it's own chapter in the MKV file. +# Name the chapter with the date and time the video clip was taken (modified date). +print "-> Creating $opt_o with title '$opt_t' from the following video files in last modified date order:\n"; +open(CHAPTERS,">$chapter_file") || die "-E- Unable to create chapter file: $chapter_file\n"; +my $chapter_num = 0; +my $prev_hour = 0; +my $prev_min = 0; +my $prev_sec = 0; +my $new_duration = DateTime::Duration->new(years => 1900, hours => $prev_hour, minutes => $prev_min, seconds => $prev_sec); +my $duration_format = DateTime::Format::Duration->new(pattern => '%H:%M:%S.%3N', normalize => 1); +foreach my $video (sort{$videos{$a} <=> $videos{$b}} keys %videos) { + $chapter_num++; + my $hour = 0; + my $min = 5; + my $sec = 0; + my $mtime_epoch = stat("$video")->mtime; + my $mdate = epoch_to_date($mtime_epoch); + my $duration = `$ffmpeg -i "$video" 2>&1 | grep Duration`; + if($duration =~ /Duration: (\d+):(\d+):(\d+)\.(\d+)/) { + $hour = $1; + $min = $2; + $sec = "$3.$4"; + } + my $start_time = $duration_format->format_duration($new_duration); + print "$mdate $hour:$min:$sec -> $video \n"; + print CHAPTERS "CHAPTER".sprintf("%02d",$chapter_num)."=".$start_time."\n"; + print CHAPTERS "CHAPTER".sprintf("%02d",$chapter_num)."NAME=".$mdate."\n"; + my $dt = DateTime::Duration->new(years => 1900, hours => $hour, minutes => $min, seconds => $sec); + my $prev_dt = DateTime::Duration->new(years => 1900, hours => $prev_hour, minutes => $prev_min, seconds => $prev_sec); + $new_duration = $dt + $prev_dt; + $prev_hour = $hour; $prev_min = $min; $prev_sec = $sec; +} +close(CHAPTERS); +print "\n-> Creating the following chapter file for this video:\n"; +$chapter_file_contents = `cat $chapter_file`; +print "$chapter_file_contents\n"; + +# Create the mkv video +print "-> Creating the MKV video file '$opt_o'\n"; + +my $cmd = "$mkvmerge --title \"$opt_t\" $output_file_options -o \"$opt_o\""; +my $video_count = 0; +foreach my $video (sort{$videos{$a} <=> $videos{$b}} keys %videos) { + if($video_count == 0) { + $cmd .= " $input_file_options \"$video\""; + } else { + $cmd .= " $input_file_options + \"$video\""; + } + $video_count++; +} +print "$cmd\n"; +if(! defined $opt_s) { + my $errno = system("$cmd"); + if($errno > 0) { $errno = $errno - 255; } + if($errno > 1) { die "-E- mkvmerge encountered some errors with exit code $errno\n"; } +} + +# Remove the temporary file +if(-e "$tmpfile") { unlink "$tmpfile"; } + +########################### + diff --git a/merge_videos_by_day b/merge_videos_by_day new file mode 100755 index 0000000..dec78b2 --- /dev/null +++ b/merge_videos_by_day @@ -0,0 +1,163 @@ +#!/usr/bin/perl + +use File::Copy; +use File::Basename; +use Getopt::Std; +use File::stat; +use Time::localtime; + +# Command line options +getopts("h:tvs:"); + +sub usage { + print "usage: $0 [-t] -s <srcpath>\n"; + print " -s <srcpath> specify the path to search for videos to merge under\n"; + print " -h <compute host> specify the remote compute host to submit the mkvmerge job to\n"; + print " -v verbose mode; print extra information about what is being found/merged\n"; + print " -t test mode; print what will happen, but don't do anything\n"; + return 1; +} +if(defined $opt_h) { usage(); exit 1; } + +# Configuration parameters +my $compute_host = "pippin.pippins.net"; +my $srcpathname = $opt_s; +my $minage = "+10"; # Files must be older than X minutes to move +my $owner = "ajp"; # The owner of the files after they are moved +my $group = "pip"; # The group of the files after they are moved +my $mode = "664"; # The mode to set on each file after they are moved +my $make_mkv = "/naspool/videos/bin/make_mkv"; chomp($make_mkv); +my $find_cmd = "find \"$srcpathname/\" -cmin $minage -iregex \".*\.mov\" -o -iregex \".*\.3gp\" -o -iregex \".*\.mp4\" -o -iregex \".*\.mts\""; + +# Sanity check +if(! -x $make_mkv) { die "-E- Unable to find required script: make_mkv\n"; } +if(! -d $srcpathname) { &usage; print "-E- Can't find srcpath: $srcpathname\n"; exit 1; } +if(defined $opt_h) { $compute_host = $opt_h; } + +my %monthname2month = ( + "Jan" => "01", + "Feb" => "02", + "Mar" => "03", + "Apr" => "04", + "May" => "05", + "Jun" => "06", + "Jul" => "07", + "Aug" => "08", + "Sep" => "09", + "Oct" => "10", + "Nov" => "11", + "Dec" => "12" + ); + +my %month2monthname = ( + "01" => "Jan", + "02" => "Feb", + "03" => "Mar", + "04" => "Apr", + "05" => "May", + "06" => "Jun", + "07" => "Jul", + "08" => "Aug", + "09" => "Sep", + "10" => "Oct", + "11" => "Nov", + "12" => "Dec" + ); + +# Change directories to the srcpath to search for videos to merge +print "-> Finding all videos under '$srcpathname' to merge by day\n"; +my %videos; +chdir "$srcpathname"; +print "$find_cmd\n" if($opt_v); +foreach $file (sort `$find_cmd`) { + + chomp($file); + $srcdir = dirname($file); + $file = basename($file); + $srcfile = $file; + $ext = "mkv"; + + print "Found movie: srcdir: $srcdir srcfile: $srcfile ext: $ext\n" if($opt_v); + + # Throw out files not in the current srcpath + if((! -f "$srcfile") && (! -f "$srcdir/$srcfile")) { next; } + + # Make a note of the month, year, and day this video was taken (from the modification time of the file) + $date_taken = ctime(stat("$srcdir/$srcfile")->mtime); + + # Get the date taken from the filename + if($srcfile =~ /^(\d+)-(\d+)-(\d+)/) { + $year = $1; + $month = $2; + $day = sprintf("%02d",$3); + $monthnum = $month; + $monthname = lc($month2monthname{$month}); + } + # Get the date taken from the modification time + elsif($date_taken =~ /\S+\s+(\S+)\s+(\d+)\s+\S+\s+(\d+)/) { + $year = $3; + $month = $1; + $day = sprintf("%02d",$2); + $monthnum = $monthname2month{$month}; + $monthname = lc($month2monthname{$month}); + } else { + print "-E- Unable to parse year and month from this file: $srcdir/$srcfile\n"; + next; + } + + # We are ready to pick a destination folder to put the merged video in + $dstdir = $srcdir; + $dstfile = $dstdir . "/" . $year . "-" . $monthnum . "-" . $day; + + # Check for duplicate filenames at the destination + $newfile = $dstfile . "." . "000"; + if(-e "$newfile.$ext") { + foreach $i ('001' .. '999') { + $newfile = $dstfile . "." . $i; + if(! -e "$newfile.$ext") { last; } + } + $dstfile = $newfile; + } + $dstfile = "$newfile.$ext"; + + print " merging \"$srcdir/$srcfile\" into \"$dstfile\"\n"; + push(@{$videos{"$dstfile"}}, "\"$srcdir/$srcfile\""); +} + +foreach $video (sort keys %videos) { + + my $videos = join(',', @{$videos{$video}}); + + # Only merge the videos if there is more than 1 + my $num_videos = $#{$videos{$video}} + 1; + if($num_videos <= 1) { next; } + + if($video =~ /(\d+)-(\d+)-(\d+)/) { + $year = $1; + $month = $2; + $day = sprintf("%02d",$3); + } + + my $pwd = `pwd`; chomp($pwd); + my $cmd = "ssh $compute_host 'cd \"$pwd\"; $make_mkv -t \"HomeVideos: $year-$month-$day\" -o \"$video\" -i $videos'\n"; + if(defined $opt_t) { + print "\n-> Creating \"$video\"\n"; + print "$cmd\n"; + foreach $video (@{$videos{$video}}) { + print("rm -f $video\n"); + } + } else { + # Create the merged video + my $errno = system("$cmd"); + if($errno > 0) { $errno = $errno - 255; } + if($errno) { die "-E- make_mkv encountered some errors with exit code $errno\n"; } + # Fix the permissions + system("chown $owner \"$video\""); + system("chgrp $group \"$video\""); + system("chmod $mode \"$video\""); + # Remove the individual video files + foreach $video (@{$videos{$video}}) { + system("rm -f $video"); + } + } +} diff --git a/mts2mpg b/mts2mpg new file mode 100755 index 0000000..e3e4962 --- /dev/null +++ b/mts2mpg @@ -0,0 +1,25 @@ +#!/usr/bin/perl +# transcode_mts-mpg.pl +use File::Basename; +@files = glob "*.MTS"; + +foreach(@files) +{ + print "-> Encoding $_.MTS to $_.mpg\n"; + + # Find out if content is interlaced or not + $deint_option = "-deinterlace"; + $interlaced = system('ffmpeg -i "$_.MTS" 2>&1 | grep -q "frame rate differs"'); + if($interlaced != 0) { + print " Detected interlaced video content\n"; + } else { + print " Detected progressive video content\n"; + $deint_option = ""; + } + + # 2 pass encode the video to DVD compatible mpg + `ffmpeg -i $_ $deint_option -target ntsc-dvd -pass 1 $_.mpg`; + `rm $_.mpg`; + `ffmpeg -i $_ $deint_option -target ntsc-dvd -pass 2 $_.mpg`; + +} diff --git a/organize_videos b/organize_videos new file mode 100755 index 0000000..c606da3 --- /dev/null +++ b/organize_videos @@ -0,0 +1,188 @@ +#!/usr/bin/perl + +use File::Copy; +use File::Basename; +use Getopt::Std; +use File::stat; +use Time::localtime; + +# Configuration parameters +my $srcpathname = "/naspool/pictures/New Photos"; # Path to look for photos to move from +my $dstpathname = "/naspool/videos/HomeVideos"; # Path to move the photos to +my $merge_videos_by_day = "/naspool/videos/bin/merge_videos_by_day"; +my $minage = "+10"; # Files must be older than X minutes to move +my $owner = "ajp"; # The owner of the files after they are moved +my $group = "pip"; # The group of the files after they are moved +my $mode = "664"; # The mode to set on each file after they are moved +my $find_cmd = "find \"$srcpathname/\" -cmin $minage -a \\( -iregex \".*\.mov\" -o -iregex \".*\.3gp\" -o -iregex \".*\.mp4\" -o -iregex \".*\.mts\" -o -iregex \".*\.mkv\" \\)"; + +# Sanity check +if(! -d $srcpathname) { print "-E- Can't find srcpath: $srcpathname\n"; exit 1; } +if(! -d $dstpathname) { print "-E- Can't find dstpath: $dstpathname\n"; exit 1; } +if(! -x $merge_videos_by_day) { print "-E- Can't find required script: $merge_videos_by_day\n"; exit 1; } + +my %monthname2month = ( + "Jan" => "01", + "Feb" => "02", + "Mar" => "03", + "Apr" => "04", + "May" => "05", + "Jun" => "06", + "Jul" => "07", + "Aug" => "08", + "Sep" => "09", + "Oct" => "10", + "Nov" => "11", + "Dec" => "12" + ); + +my %month2monthname = ( + "01" => "Jan", + "02" => "Feb", + "03" => "Mar", + "04" => "Apr", + "05" => "May", + "06" => "Jun", + "07" => "Jul", + "08" => "Aug", + "09" => "Sep", + "10" => "Oct", + "11" => "Nov", + "12" => "Dec" + ); + +getopts("htv"); + +sub usage { + print "usage: $0 [-v] [-t]\n"; + print " -v = verbose; print file being moved (to)\n"; + print " -t = test; print what will happen, but don't do anything\n"; + return 1; +} + +sub is_folder_empty { + my $dirname = shift; + opendir(my $dh, $dirname) or die "Not a directory"; + return scalar(grep { $_ ne "." && $_ ne ".." } readdir($dh)) == 0; +} + +if(defined $opt_h) { usage(); exit 1; } + +# Only proceed if there are video files to organize +$video_files_found=`$find_cmd`; +if(!$video_files_found) { exit 0; } + +# Only one instance of this script running at a time +use File::Pid; +my $pidfile = File::Pid->new({file => "/tmp/organize_videos.pid"}); +exit if $pidfile->running(); +$pidfile->write(); + +# Print the date +system("date"); + +# Merge videos prior to copying them over to the destination path +my $errno = 0; +if(defined $opt_t) { + $errno=system("$merge_videos_by_day -s \"$srcpathname\" -t"); +} else { + $errno=system("$merge_videos_by_day -s \"$srcpathname\""); +} +if($errno > 0) { $errno = $errno - 255; } +if($errno) { die "-E- $merge_videos_by_day encountered some errors with exit code $errno\n"; } + +# Copy the videos over to the destination path +chdir "$srcpathname"; +print "$find_cmd\n" if($opt_v); +foreach $file (`$find_cmd`) { + + chomp($file); + $srcdir = dirname($file); + $file = basename($file); + $srcfile = $file; + $ext = $file; $ext =~ s/.*\.(\S+)$/$1/; $ext = lc($ext); + + print "Found movie: srcdir: $srcdir srcfile: $srcfile ext: $ext\n" if($opt_v); + + # Throw out files not in the current srcpath + if((! -f "$srcfile") && (! -f "$srcdir/$srcfile")) { next; } + + # Change all spaces to underscores in the filename + #$srcfile =~ s/ /_/g; + + # Make a note of the month, year, and day this video was taken (from the modification time of the file) + $date_taken = ctime(stat("$srcdir/$srcfile")->mtime); + + # Get the date taken from the filename + if($srcfile =~ /^(\d+)-(\d+)-(\d+)/) { + $year = $1; + $month = $2; + $day = sprintf("%02d",$3); + $monthnum = $month; + $monthname = lc($month2monthname{$month}); + } + # Get the date taken from the modification time + elsif($date_taken =~ /\S+\s+(\S+)\s+(\d+)\s+\S+\s+(\d+)/) { + $year = $3; + $month = $1; + $day = sprintf("%02d",$2); + $monthnum = $monthname2month{$month}; + $monthname = lc($month2monthname{$month}); + } else { + print "-E- Unable to parse year and month from this file: $srcdir/$srcfile\n"; + next; + } + + # We are ready to pick a destination folder to put the picture in + $dstdir = $dstpathname . "/" . $year; + $dstfile = $dstdir . "/" . $year . "-" . $monthnum . "-" . $day; + + # Check for duplicate filenames at the destination + $newfile = $dstfile . "." . "000"; + if(-e "$newfile.$ext") { + foreach $i ('001' .. '999') { + $newfile = $dstfile . "." . $i; + if(! -e "$newfile.$ext") { last; } + } + $dstfile = $newfile; + } + $dstfile = "$newfile.$ext"; + + if(defined $opt_t) { + print "-> Moving \"$srcdir/$srcfile\" to \"$dstfile\"\n"; + } else { + # Make sure the destination directories exist + $errno=system("mkdir -p \"$dstdir\""); + if($errno) { print "-E- Error creating dstdir: $dstdir\n"; next; } + # Perform the move operation from $srcdir/$srcfile -> $dstfile + if($opt_v) { print "-> Moving \"$srcdir/$srcfile\" to \"$dstfile\"\n"; } + # Make sure the dstfile doesn't exist, if it does, don't do the move + if(! -f "$dstfile") { + $errno=system("mv \"$srcdir/$srcfile\" \"$dstfile\" 2>/dev/null"); + if($errno) { print "-E- Error moving srcfile to dstfile: $srcdir/$srcfile -> $dstfile\n"; next; } + } else { + if($opt_v) { print "-> Skipping \"$srcdir/$srcfile\". Destfile \"$dstfile\" already exists.\n"; } + } + # Fix the permissions + system("chown $owner \"$dstfile\""); + system("chgrp $group \"$dstfile\""); + system("chmod $mode \"$dstfile\""); + } + + # Check to see if there is an empty sub directory to remove + if(($srcdir ne $srcpathname) && ($srcpathname ne ".")) { + if(is_folder_empty($srcdir)) { + print "-> Subdir detected for videos ($srcdir != $srcpathname)\n" if($opt_v); + if(! defined $opt_t) { + $tmpdir=`tempfile`; + system("rm $tmpdir"); + system("mv \"$srcdir\" $tmpdir > /dev/null 2>/dev/null"); + print "-> Moved empty subdir $srcdir to $tmpdir\n" if($opt_v); + } + } + } +} + +$pidfile->remove(); + +print "\n\n"; diff --git a/setprompt.pl b/setprompt.pl deleted file mode 100755 index c1c4280..0000000 --- a/setprompt.pl +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/perl - -$host = `hostname`; chomp($host); -%hostaliases = ( - "hpesajp" => "hp", - "pippin" => "pippin", - ); -$pwd = $ENV{PWD}; - -@aliases = ( - "/tmp_mnt/auto=>", - "$ENV{HOME}=>~", - "/net/=>", - "/home/=>/~", - ); - -$host = $hostaliases{$host} if defined $hostaliases{$host}; -foreach $alias (@aliases) { - @alias = split(/=>/, $alias); - if ( $alias[0] ne "" ) { - $pwd =~ s/$alias[0]/$alias[1]/; - } -} -if ($pwd =~ /^(~)?(.+)(\/.*?\/.*?\/.*)/) { - @prec = split(/\//, $2); - $pwd = "$1($#prec)$3" if $#prec; -} - -while ($pwd =~ /[\/]+([^\/]{13,})/) { - $segment = $oldseg = $1; - $segment =~ s/^(.{4}).*?(.{5})$/$1\.\.\.$2/; - $pwd =~ s/$oldseg/$segment/; -} -$whoami = `whoami`; -chomp( $whoami ); -if ( $whoami eq "root" ) { - $user = "\\[\\]ROOT\\[\\]:"; -} elsif( $whoami ne "ajp" ) { - $user = "\\[\\]$whoami\\[\\]@"; -} - -#Colors -if ( $ENV{COLOR_PROMPT} ne "no" ) -{ - $host = "\\[\\]$host\\[\\]" if $host; - $pwd = "\\[\\]$pwd\\[\\]"; -} - -print "$user$host:$pwd> "; - diff --git a/tsMuxeR b/tsMuxeR new file mode 100755 index 0000000..82aa2b1 Binary files /dev/null and b/tsMuxeR differ diff --git a/tsMuxerGUI b/tsMuxerGUI new file mode 100755 index 0000000..d2bbc24 Binary files /dev/null and b/tsMuxerGUI differ