shithub: rc

ref: f3afdf563f784c0a5703496f48c1a72dff4617f4
dir: /crip/

View raw version
#!/bin/rc
# 2016-10-22T22:34:59-0400
# Repack .cbr as .cbz. Try to fix the file names.
rfork e
fn fixname{
	sed '
		s/( |\+|%C2)/_/g;
		s/(\(|\)|\'')//g;
		s/%..//g;
		s/(__|___)/_/g;
		s/_-_/-/g;
	'
}
fn usage {
	echo 'usage: crip [ -cdnrz ]' >[1=2]
	exit usage
}
zip=(zip -v -f)
switch($1){
case -c
	for(i in *.cbr){
		wdir=`{pwd}
		file=`{echo $"i | urlencode | fixname | sed 's/\.cbr$/\.cbz/g'}
		dir=`{echo $"file | sed 's/\.cbz$//g'}
		mkdir crip.$file &&
		cd crip.$file &&
		unrar x $"wdir'/'$"i &&
		crip -n &&
		cd $wdir &&
		mv crip.$file $dir &&
		eval $zip $file $dir &&
		rm -r $dir &&
		rm $"i &&
		echo $file
	}
case -d
	for(i in `{ls | grep -v -e '\.cb(r|z)'}){
		file=`{echo $"i | urlencode | fixname}
		if(! ~ $i $file)
			mv $"i $file
		eval $zip $file.cbz $file &&
		rm -rf $file
		echo $file.cbz
	}
case -n
	for(i in *){
		file=`{echo $"i | urlencode | fixname}
		if(! ~ $i $file)
			mv $"i $file
		echo $file
	}
case -r
	for(i in *.rar){
		file=`{echo $"i | urlencode | fixname | sed 's/\.rar$/\.cbr/g'}
		if(! ~ $i $file)
			mv $"i $file
		echo $file
	}
case -z
	for(i in *.zip){
		file=`{echo $"i | urlencode | fixname | sed 's/\.zip$/\.cbz/g'}
		if(! ~ $i $file)
			mv $"i $file
		echo $file
	}
case *
	usage
}