Downloading Manga Comics Using a Bash Script

My teenage daughter got immersed into manga, that is, Japanese comics books. That is not something that I would enjoy doing myself (never was much of a fan of comics books), but since she asked me to download the comics for offline reading, it became a father-and-daughter thing for us. So I decided to show her some Linux command line magic. After some tinkering I wrote a bash script that can download manga books from many popular manga sites to read offline, on an ebook reader.

So far I have downloaded the „My Hero Academia”, consisting of thousands of images. After downloading the images all you have to do is zip them, rename the archive from .zip to .cbz (comic book zip format), and you can upload the file to your ebook reader.

If you want to try it, here is the script content:

#!/bin/bash
#######################################################
## SETTINGS SECTION ###################################
#######################################################

## variable for the first chapter to download
first_chapter=1

## variable for the last chapter to download
last_chapter=98

## the uri of the manga images folder
## if the url of the first image is
## https://example.com/manga/book/0001-001.png
## the $uri variable should be set to
## https://example.com/manga/book – no trailing slash
uri="https://hot.leanbox.us/manga/Boku-No-Hero-Academia"

## YOU BETTER CHANGE NOTHING BELOW THIS LINE 🙂 ########

j=$first_chapter
while [ $j -le $last_chapter ]
do
echo ""
echo "========================="
echo "DOWNLOADING CHAPTER $j"
echo "========================="

# creates a chapter number with trailing
# zeros to make a four-digit number
ch=$(echo $j | awk ‘{printf("%04d", $1)}’)
  i=1
  status=0
  # script will run the loop till wget fails
  # to find a file and returns exit code 8
  while [ $status -ne 8 ]
  do
  num=$(echo $i | awk ‘{printf("%03d", $1)}’)
  sleep 1
  echo "Downloading page $i"

  wget –quiet $uri/$ch–$num.png
  status=$?
    if [[ $status -eq 0 ]]
      then
      i=$(( $i + 1 ))
      continue
    elif [[ status -eq 8 ]]
    then
      echo "End of chapter, starting another…"
    else
      echo "Could not get the file, wget returned "
      echo "exit code: $status"
      i=$(( $i + 1 ))
    fi
  done

j=$(( $j + 1 ))

done

Copy the text, paste it into a text file and save it with an *.sh extension (like mangadownload.sh). Then modify the three variables at the beginning of the file: $first_chapter, $last_chapter and $uri.

For example, let’s say you need to download „Tokyo Revengers” from https://manga4life.com. Find the book on the website with your browser, find the first chapter and first page of the book, rightclick on the first image and choose „Show Image”. Now you will see the real URI of the place where the images are stored:

https://official-ongoing.ivalice.us/manga/Tokyo-Revengers/0001-001.png

You will need the highlighted part of the address as the $uri variable, so replace the

uri="https://hot.leanbox.us/manga/Boku-No-Hero-Academia"

in my script with

uri="https://official-ongoing.ivalice.us/manga/Tokyo-Revengers"

in yours. Update the other two variable entering the right numbers for the first and last chapter to download. Then save the script, make it executable, and run it on Linux command line. The script will report the progress. After all is downloaded, pack the downloaded .png files into zip and rename it to .cbz. Hope it has been useful.


Paskelbta

,

sukūrė

Žymos:

Komentarai

Atsakymai į “Downloading Manga Comics Using a Bash Script”: 3

  1. Badge avataras
    Badge

    Thanks for the script, I will try it out for my favourite comics. I will have to modify the script more, I guess, as the file names are of a different structure on my favourite site.

  2. Dmitry G. avataras
    Dmitry G.

    Yes, that seems to be a useful script to retrieve series of images from various websites. You might also want to look at a more automated script here: https://github.com/NITDgpOS/manga – but I think yours is quite good, the simplicity of it… Just make an executable file and go!

  3. zoro.tv avataras

    Thanks for the script, I will try it out for my favorite comics.

Parašykite komentarą

El. pašto adresas nebus skelbiamas. Būtini laukeliai pažymėti *

Brukalų kiekiui sumažinti šis tinklalapis naudoja Akismet. Sužinokite, kaip apdorojami Jūsų komentarų duomenys.