Sunday, March 14, 2010

Uploading files to my Popcorn Hour

I was for some time using SCP to transfer files from my Mac to my Popcorn Hour media player until I discovered Curl. Curl or rather cURL is a utility for transferring files using various internet protocols using URL syntax.

For a one off transfer you can simply use

curl -T {file} -u {user}:{password} ftp://{ip address}{path}

For sending a complete folder I manage to find a useful script (batch_folder_upload.sh) and adapt it for my needs

#!/bin/sh 

Pwd=$(pwd)
fullDir=$Pwd/$1

echo $fullDir

if [ ! -d $fullDir ]
then
   echo "Could not find folder to upload from $fullDir"
   exit -1
fi

for file in $1/* ; do
 echo "Uploading $file to /Upload/$1"
 curl --globoff --ftp-create-dirs -T $file -u ftpuser:1234 ftp://192.168.1.9/Upload/$1/
done

I have included the --globoff argument as curl does not like the use of [ or ] in the filename. Apparantly there is a fix coming for this issue.

Simply invoke the script

   $ ./batch_upload

Format your code blocks for blogging

Here is a nice link I found for converting code blocks to be viewed in a more readable way.

Formatting Code blocks for pasting into blog posts

Adding image borders and EXIF tagging

I found a web blog from Frederico Maggi who posted a nice tutorial for batch editing image files to add a border with some Exif data.

The work by Frederico was a great start and I took his work and made a few treaks. The major change I made was to the ~/bin/lr_borderscript. I felt that the border size was too small and that the text was too small. I also adapted the script to perform a rename using the convert utility

#!/bin/sh
#File: ~/bin/lr_border
 
year=$($HOME/bin/exiv_year $1)
data=$($HOME/bin/exiv_data $1)
 
name="Carl Wainwright © "
 
if [ -n "$year" ]
then
name=$name" "$year
fi

inname=`convert $1 -format "%t" info:` 
echo "Processing $inname"

outname=${inname}_mod.jpg
#convert $1 -resize 50% $outname
convert $1 $outname

echo "Writing to $outname"
 
mogrify -gravity North -border 5x5 -bordercolor black $outname
mogrify -gravity North -border 1x1 -bordercolor grey $outname
mogrify -gravity North -border 60x60 -bordercolor black $outname
 
if [ -n "$data" ]
then
mogrify -pointsize 30 -fill white -gravity SouthEast -annotate +25+6 "$name" -gravity SouthWest -annotate +25+6 "$data" $outname
else
mogrify -pointsize 30 -fill white -gravity SouthEast -annotate +25+6 "$name" $outname
fi

I also modified the exiv_data script to match the Exif data for my Konica Minolta 7D.


#!/bin/sh
#File: $HOME/bin/exiv_data
time=$(exiv2 -PEkt pr $1 2>/dev/null | tr -s " " " " | grep -E "\.Photo\.ExposureTime" | awk '{print $2}')
focal=$(exiv2 -PEkt pr $1 2>/dev/null | tr -s " " " " | grep -E "\.FocalLength " | awk '{print $2}')
aperture=$(exiv2 -PEkt pr $1 2>/dev/null | tr -s " " " " | grep -E "\.Photo\.FNumber" | awk '{print $2}')
iso=$(exiv2 -PEkt pr $1 2>/dev/null | tr -s " " " " | grep -E "\.ISOSpeedRatings" | awk '{print $2}')
 
if [ -n "$time" -a -n "$focal" -a -n "$aperture" -a -n "$iso" ]
then
echo $focal"mm, "$time" @ "$aperture" (ISO "$iso")"
fi

Executing the above script can be done as follows 

ls *.JPG | while read file; do ~/bin/lr_borderscript_new $file; done

Start of a new Adventure

First post of my blogging adventure...

First stop to collect some of my recent scripts and command lines to get things going..