Fix comic extension

View previous topic View next topic Go down

Fix comic extension

Post  anomander on Mon Feb 24, 2014 3:34 am

I am requesting that comictagger be given an optional feature to automatically fix misnamed extensions and standardise case on comics as it sees them.

Examples:

cbr which is actually a zip would be auto renamed to cbz
CBZ be lower cased to cbz
etc
avatar
anomander

Posts : 74
Join date : 2013-03-28

View user profile

Back to top Go down

Re: Fix comic extension

Post  ComicTagger on Wed Feb 26, 2014 1:12 am

Not a bad feature if I ever get around to it.

In the meantime, here is a bash script that does what you want:

Code:

#!/bin/bash   

# A script to fix CBR/CBZ filename extensions that might be mislabeled
# (Also make the extensions all lowercase)

#---------------------------------------------------------------------------
function fix_one_file
{
   F=$1

   if [ ! -e "$F" ]
   then
      echo "File doesn't exist!"
      exit
   fi
      
   ISZIP=`file "$F" |grep  "Zip archive data"`
   ISRAR=`file "$F" |grep  "RAR archive data"`

   EXT="${F##*.}"
   EXT_LOWER=`echo $EXT | tr '[:upper:]' '[:lower:]'`

   if [ "$EXT_LOWER" != "cbz" -a "$EXT_LOWER" != "cbr" ]
   then
      echo File is not labeled as cbz or cbr.
      exit
   fi

   if [ "$ISZIP" != "" ]
   then
      if [ "$EXT" != "cbz" ]
      then
         NEW_EXT=cbz
      fi
   elif [ "$ISRAR" != "" ]
   then
      if [ "$EXT" != "cbr" ]
      then
         NEW_EXT=cbr
      fi
   else
      echo "Not a RAR or Zip archive!"
      exit
   fi

   if [ "$NEW_EXT" != "" ]
   then
      NEWNAME=`basename "$F" .$EXT`.$NEW_EXT
      mv "$F" "$NEWNAME"
      echo "New extension is .$NEW_EXT"
   else
      echo "Current extension (.$EXT) is good."
   fi
}
#---------------------------------------------------------------------------

if [ $# == 0 ]
then
   echo "Usage: $0 [COMIC FILE LIST]"
   echo "Fix the extension on improperly named CBZ and CBR files"
   exit
fi

# iterate over all args
IFS=$'\n'
for i in $*
do
   echo "$i: "`fix_one_file $i`
done
avatar
ComicTagger
Admin

Posts : 208
Join date : 2012-12-02

View user profile http://comictagger.forumotion.com

Back to top Go down

Re: Fix comic extension

Post  anomander on Fri Feb 28, 2014 3:32 am

It simply didnt occur to me to use "file". Elegant.

I have been using Perl and some logic around this "read (DATA, $data, 2);"... "if($data eq "PK") {" etc

Its pretty fast and because its Perl cross platform capable. Still all things scripting are beyond (or at least beyond the comfort level) of most users. Maybe not the ones that we have here yet but certainly most of the potential users.

Give it a ponder.
avatar
anomander

Posts : 74
Join date : 2013-03-28

View user profile

Back to top Go down

Re: Fix comic extension

Post  Sponsored content


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum