ComicTagger Talk
Would you like to react to this message? Create an account in a few clicks or log in to continue.

Fix comic extension

2 posters

Go down

Fix comic extension Empty Fix comic extension

Post  anomander 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
anomander
anomander

Posts : 74
Join date : 2013-03-28

Back to top Go down

Fix comic extension Empty Re: Fix comic extension

Post  ComicTagger 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
ComicTagger
ComicTagger
Admin

Posts : 209
Join date : 2012-12-02

https://comictagger.forumotion.com

Back to top Go down

Fix comic extension Empty Re: Fix comic extension

Post  anomander 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.
anomander
anomander

Posts : 74
Join date : 2013-03-28

Back to top Go down

Fix comic extension Empty Re: Fix comic extension

Post  Sponsored content


Sponsored content


Back to top Go down

Back to top

- Similar topics

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