shbash脚本根据exif数据和文件时间戳移动图像(代码片段)

author author     2022-12-20     231

关键词:

#!/bin/bash

# Reads EXIF creation date from all .JPG files in the
# current directory and moves them carefully under
#
#   $BASEDIR/YYYY/YYYY-MM/YYYY-MM-DD/
#
# ...where 'carefully' means that it does not overwrite
# differing files if they already exist and will not delete
# the original file if copying fails for some reason.
#
# It DOES overwrite identical files in the destination directory
# with the ones in current, however.
#
# This script was originally written and put into
# Public Domain by Jarno Elonen <elonen@iki.fi> in June 2003.
# Feel free to do whatever you like with it.

# Defaults
TOOLS=(exiftool jq) # Also change settings below if changing this, the output should be in the format YYYY:MM:DD
DEFAULTDIR='/Users/jvhaarst/Pictures/van camera/van camera'
MAXDEPTH=-maxdepth 1
#MAXDEPTH=''
# activate debugging from here
#set -o xtrace
#set -o verbose

# Improve error handling
set -o errexit
set -o pipefail

# Check whether needed programs are installed
for TOOL in $TOOLS[*]
do
    hash $TOOL 2>/dev/null ||  echo >&2 "I require $TOOL but it's not installed.  Aborting."; exit 1; 
done

# Enable handling of filenames with spaces:
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")

# Use BASEDIR from commandline, or default if none given  
BASEDIR=$1:-$DEFAULTDIR

for FILE in $(find $(pwd -P) $MAXDEPTH -not -wholename "*._*" -iname "*.JPG" -or -iname "*.JPEG" -or -iname "*.CRW" -or -iname "*.THM" -or -iname "*.RW2" -or -iname '*.ARW' -or -iname "*AVI" -or -iname "*MOV" -or -iname "*MP4"  -or -iname "*MTS" -or -iname "*PNG") 
do
	INPUT=$FILE
	DATE=$(exiftool -quiet -tab -dateformat "%Y:%m:%d" -json -DateTimeOriginal "$INPUT" | jq --raw-output '.[].DateTimeOriginal')
	if [ "$DATE" == "null" ]  # If exif extraction with DateTimeOriginal failed
	then
		DATE=$(exiftool -quiet -tab -dateformat "%Y:%m:%d" -json -MediaCreateDate "$INPUT" | jq --raw-output '.[].MediaCreateDate')
	fi
	if [ -z "$DATE" ] || [ "$DATE" == "null" ] # If exif extraction failed
	then
		DATE=$(stat -f "%Sm" -t %F "$INPUT" | awk 'print $1'| sed 's/-/:/g')
	fi
	if [ ! -z "$DATE" ]; # Doublecheck
	then
		YEAR=$(echo $DATE | sed -E "s/([0-9]*):([0-9]*):([0-9]*)/\\1/")
		MONTH=$(echo $DATE | sed -E "s/([0-9]*):([0-9]*):([0-9]*)/\\2/")
		DAY=$(echo $DATE | sed -E "s/([0-9]*):([0-9]*):([0-9]*)/\\3/")
		if [ "$YEAR" -gt 0 ] & [ "$MONTH" -gt 0 ] & [ "$DAY" -gt 0 ]
		then
			OUTPUT_DIRECTORY=$BASEDIR/$YEAR_$MONTH_$DAY
			mkdir -pv $OUTPUT_DIRECTORY
			OUTPUT=$OUTPUT_DIRECTORY/$(basename $INPUT)
			if [ -e "$OUTPUT" ] && ! cmp -s "$INPUT" "$OUTPUT"
			then
				echo "WARNING: '$OUTPUT' exists already and is different from '$INPUT'."
			else
				echo "Moving '$INPUT' to $OUTPUT" 
				rsync -ah --progress "$INPUT"  "$OUTPUT"
				if ! cmp -s "$INPUT" "$OUTPUT"
				then
					echo "WARNING: copying failed somehow, will not delete original '$INPUT'"
				else
					rm -f "$INPUT"
				fi
			fi
		else
		  echo "WARNING: '$INPUT' doesn't contain date."
		fi
	else
		echo "WARNING: '$INPUT' doesn't contain date."
	fi
done

# restore $IFS
IFS=$SAVEIFS

