├── .gitignore ├── LICENSE ├── README.md └── manga-cli /.gitignore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/prsh11/manga-cli/1469bcefada87a636d4d13b666a4b5da190af336/.gitignore -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 - present Prashant Baid 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Manga CLI 2 | ## Table of contents 3 | 4 | - [Install](#Install) 5 | - [Mac](#Mac) 6 | - [Linux](#Linux) 7 | - [Arch](#Arch) 8 | - [Uninstall](#Uninstall) 9 | - [Dependencies](#Dependencies) 10 | 11 | ## Install 12 | > Check the [dependencies](#dependencies) 13 | ### Mac 14 | ```bash 15 | # dependencies 16 | brew tap zegervdv/zathura 17 | brew install pup 18 | brew install zathura 19 | brew install bash # plugin requires new version of bash 4.xx, while macOS uses 3.xx 20 | 21 | # cbz support 22 | brew install zathura-cb 23 | 24 | # pdf support 25 | brew install imagemagick 26 | brew install zathura-pdf-mupdf 27 | 28 | # install manga-cli 29 | git clone https://github.com/prsh11/manga-cli.git && cd manga-cli 30 | sudo cp manga-cli /usr/local/bin/manga-cli 31 | ``` 32 | 33 | ### Arch 34 | ```bash 35 | yay -S manga-cli-git 36 | ``` 37 | ### Linux 38 | > Install dependencies with your respective package manager 39 | ```bash 40 | git clone https://github.com/prsh11/manga-cli.git && cd manga-cli 41 | sudo cp manga-cli /usr/local/bin/manga-cli 42 | ``` 43 | 44 | ## Uninstall 45 | 46 | - Linux & Mac: `rm /usr/local/bin/manga-cli` 47 | - Arch: `yay -Rns manga-cli-git` 48 | 49 | ## Dependencies 50 | 51 | - [pup](https://github.com/ericchiang/pup) 52 | - [zathura](https://github.com/pwmt/zathura) 53 | - [zathura-cb](https://github.com/pwmt/zathura-cb) 54 | - [curl](https://curl.se/) 55 | 56 | ### PDF support 57 | 58 | - [zathura-pdf-mupdf](https://github.com/pwmt/zathura-pdf-mupdf) 59 | - [imagemagick](https://imagemagick.org/index.php) 60 | -------------------------------------------------------------------------------- /manga-cli: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | trap exit_script SIGINT SIGTERM 4 | 5 | search_url="https://m.manganelo.com/search/story/" 6 | image_dir="$HOME/.cache/manga-cli/" 7 | 8 | # File format 9 | file_format="cbz" 10 | pdf_viewer=zathura 11 | 12 | # colors 13 | Green='\033[0;32m' 14 | Yellow='\033[0;33m' 15 | White='\033[0;37m' 16 | EndColor='\033[0m' 17 | 18 | mangaName="${@: -1}" 19 | prog="$0" 20 | 21 | # Commands 22 | if [[ "$OSTYPE" == "darwin"* ]]; then # Mac OSX 23 | ls=/bin/ls 24 | else 25 | ls=/usr/bin/ls 26 | fi 27 | 28 | help_text() { 29 | while IFS= read -r line; do 30 | printf "%s\n" "$line" 31 | done <<-EOF 32 | 33 | Usage: 34 | ${prog} [option] 35 | Options: 36 | -p change file format to pdf 37 | -c clears the downloaded files 38 | -o select pdf viewer 39 | -h displays this message 40 | EOF 41 | } 42 | 43 | 44 | exit_script() { 45 | trap - SIGINT SIGTERM 46 | echo "Exiting script" 47 | end_color 48 | exit 1 49 | } 50 | 51 | 52 | end_color() { 53 | echo -n -e "${EndColor}" 54 | } 55 | 56 | search_manga() { 57 | echo -n -e "${Yellow}Search manga: " 58 | read -r mangaName 59 | mangaName="${mangaName// /_}" 60 | mangaName="${mangaName//-/_}" 61 | 62 | mapfile -t mangaNames < <(curl -s "$search_url$mangaName" | pup "div.item-right h3 a text{}") 63 | declare -p mangaNames >/dev/null 64 | 65 | # Manga Ids 66 | mapfile -t mangaIds < <(curl -s "$search_url$mangaName" | pup "div.item-right h3 a attr{href}") 67 | declare -p mangaIds >/dev/null 68 | 69 | i=1 70 | for each in "${mangaNames[@]}"; do 71 | echo -e "${White}[$i]$each" 72 | ((i = i + 1)) 73 | done 74 | 75 | echo -n -e "${Yellow}Enter Number: " 76 | read -r mangaNumber 77 | 78 | mangaNumber="$((mangaNumber - 1))" 79 | name="${mangaNames[$mangaNumber]}" 80 | name="${name// /_}" 81 | name="${name//[^[:alnum:]]/}" 82 | mangaLink="${mangaIds[$mangaNumber]}" 83 | 84 | } 85 | 86 | select_chapter() { 87 | echo -n -e "${Yellow}Enter chapter number: " 88 | read -r chapterNumber 89 | 90 | get_images "$mangaLink" "$chapterNumber" 91 | 92 | } 93 | 94 | create_file() { 95 | if [ $file_format == "pdf" ]; then 96 | echo "Converting to pdf..." 97 | convert $($ls -v $image_dir*.jpg) $image_dir$name-$chapterNumber.pdf 98 | rm $image_dir/*.jpg 99 | clear 100 | $pdf_viewer $image_dir$name-$chapterNumber.pdf & 101 | choose_next 102 | else 103 | 104 | echo "Converting to cbz..." 105 | zip -q $image_dir$name-$chapterNumber.cbz $image_dir*.jpg 106 | 107 | rm $image_dir/*.jpg 108 | clear 109 | $pdf_viewer $image_dir$name-$chapterNumber.cbz & 110 | choose_next 111 | fi 112 | } 113 | 114 | download_chapter() { 115 | clear 116 | echo -e "${Green}Getting data on the chapters...." 117 | i=11 118 | 119 | for each in "${chapterImages[@]}"; do 120 | curl \ 121 | --silent \ 122 | --create-dirs \ 123 | --header 'Referer: https://readmanganato.com/' \ 124 | --output "$image_dir$name-$i.jpg" \ 125 | "${each}" & 126 | 127 | ((i = i + 1)) 128 | done 129 | 130 | wait 131 | 132 | create_file 133 | 134 | } 135 | 136 | get_images() { 137 | link=$1 138 | chNumber=$2 139 | 140 | if [ -f "$image_dir$name-$chNumber.$file_format" ]; then 141 | clear 142 | echo -e "${Green}Manga file exists .cache, opening it..." 143 | $pdf_viewer $image_dir$name-$chapterNumber.$file_format & 144 | choose_next 145 | fi 146 | 147 | link="$mangaLink/chapter-$chNumber" 148 | 149 | link2=${mangaLink##*/} 150 | 151 | if [[ $mangaLink == *"read-"* ]]; then 152 | link="https://mangakakalot.com/chapter/$name/chapter_$chNumber" 153 | elif [[ ! $link2 == *"manga-"* ]]; then 154 | link="https://mangakakalot.com/chapter/$link2/chapter_$chNumber" 155 | fi 156 | 157 | mapfile -t chapterImages < <(curl -s "$link" | pup "div.container-chapter-reader img attr{src}") 158 | # curl -s "$mangaLink/chapter-$mangaNumber" | pup "div.container-chapter-reader img attr{src}" 159 | declare -p chapterImages >/dev/null 160 | 161 | if [ ! -d "$image_dir" ]; then 162 | mkdir ~/.cache/manga-cli 163 | fi 164 | } 165 | 166 | choose_next() { 167 | clear 168 | echo -e "${White}next chapter ${Green}(n)" 169 | echo -e "${White}quit ${Green}(q)" 170 | echo -e "${White}previous chapter ${Green}(p)" 171 | 172 | echo -n -e "${Yellow}Enter Option: " 173 | read -r option 174 | 175 | if [ "${option}" = "n" ]; then 176 | chapterNumber=$((chapterNumber + 1)) 177 | get_images "$mangaLink" "$chapterNumber" 178 | download_chapter 179 | 180 | elif [ "${option}" = "p" ]; then 181 | chapterNumber=$((chapterNumber - 1)) 182 | get_images "$mangaLink" "$chapterNumber" 183 | download_chapter 184 | 185 | elif [ "${option}" = "q" ]; then 186 | end_color 187 | exit 1 188 | 189 | else 190 | choose_next 191 | 192 | fi 193 | 194 | } 195 | 196 | # Flags 197 | while getopts "pcho:" option; do 198 | case $option in 199 | p) 200 | file_format="pdf" 201 | ;; 202 | c) 203 | rm -rf $image_dir 204 | echo "Cleared Cache" 205 | ;; 206 | h) 207 | help_text 208 | exit 1 209 | ;; 210 | o) 211 | pdf_viewer=$OPTARG 212 | ;; 213 | *) 214 | help_text 215 | exit 1 216 | ;; 217 | esac 218 | done 219 | 220 | main() { 221 | search_manga 222 | 223 | select_chapter 224 | 225 | download_chapter 226 | 227 | choose_next 228 | clear 229 | } 230 | 231 | main 232 | end_color 233 | --------------------------------------------------------------------------------