Create ComicRack compatible cb7 archives
Well, I have a few directories containing comics (in JPG/PNG) format. Since I’m lazy and didn’t want to create a 7z by hand for each directory, I wrote a short script that’ll do the work for me 😄 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 #!/bin/bash # Mangle IFS, since space is a valid default IFS SAVEIFS=$IFS IFS=$(echo -en "\n") # Locate the 7z binary if [ -x "/usr/bin/7zr" ] ; then ZIP='/usr/bin/7zr' fi if [ -x "/usr/syno/bin/7z" ] ; then ZIP='/usr/syno/bin/7z' fi ORIG_DIR="$PWD" #find $DIR -mindepth 1 -maxdepth 1 -type d -print0 | sed "s,./,," | while IFS= read -r -d '' dir; do find $DIR -mindepth 1 -maxdepth 1 -type d -print0 | while IFS= read -r -d '' dir; do dir="${dir##*/}" case $dir in extracted|@eaDir*) continue;; esac ARCHIVE="${dir}" # Remove tags from file names ARCHIVE="$( echo $ARCHIVE | sed -e "s,\[SaHa\] ,,g" )" ARCHIVE="$( echo $ARCHIVE | sed 's/([^)]*)//g' )" ARCHIVE="$( echo $ARCHIVE | sed -e "s,_, ,g" )" ARCHIVE="$( echo $ARCHIVE | sed -e 's/[ \t]*$//' )" # Decide, whether "," or "-" separates writer and series # Get series and author from directory name WRITER="$( echo ${ARCHIVE} | cut -d, -f1 | sed "s,./,," )" SERIES="$( echo ${ARCHIVE} | cut -d, -f2- | sed -e 's/^[ \t]*//' )" # Check if the pictures are directly beyond the subdirectory. Otherwise # report the directory and skip it. HAS_PICTURES="$( find "$dir" -mindepth 1 -maxdepth 1 -type f -regex ".*\.\(PNG\|png\|jpg\|JPG\|jpeg\|JPG\)" | wc -l )" if [ "$HAS_PICTURES" -lt 1 ] ; then echo echo "Attention: $dir" echo "has no pictures in the immediate directory. Please move the pictures" echo "from the subdirectory to the immediate directory." echo continue fi # Create a bare ComicInfo.xml cat > "$dir/ComicInfo.xml" << EOF <?xml version="1.0"?> <ComicInfo xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <Series>$SERIES</Series> <Writer>$WRITER</Writer> <Genre>Adult</Genre> <LanguageISO>en</LanguageISO> <AgeRating>Adults Only 18+</AgeRating> </ComicInfo> EOF if [ -f "$ORIG_DIR/$ARCHIVE.cb7" ] ; then echo "$ARCHIVE.cb7: Skipping, since the new archive already exists ?" continue else cd "$dir" # Create the cb7 archive echo "Creating $ARCHIVE.cb7" ret=$( $ZIP a "$ORIG_DIR/$ARCHIVE.cb7" * &>/dev/null && echo 0 || echo 1 ) cd $ORIG_DIR if [ $ret -eq 0 -a -f "$ORIG_DIR/$ARCHIVE.cb7" ] ; then rm -rf "$dir" &>/dev/null fi fi done # restore $IFS IFS=$SAVEIFS