-
Notifications
You must be signed in to change notification settings - Fork 0
/
manganato.sh
executable file
·93 lines (67 loc) · 3.1 KB
/
manganato.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#! /bin/bash
# Note - Comments starting from # are normal comments
# and which starts with ## are commands just used for
# debugging purposes
# Taking input from user
TITLE=$1
# Removing spaces and joining all the words present in input ex. tokyo ghoul -> tokyo_ghoul
TITLE=${TITLE// /_}
# Presenting a list of mangas similar to the query given
curl -s https://manganato.com/search/story/$TITLE | grep item-title | grep -no '>.*<' | tr -d ">|<"
# Extracting the unique urls associated with each manga title and storing in an array
URLS=($(curl -s https://manganato.com/search/story/$TITLE | grep item-title | grep -Eo "https://(readmanganato|manganato).com/manga-[a-z]{2}[0-9]{6}"))
# List of modified title (ex. Kaiju No. 8 -> Kaiju_No._8 )to help in creating the folder
LIST=($(curl -s https://manganato.com/search/story/${TITLE} | grep item-title | grep -o 'title=".*"' | grep -o '\".*\"' | tr '\ :' '_' | tr '"' ' ' ))
# Selecting the index of the manga user wants to read
printf "SELECT FROM ABOVE : "
# This it the index value we are reading from user and will use in our URL array
read CHOICE
clear
# Extracting chapter list
CHAPTER_LIST=$(curl -s ${URLS[(CHOICE-1)]} | grep chapter-name | grep -Po "chapter-([0-9]{1,4}+\.[0-9]|[0-9]{1,4})" )
# Extracting the starting index from where manga starts
START=$(echo $CHAPTER_LIST | grep -Eo "chapter-([0-9]{1,4}+\.[0-9]|[0-9]{1,4})"| tail -3)
# Extracting the last index
LAST=$(echo $CHAPTER_LIST | grep -Eo "chapter-([0-9]{1,4}+\.[0-9]|[0-9]{1,4})"| head -2)
# Taking input of chapter number
printf "ENTER CHAPTER NO. OR ENTER 'all' to download all chapters \n$LAST \n.\n.\n.\n$START\n:"
read CHAPTER_CHOICE
# Fetching the pages url corresponding to the chapter
download_chpater(){
PAGES=($(curl -s https://readmanganato.com/${URLS[(CHOICE-1)]}/chapter-$1 | grep -Eo '(http|https)://[^"]+' | grep chapter_))
# Making Folder where we will store our downloaded manga
mkdir -p ${LIST[(CHOICE-1)]}/$1
# counter varibale to track the number of each page
COUNTER=1
# for loop to download the pages
for PAGE in ${PAGES[@]}
do
## echo $PAGE
printf "Downloading Chapter - $1 Pages -> $COUNTER/${#PAGES[@]}\r"
curl -s --output "${LIST[(CHOICE-1)]}/$1/page_$((COUNTER++)).jpg" $PAGE -H 'Referer: https://readmanganato.com/'
done
printf "Downloading Chapter - $1 Finished \n"
if [[ $2 == '-p' ]]
then
# printf 'pdf compiled\n'
img2pdf --output "${LIST[(CHOICE-1)]}/$1.pdf" $(ls -v ${LIST[(CHOICE-1)]}/$1/*)
fi
}
clear
if [[ $CHAPTER_CHOICE == "all" ]]
then
printf "Downloading all chapters please wait \n"
for CHAPTER in $(echo $CHAPTER_LIST | grep -Eo "([0-9]{1,4}+\.[0-9]|[0-9]{1,4})" | sort -g)
do
# printf "Downloading Chapter - $CHAPTER\n"
download_chpater $CHAPTER $2
done
else
for CHAPTER in $CHAPTER_CHOICE
do download_chpater $CHAPTER $2
done
# download_chpater $CHAPTER_CHOICE
fi
# Combining the pages into a pdf (requires "img2pdf" package)
notify-send "Manga Download Finished"
## echo "https://manganato.com/search/story/${TITLE// /_}"