shithub: img

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

View raw version
#!/bin/rc

flag e +

. ./fns.rc

rename webp WEBP -- *.webp >[2]/dev/null || {}
rename jpg JPG -- *.jpg >[2]/dev/null || {}
rename png PNG -- *.png >[2]/dev/null || {}

files=`{lscmd >[2]/dev/null}

if(~ $#files 0)
	exit 0

exiv2 -q --Force -t rename $files || {}

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