Exiftool 使用实例

更新

Twitter整理

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
# 对于 LIJIA-1203879100760260608-20191209_112839-img1.jpg 的格式
# user-post-time-img
# 写入时间
exiftool '-XMP:DateCreated<${Filename;m/(.*)-(.*)-(.*)-(.*)/;$_="$3"}' -d %Y%m%d_%H%M%S 
# 写入url: twitter.com/$user/status/$post
exiftool '-BaseUrl<${Filename;m/(.*)-(.*)-(.*)-(.*)/;$_="https://twitter.com/$1/status/$2"}'
exiftool '-ImageCreatorName<${Filename;m/(.*)-(.*)-(.*)-(.*)/;$_="$1"}'
exiftool '-ImageCreatorID<${Filename;m/(.*)-(.*)-(.*)-(.*)/;$_="https://twitter.com/$1"}'
exiftool '-SeriesNumber<${Filename;m/(.*)-(.*)-(.*)-(.*).([a-z1-9]+)/;$_="$4"}'
exiftool -ImageSupplierName=Twitter 

# 写入标题
exiftool '-Title<$ImageCreatorName'

# 将url写入description
exiftool '-ImageDescription<BaseUrl'
# 将 Twitter 写入关键词
exiftool '-Subject-=Twitter' '-Subject+=Twitter' 
# 重命名
exiftool  '-filename<$DateTimeOriginal-$Title%+2c%E'   -d '%Y-%m-%d'    -progress  -fileorder filename

Weibo整理

用户信息生成与更新

首先用如下命令生成数据库文件ImageSupplierName/ImageSupplierID

1
2
3
4
5
function wb-database-gen(){
	SupplierName="Weibo"
  mkdir -p  $CRAWLER_INFO_HOME/$SupplierName
  fd -td --exact-depth 1 -x exiftool -ImageCreatorID=https://weibo.com/u/{} -ImageSupplierID={} -ImageSupplierName=$SupplierName "$CRAWLER_INFO_HOME/$SupplierName/{}.xmp" -progress
}

更新数据库文件

1
2
3
4
5
6
7
function wb-database-update{
  for file in "$@"; do
    SupplierName=$(exiftool -s3 -ImageSupplierName -- $file)
    SupplierID=$(exiftool -s3 -ImageSupplierID -- $file)
    exiftool -tagsfromfile $file $CRAWLER_INFO_HOME/$SupplierName/$SupplierID.xmp -progress
  done
}

将用户信息写入图片中

1
fd -td --exact-depth 1 -x exiftool -tagsfromfile "$CRAWLER_INFO_HOME/Weibo/{}.xmp" -r -progress -m {}

写入图片信息

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# 获取时间; 文件名格式为`20200722_Jcr1a7otC_6.jpg`  [^\W_] 表示26个字母+数字
function wb-write-info-from-filename(){
  exiftool -m -d "%Y%m%d" -progress -r $1 \
    '-DateTimeOriginal<${Filename;m/(\d*)_([^\W_]+)_?(\d*).([a-z1-9]+)/;$_=$1}' \
    '-BaseUrl<https://weibo.com/$ImageSupplierID/${Filename;m/(\d*)_([^\W_]+)_?(\d*).([a-z1-9]+)/;$_=$2}' \
    '-SeriesNumber<${Filename;m/(\d*)_([^\W_]+)_?(\d*).([a-z1-9]+)/;$_=$3}' \
    '-Title<$Artist' \
    '-ImageDescription<BaseUrl' \
    '-Subject-=Weibo' '-Subject+=Weibo' \
}
1
2
3
# 重命名
exiftool  '-testname<$Artist-$DateTimeOriginal%+2c%E'   -d '%Y-%m-%d'    -progress -fileorder Filename
exiftool '-directory<$ImageCreatorName' ''
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
function _update_img_meta(){
SupplierID=$(exiftool -s3 -ImageSupplierID -- $file)
SupplierName=$(exiftool -s3 -ImageSupplierName -- $file)
 exiftool -tagsfromfile $file
}

function _wb-info-update-args(){
  for file in "$@"; do
    SupplierID=$(exiftool -s3 -ImageSupplierID -- $file)
    SupplierName=$(exiftool -s3 -ImageSupplierName -- $file)
    exiftool -tagsfromfile $file $CRAWLER_INFO_HOME/$SupplierName/$SupplierID.xmp -progress
  done
}

function _wb-info-update-pipe(){
  while read -r file; do
    SupplierID=$(exiftool -s3 -ImageSupplierID -- $file)
    SupplierName=$(exiftool -s3 -ImageSupplierName -- $file)
    exiftool -tagsfromfile $file $CRAWLER_INFO_HOME/$SupplierName/$SupplierID.xmp -progress
  done
}

更新图片信息

1
2
3
4
5
6
7
function wb-img-update-from-datebase{
  for file in "$@"; do
    SupplierName=$(exiftool -s3 -ImageSupplierName -- $file)
    SupplierID=$(exiftool -s3 -ImageSupplierID -- $file)
    exiftool -tagsfromfile  $CRAWLER_INFO_HOME/$SupplierName/$SupplierID.xmp $file -progress
  done
}

文件夹

1
2
3
4
5
6
exiftool '-directory<$DateCreated' -d %Y/%Y-%m \
-Filename=%f%+2c%E    

exiftool '-directory<$ImageSupplierName/$DateCreated' -d %Y-%m -Filename=%f%+2c%E   -if 'not $Rating'

exiftool '-directory<${ImageSupplierName}-S${Rating}/${Title}'  -Filename=%f%+2c%E -if '$Rating==5'   
1
exiftool '-Subject-=Twitter' '-Subject+=Twitter' if '$Subject =~ "Instagram"'

IF

1
2
3
4
5
6
7
8
9
 -if '$ImageSupplierName eq "Weibo" ' .
 -if '$Subject =~ /weibo/i ' # case insenstive
 -if '$Subject =~ /weibo/ ' 


 -if '$DateTimeOriginal ge "2017"'
 -if ' not $DateTimeOriginal ge "2017"'
 
 
updatedupdated2023-06-052023-06-05
Update https-ca.md