Welcome, Guest
Python Scripts for ComicRack
  • Page:
  • 1
  • 2

TOPIC: cbr2cbz RAR to ZIP conversion for linux

Re: cbr2cbz RAR to ZIP conversion for linux 4 years 9 months ago #30417

  • startreksteve
  • startreksteve's Avatar
  • Offline
  • Platinum Boarder
  • Posts: 402
  • Thank you received: 28
  • Karma: 7
Well, you could use it in a Virtualbox on a shared folder of comics on your Linux box.
The administrator has disabled public write access.

Re: cbr2cbz RAR to ZIP conversion for linux 4 years 9 months ago #30418

I haven't used windows on my computers since -98-99(?) and I'm not starting now. :)

Regarding the file integrity check feature, I posted a question over at Stackoverflow, let's see how that pan out over there.
Last Edit: 4 years 9 months ago by danielpublic.
The administrator has disabled public write access.

Re: cbr2cbz RAR to ZIP conversion for linux 4 years 9 months ago #30419

Meanwhile...

I removed unrar as an dependency and use p7zip instead, as it can extract rar-files.
#!/bin/bash
#Source: http://comicrack.cyolito.com/forum/13-scripts/30013-cbr3cbz-rar-to-zip-conversion-for-linux
echo "Converting CBRs to CBZs"

# Set the "field separator" to something other than spaces/newlines" so that spaces
# in the file names don't mess things up. I'm using the pipe symbol ("|") as it is very
# unlikely to appear in a file name.
IFS="|"

# Set working directory where to create the temp dir. The user you are using must have permission
# to write into this directory.
# For performance reasons I'm using ram disk (/dev/shm/) in Ubuntu server.
WORKDIR = "/dev/shm/"

# Set name for the temp dir. This directory will be created under WORDDIR
TEMPDIR="cbr2cbz"

# The script should be invoked as "cbr2cbz {directory}", where "{directory}" is the
# top-level directory to be searched. Just to be paranoid, if no directory is specified,
# then default to the current working directory ("."). Let's put the name of the
# directory into a shell variable called SOURCEDIR.
# Note: "$1" = "The first command line argument"
if test -z $1; then
        SOURCEDIR=`pwd`
else
        SOURCEDIR="$1"
fi

echo "Working from directory $SOURCEDIR"

# We need an empty directory to work in, so we'll create a temp directory here
cd $WORKDIR
mkdir $TEMPDIR
# and step into it
cd $TEMPDIR

