shithub: img

ref: ab3a209ed97ea6d9e085a32bf806fd9395615ade
dir: /sdrip/rename.rc/

View raw version
#!/bin/rc -e

. ./fns.rc

rename webp WEBP -- *.webp >[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)
	src=quote($2)
	dst=sprintf("%s.%s.full.%s", date, hash, fext)
	if(src != dst)
		printf "mv -- %s %s\n", src, dst
	next
}
{
	hash=$1
	match($2, ".[A-Z]+$")
	fext=substr($2, RSTART+1, RLENGTH-1)
	src=quote($2)
	dst=sprintf("misc.%s.full.%s", $1, fext)
	if(src != dst)
		printf "mv -- %s %s\n", src, dst
}' | rc