shithub: img

ref: 483783068655c0cc4b7710008f8edc3a559e0479
dir: /sdrip/rename.rc/

View raw version
#!/bin/rc -e

fn lscmd{
	for(ext in HEIC JPG PNG)
		ls *.^$ext >[2]/dev/null || {}
}

rename jpg JPG *.jpg >[2]/dev/null || {}
rename png PNG *.PNG >[2]/dev/null || {}
exiv2 -q --Force -t rename `{lscmd >[2]/dev/null} || true

sha1sum `{lscmd >[2]/dev/null} | awk '
function quote(s){
	gsub("''", "''''", s)
	return sprintf("%s", s)
}
/[0-9]{6}_[0-9]{6}\.[^.]*/{
	hash=substr($1, 1, 8)
	date=substr($2, 1, 15)
	match($2, ".[A-Z]+$")
	fext=substr($2, RSTART+1, RLENGTH-1)
	printf "mv %s %s.%s.full.%s\n", quote($2), date, hash, fext
	next
}
{
	hash=$1
	match($2, ".[A-Z]+$")
	fext=substr($2, RSTART+1, RLENGTH-1)
	printf "mv %s misc.%s.full.%s\n", quote($2), $1, fext
}' | rc