Re: 'nother question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Saturday 10 July 2021 10:43:56 am Jim via tde-users wrote:
> On Sat, Jul 10, 2021 at 15:26 (+0000), dep via tde-users wrote:
> >
> > Maybe there's a script someplace that
> > will overright modified date with creation date. Not a thing everyone
> > would want to do, but useful in a variety of circumstances.
> > --
> > dep
>
> In case this is useful to you... it is a little script that sets the
> modification time of a JPEG to its EXIF time (which would then give
> you the date you seem to want in your file manager).  If you save it
> to a file called "set-photo-time" and give it execute perms, then you
> can run it as follows:
>         set-photo-time file1.jpg file2.jpg file3.jpg file4.jpg ...
> It requires the "exif" program, which you may or may not already have
> installed.  It works for me, but use at your own risk.
>

Another alternative I wrote several years ago:

http://inet-design.com/blogs/michael/extract-exif-datetimeoriginal-field-and-prepend-it-file-name-facilitate-image-sorting

Although looking at that, it's been up-rev'ed, so attaching the last version, 
but do read its comments in the code before running.

Best,
Michael
#!/bin/bash
#
#  Extracts the Exif:DateTimeOriginal field and prepends
#  it to the image file to facilitate sorting.
#
#  One off script, possibly has bugs, use at your own risk.
#
#  You will need imagemagick:
#    yum install imagemagick
#    apt-get install imagemagick
#    (whatever you use to install it)
#
# Script=addexiftime
# Author=Michael
# Email=staff_scripts at the commercial domain inet-design
# Website=http://www.inet-design.com/
# License=GPL
# Script repository=
# # # #

#   Prettify things
INVT="\033[7m";NORM="\033[0m";BOLD="\033[1m";BLINK="\033[5m";BLACK_F="\033[30m";BLACK_B="\033[40m";RED_F="\033[31m";RED_B="\033[41m";GREEN_F="\033[32m";GREEN_B="\033[42m";YELLOW_F="\033[33m";YELLOW_B="\033[43m";BLUE_F="\033[34m";BLUE_B="\033[44m";MAGENTA_F="\033[35m";MAGENTA_B="\033[45m";CYAN_F="\033[36m";CYAN_B="\033[46m";WHITE_F="\033[37m";WHITE_B="\033[47m";
####

#  Who am I?
MyName=`basename "$0"`

#  Check usage
if [ "$1" != "" ] && [ ! -d "$1" ] ; then
  echo -e "$YELLOW_F""Usage               :""$NORM  $GREEN_F""$MyName [\"Path\"] [\"File Filter\"]""$NORM"
  echo "Default Path        :  Current Directory"
  echo "Default File Filter :  *.jpg"
  echo -e "$YELLOW_F""Example             :""$NORM  $GREEN_F""$MyName \"/home/user/some directory\" \"*.jpeg\"""$NORM"
  exit
fi

#  Say Hello
StartTime=`date +%s`
CurrDateTime=$(date +"%y-%m-%d %H:%M:%S")
echo -e "$RED_F$CurrDateTime:$GREEN_F$BOLD Starting$NORM \"$MyName\" It can take awhile, need coffee?"

#  Do the work
if [ "$1" != "" ] ; then
  cd "$1"
fi

ResultsDir="`pwd`/results"

FileExt="*.jpg"
if [ "$2" != "" ] ; then
  FileExt="$2"
fi

FileExt="*"  # Comment this out or you get everything in the current dir.


FileList=`find ./ -maxdepth 1 -type f -name "$FileExt"`
FilesToProcess=`echo "$FileList" | wc -l`

D00=`date +"%y-%m-%d %H:%M:%S"`
MESG="Adding EXIF timestamps and copying to: $ResultsDir"
echo -e "$YELLOW_F$D00:$NORM $GREEN_F$MESG$NORM"
MESG="Files to Process :  $FilesToProcess"
echo -e "$YELLOW_F$D00:$NORM $GREEN_F$MESG$NORM"

FilesProcessed="0"
FilesProcessedwDate="0"
mkdir -p results

while IFS= read -r filename
do
  DateString=""
  NameofFile=`basename "$filename"`
  DateString=`identify -verbose "$NameofFile" | grep exif:DateTimeOriginal | awk '{ print $2" "$3 }' | sed -e s/":"/"."/g -e s/" "/"--"/g`
# echo
# echo $NameofFile , "$DateString"
# echo
  if [ "$DateString" = "" -o "$DateString" = ".--." ]; then
    DateString=`identify -verbose "$NameofFile" | grep exif:DateTime: | awk '{ print $2" "$3 }' | sed -e s/":"/"."/g -e s/" "/"--"/g`
    if [ "$DateString" = "" ]; then
      DateString="1900.00.00--00.00.00"
    fi
  fi
  #Strip off any existing dates
  NameofFile=`echo $NameofFile | sed s/"^[0-9]\{4\}.[0-9]\{2\}.[0-9]\{2\}.[0-9]\{2\}.[0-9]\{2\}.[0-9]\{2\}-\{1,2\}"/""/`
  NameofFile=`echo $NameofFile | sed s/"^[0-9]\{4\}.[0-9]\{2\}.[0-9]\{2\}-\{1,2\}[0-9]\{2\}.[0-9]\{2\}.[0-9]\{2\}-\{1,2\}"/""/`
  cp --preserve=timestamps "$filename" "results/$DateString--$NameofFile"
# echo "results/$DateString--$NameofFile"
  if [ "$DateString" != "1900.00.00--00.00.00" ]; then
    FilesProcessedwDate=$((FilesProcessedwDate + 1))
  fi
  FilesProcessed=$((FilesProcessed + 1))
  D00=`date +"%y-%m-%d %H:%M:%S"`
  MESG="Files Processed  :  $FilesProcessedwDate / $FilesProcessed"
  echo -en "$YELLOW_F$D00:$NORM $GREEN_F$MESG$NORM"
  echo -en "\r"
done <<< "$FileList"

D00=`date +"%y-%m-%d %H:%M:%S"`
MESG="Files Processed  :  $FilesProcessedwDate / $FilesProcessed"
echo -e "$YELLOW_F$D00:$NORM $GREEN_F$MESG$NORM"
D00=`date +"%y-%m-%d %H:%M:%S"`
MESG="Files in $ResultsDir : `ls -1 "$ResultsDir" | wc -l`"
echo -e "$YELLOW_F$D00:$NORM $GREEN_F$MESG$NORM"

#  Say Goodbye
END_TIME=`date +%s`
ELAPSED=`expr $END_TIME - $StartTime`
remainder="$(expr $ELAPSED % 3600)"
hours="$(expr $(expr $ELAPSED - $remainder) / 3600)"
seconds="$(expr $remainder % 60)"
minutes="$(expr $(expr $remainder - $seconds) / 60)"
CurrDateTime=$(date +"%y-%m-%d %H:%M:%S")
echo -e "$RED_F$CurrDateTime:$GREEN_F$BOLD Finished$NORM \"$MyName\"  Elapsed time: `printf %02d $hours`:`printf %02d $minutes`:`printf %02d $seconds`"


____________________________________________________
tde-users mailing list -- users@xxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxx
Web mail archive available at https://mail.trinitydesktop.org/mailman3/hyperkitty/list/users@xxxxxxxxxxxxxxxxxx

[Index of Archives]     [Trinity Devel]     [KDE]     [Linux Sound]     [ALSA Users]     [ALSA Devel]     [Linux Audio Users]     [Linux Media]     [Kernel]     [Gimp]     [Yosemite News]     [Linux Media]     [Trinity Desktop Environment]

  Powered by Linux