Advertisement
Guest User

Untitled

a guest
May 27th, 2015
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.58 KB | None | 0 0
  1. #!/bin/bash
  2. # Author: Nate Stokes
  3. # License: GPL3+
  4. # Based on a blog entry by Alon Ivtsan
  5. #
  6. #
  7. # mycolor='\033[0;30m' - colorise echo output to make it pretty!!
  8. # Notes 15/4 - Apparently I should be using tput instead of ascii escapes, but they no worky.
  9. # Notes 1/05/15 - Forked to add imagemajik scale function, because I've been getting heaps of broken cbr/cbz that are
  10. # fine on the computer, but won't display on Android. My solution for this is to basically batch rename and very slightly
  11. # resize the image files in between unrarring and rezipping - Seems to be working ok so far.
  12. # Intentions - To extend teh suite of scripts to fix without converting, convert and rename without resizing, etc etc.
  13. # Notes 06/05/15 - After struggling like hell to get the bigger comics to convert while still being able to use my
  14. # machine, I've gotten looping working properly with teh image scaling thingy. Now I'll want to see if it's faster on
  15. # small files, or if I should have a big file and a small file version of the script.
  16. #
  17. #
  18. # The purpose of this file is to extract a cbz file, rename the content files based to the original cbz name,
  19. # scale the image by a very small amount to negate the integrity issue with CBZ readers on Android and rearchive
  20. # in CBZ format.
  21. #
  22. #
  23. # Color escapes for prettiness
  24. red='\033[1;31m'
  25. green='\033[1;32m'
  26. blue='\033[1;34m'
  27. purple='\033[1;35m'
  28. NC='\033[0m' #no color - return echo to default
  29.  
  30. # Variables
  31. COUNTER=0
  32. tick=0
  33. BACKUP='original_cbrs'
  34.  
  35. # Attempt at using tput #
  36. #red='tput setaf 1'
  37. #green='tput setaf 2'
  38. #blue='tput setaf 3'
  39. #purple='tput setaf 4'
  40. #NC='tput sgr0'
  41.  
  42. mkdir "$BACKUP"; #Stick the old files out of the way once converted
  43.  
  44. for FILE in *{.cbr,.CBR}
  45. do
  46. [ -e "$FILE" ] || continue
  47. #echo -e "${red}**Converting ${green} $FILE ${red} to cbz format:${NC}"
  48. DIR="${FILE%.*}"
  49. mkdir "$DIR";
  50. mkdir "$DIR"/temp;
  51. echo -e "${blue}-Unrar ${green} $FILE ${NC}"
  52. unrar e ./"$FILE"  ./"$DIR"/temp;
  53. mv "$FILE" ./"$BACKUP"/;
  54. cd "$DIR"/temp;
  55.  
  56. nice -n 19 convert -verbose -resize 95% '*.jpg' ../"$DIR"-%03d.jpg;
  57.  
  58. # for i in *.jpg;
  59. # do
  60. # nice -n 19 convert -limit memory 5GiB -verbose -resize 95% "$i" ../a-"$DIR"-`printf %03d $tick`.jpg;
  61. # tick=$((tick + 1))
  62. # done
  63.  
  64. cd ../..;
  65. rm -r "$DIR"/temp;
  66.  
  67. echo -e "${purple}-Zipping Up: ${green} $DIR ${NC}"
  68. zip -rq "$DIR".cbz "$DIR";
  69. rm -r "$DIR";
  70. # Now Move CBR File to the old directory
  71.  
  72. COUNTER=$((COUNTER + 1))
  73. echo -e "${red}Conversion of ${green} $FILE ${red} successful!"
  74. echo -e "${red}  --Old CBR Copy Of ${green} $FILE ${red} Moved To ${blue}/old ${red}--${NC}\n"
  75. done
  76. echo -e "${red}All Files Completed, ${green} $COUNTER ${red} Files Converted.${NC}"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement