-
Notifications
You must be signed in to change notification settings - Fork 11
/
anymangaget
executable file
·119 lines (94 loc) · 2.67 KB
/
anymangaget
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/bin/sh
# Copyright (c) 2011, Alexander Batischev
# All rights reserved.
clBold="`echo '\033[1m'`"
clReset="`echo '\033[m'`"
fetchChapter() {
title="$1"
volume="$2"
chapter="$3"
page="`curl -s \"http://anymanga.com/$title/$volume/$chapter\"`"
pageNames="`echo \"$page\" | grep pagelist | head -1 | sed 's#show_pagelist(\[##; s#\],.*$##' | tr -d "' "`"
pages="`curl -s \"http://anymanga.com/$title/$volume/$chapter/{${pageNames}}\"`"
if [ -n "$pages" ]
then
mkdir -p "$chapter"
cd "$chapter"
echo "$pages" | grep img | grep "$title" | sed -r 's#<img src="(.*)" title.*#\1#; s#^#http://anymanga.com#' | wget -ci-
cd ..
fi
}
fetchVolume() {
title="$1"
volume="$2"
page="`curl -s \"http://anymanga.com/$title/\"`"
chapters="`echo \"$page\" | grep \"/$title/$volume\" | grep '<li>' |
sed -r 's#.*a href="(.*)" >.*#\1#; s#/[^/]+/[^/]+/([^/]+)/#\1#'`"
if [ -n "$chapters" ]
then
mkdir -p "$volume"
cd "$volume"
for chapter in $chapters
do
fetchChapter "$title" "$volume" "$chapter"
done
cd ..
fi
}
fetchTitle() {
title="$1"
page="`curl -s \"http://anymanga.com/$title/\"`"
volumesAndChapters="`echo \"$page\" | grep \"/$title\" | grep '<li>' | sed -r 's#.*a href="(.*)" >.*#\1#; s#/[^/]+/(.*)/#\1#'`"
if [ -n "$volumesAndChapters" ]
then
mkdir -p "$title"
cd "$title"
for i in $volumesAndChapters
do
volume="`dirname $(echo \"$i\")`"
chapter="`basename $(echo \"$i\")`"
mkdir -p "$volume"
cd "$volume"
fetchChapter "$title" "$volume" "$chapter"
cd ..
done
cd ..
fi
}
if [ -z "$1" -o "$1" = "-h" ]
then
echo "Usage: $0 ${clBold}title${clReset} [${clBold}volume${clReset} [${clBold}chapter${clReset}]]"
echo " $0 ${clBold}URL${clReset}"
exit
fi
if [ -z "`echo \"$1\" | grep 'anymanga\.com'`" ]
then
title="$1"
volume="$2"
chapter="$3"
else
# we were given a URL; now let's parse it
url="`echo \"$1\" | sed 's#^http://##'`"
title="`echo \"$url\" | sed -r 's#[^/]+/([^/]+).*#\1#'`"
volume="`echo \"$url\" | sed -r 's#[^/]+/[^/]+/([^/]+).*#\1#'`"
if [ "$volume" = "$url" ]
then
volume=""
fi
chapter="`echo \"$url\" | sed -r 's#[^/]+/[^/]+/[^/]+/([^/]+).*#\1#'`"
if [ "$chapter" = "$url" ]
then
chapter=""
fi
fi
if [ -n "$chapter" ]
then
fetchChapter "$title" "$volume" "$chapter"
else
if [ -n "$volume" ]
then
fetchVolume "$title" "$volume"
else
fetchTitle "$title"
fi
fi