# Now, execute a loop, based on a "find" command in the specified directory. The
# "-printf "$p|" will cause the file names to be separated by the pipe symbol, rather than
# the default newline. Note the backtics ("`") (the key above the tab key on US
# keyboards).
for CBRFILE in `find $SOURCEDIR -name "*.cbr" -printf "%p|"`; do

        # Now for the actual work. First, extract the base file name (without the extension)
        # using the "basename" command. Warning: more backtics.
        BASENAME=`basename $CBRFILE ".cbr"`

        # And the directory path for that file, so we know where to put the finished ".cbz"
        # file.
        DIRNAME=`dirname $CBRFILE`

        # Now, build the "new" file name,
        NEWNAME="$BASENAME.cbz"

        # We use RAR file's name to create folder for unpacked files
        echo "Processing $CBRFILE"
        mkdir "$BASENAME"
        # and unpack the rar file into it
        7z x "$CBRFILE" -O"$BASENAME"
        cd "$BASENAME"

        # Lets ensure the permissions allow us to pack everything
        sudo chmod 777 -R ./*

        # Put all the extracted files into new ".cbz" file
        7z a -tzip -mx=9 "$NEWNAME" *

        # And move it to the directory where we found the original ".cbr" file
        mv "$NEWNAME" $DIRNAME/"$NEWNAME"

        # Finally, "cd" back to the original working directory, and delete the temp directory
        # created earlier.
        cd ..
        rm -r "$BASENAME"

        # Delete the RAR file also
        rm "$CBRFILE"

done

# At the end we cleanup by removing the temp folder from ram disk
cd ..
echo "Conversion Done"
rm -r $TEMPDIR
Last Edit: 4 years 9 months ago by danielpublic.
The administrator has disabled public write access.

Re: cbr2cbz RAR to ZIP & JPEG to WEBP conversion for linux 4 years 3 months ago #36512

  • Karvajalka
  • Karvajalka's Avatar
  • Offline
  • Senior Boarder
  • Posts: 67
  • Thank you received: 4
  • Karma: 2
As the WEBP seems to be a hot potato at the moment. Here is another version on the conversion script. I added JPEG -> WEBP conversion (with ImageMagic) to save some space. Also I had to change it to process ZIPs to get the WEBP goodness into those files as well.

The script has been working pretty well for awhile. There is still plenty to improve. I might even do it if I ever stop being lazy :)

#!/bin/bash
echo "Converting CBRs to CBZs and JEPG to WEBP"

# Set the "field separator" to something other than spaces/newlines" so that spaces
# in the file names don't mess things up. I'm using the pipe symbol ("|") as it is very
# unlikely to appear in a file name.
IFS="|"

# Set working directory where to create the temp dir. The user you are using must have permission
# to write into this directory. 
# For performance reasons I'm using ram disk (/dev/shm/) in Ubuntu server.
WORKDIR="/dev/shm/"

# Set name for the temp dir. This directory will be created under WORDDIR 
TEMPDIR="cbr2cbz"

# The script should be invoked as "cbr2cbz {directory}", where "{directory}" is the
# top-level directory to be searched. Just to be paranoid, if no directory is specified,
# then default to the current working directory ("."). Let's put the name of the
# directory into a shell variable called SOURCEDIR.
# Note: "$1" = "The first command line argument"
if test -z $1; then
	SOURCEDIR=`pwd`
else
	SOURCEDIR="$1"
fi

echo "Working from directory $SOURCEDIR"

# We need an empty directory to work in, so we'll create a temp directory here
cd $WORKDIR
mkdir $TEMPDIR
# and step into it
cd $TEMPDIR

# Now, execute a loop, based on a "find" command in the specified directory. The
# "-printf "$p|" will cause the file names to be separated by the pipe symbol, rather than
# the default newline. Note the backtics ("`") (the key above the tab key on US
# keyboards).
for CBRFILE in `find $SOURCEDIR -regex ".*\(cbr\|CBR\|cbz\|CBZ\)$" -printf "%p|"`; do

	EXTENSION=`echo ${CBRFILE##*.}`

	# Now for the actual work. First, extract the base file name (without the extension)
	# using the "basename" command. Warning: more backtics.
	BASENAME=`basename $CBRFILE ".$EXTENSION"`

	# And the directory path for that file, so we know where to put the finished ".cbz"
	# file.
	DIRNAME=`dirname $CBRFILE`

	# Now, build the "new" file name,
	NEWNAME="$BASENAME.cbz"

	# We use RAR file's name to create folder for unpacked files
	echo "Processing $CBRFILE"
	mkdir "$BASENAME"
	echo ${EXTENSION^^}
	if [ "$(echo ${EXTENSION^^})" == 'CBR' ]
		then
		# and unpack the RAR file into it
		unrar e "$CBRFILE" "$BASENAME"
	fi
	
	if [ "$(echo ${EXTENSION^^})" == 'CBZ' ]
		then
		# and unpack the ZIP file into it
		unzip -j "$CBRFILE" -d "$BASENAME"
	fi
	
	cd "$BASENAME"

	# Lets ensure the permissions allow us to pack everything
	sudo chmod 777 -R ./*

	# Lets use convert from ImageMagic package to convert JEPGs to WEBP.
	for f in *.jpg; do echo "Converting $f to WEBP"; convert "$f" -quality 80 -define webp:auto-filter=true -define webp:method=6 "$(basename "$f" .jpg).webp"; rm -f $f; done

	# Put all the extracted files into new ".cbz" file
	zip "$NEWNAME" *

	# And move it to the directory where we found the original ".cbr" file
	mv "$NEWNAME" $DIRNAME/"$NEWNAME"

	# Finally, "cd" back to the original working directory, and delete the temp directory
	# created earlier.
	cd ..
	rm -r "$BASENAME"

	# Delete the RAR file also
	if [ "$EXTENSION" != 'cbz' ]
		then
			rm "$CBRFILE"
	fi

done

# At the end we cleanup by removing the temp folder from ram disk
cd ..
echo "Conversion Done"
rm -r $TEMPDIR
The administrator has disabled public write access.
The following user(s) said Thank You: gebakkenei

Re: cbr2cbz RAR to ZIP & JPEG to WEBP conversion for linux 3 years 11 months ago #37775

  • gebakkenei
  • gebakkenei's Avatar
  • Offline
  • Fresh Boarder
  • Posts: 6
  • Karma: -2
Any chance somebody can create an Android app to repack single CBR-files (or whole dirs?) from CBR-JPEG to CBZ-WebP?
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.185 seconds

Who's Online

We have 270 guests and 5 members online