shbash-日期模块-作为时间戳计数器的不同格式,函数和循环,用作父脚本的模块。(代码片段)

查看详情

移动文件并使用时间戳日期重命名的脚本

】移动文件并使用时间戳日期重命名的脚本【英文标题】:scripttomovefileandrenameitwithtimestampdate【发布时间】:2022-01-2312:33:36【问题描述】:我想创建用于移动文件并使用时间戳重命名文件的脚本。这是我的脚本mvD:\\data\\file\\Daily_f... 查看详情

如何合并两个不同的数据帧,时间戳略有不同

...10秒的记录数据中计算出15分钟的移动平均值。现在我想根据最近的时间戳将来自不同文件的两个时间序列数据(15分钟平均值和15分钟移动平均值)合并到一个新文件中。15分钟移动平均数据如下。正如 查看详情

根据文件名中的日期戳移动文件

】根据文件名中的日期戳移动文件【英文标题】:MoveFilesBasedonDateStampinFileName【发布时间】:2019-03-2100:00:09【问题描述】:不幸的是,我是PowerShell的新手,我有许多文件希望每月使用PowerShell存档。每个文件的文件名中都有一个YY... 查看详情

Bash脚本根据文件名中的时间戳删除早于n天的文件? [复制]

】Bash脚本根据文件名中的时间戳删除早于n天的文件?[复制]【英文标题】:Bashscriptdeletefilesolderthanndaysagobasedonthetimestampinfilename?[duplicate]【发布时间】:2016-05-2301:59:53【问题描述】:我有一些带有的日志文件somefiles.log.YYYY-mm-dd我... 查看详情

shbash时间戳(代码片段)

查看详情

shbash脚本:创建mysql数据库和用户(代码片段)

查看详情

shbash时间戳和/或日期(代码片段)

查看详情

shbash进程脚本捕获最佳正常运行时间和ps(代码片段)

查看详情

如何查看centos文件的时间戳

...弱化图像化操作,很多功能的实现都是通过配置文件或者脚本文件等等组成,而文件在修改过程中会不断的变化,那么这些变化如何查看呢,在Windows中,可以通过右击属性来查看,如下图,这里有3个基本信息就是创建时间、修... 查看详情

数据库迁移脚本和带有时间戳的版本控制

】数据库迁移脚本和带有时间戳的版本控制【英文标题】:Databasemigrationscriptsandversioningwithtimestamps【发布时间】:2014-07-1618:41:24【问题描述】:我们正在尝试使用Flyway(http://flywaydb.org/)来应用我们的数据库迁移脚本。大多数人都... 查看详情

shbash脚本将所有proxmox虚拟机的存储移动到不同的存储(代码片段)

查看详情

PostgreSQL 中基于时间戳的移动平均线

...动平均。我有两列:温度和时间戳(时间-日期),我想根据每15分钟的连续温度观测值执行移动平均值。换句话说,选择数据以基于15分钟的时间间隔执行平均。此外,对于不同的时间序列,可以有不同数量的观察。我的意思是... 查看详情

shbash用目录移动文件(代码片段)

查看详情

如何用date将时间戳转换为时间格式

方法和操作步骤如下:1、第一步,需要根据图示代码创建HTML文档,并创建JS标签,如下图所示,然后进入下一步。2、其次,完成上述步骤后,需要根据图示的代码new Date()创建日期对象,如下图所示,然后进入下一步。3... 查看详情

ALAsset 中缺少视频文件缩略图时间戳

】ALAsset中缺少视频文件缩略图时间戳【英文标题】:VideoFilethumbnailtimestampmissinginALAsset【发布时间】:2012-06-0511:30:58【问题描述】:嗨,我正在从ALAsset库中获取所有照片和视频缩略图。我的代码工作正常,我正在获取照片和视频... 查看详情

shbash单文件备份旋转脚本(代码片段)

查看详情

根据修改日期移动文件夹的脚本

】根据修改日期移动文件夹的脚本【英文标题】:scripttomovefolderbasedonmodifieddate【发布时间】:2013-06-0713:34:24【问题描述】:第一次发帖。背景-我的妻子是一名摄影师,她在编辑时拍了很多照片并将它们保存到驱动器(mnt/STStorage)... 查看详情