PageRenderTime 34ms CodeModel.GetById 16ms app.highlight 12ms RepoModel.GetById 1ms app.codeStats 0ms

/onemanga.sh

http://gsbabil.googlecode.com/
Shell | 75 lines | 49 code | 16 blank | 10 comment | 5 complexity | 8f64b31ee86d582c384ea543428cb0a6 MD5 | raw file
 1#!/bin/bash 
 2
 3RED='\e[0;31m'
 4CYAN='\e[0;36m'
 5NC='\e[0m' # No Color
 6
 7if [ -z $1 ]
 8then
 9	echo
10	echo "[*] usage: `basename $0` manga_url"
11	echo
12	exit
13else
14	manga_name=`echo $1 | awk -F '/' '{for(i=NF;i>=0;i--){if(length($i)>0){print $i;break;}}}'`
15fi
16
17main_url="http://www.onemanga.com"
18
19rm -rf ${manga_name}
20
21##finding list of chapters
22echo -n -e "${CYAN}[*]${RED} Finding total chapters in ${CYAN} $manga_name ${NC}= "
23wget -q -nv ${main_url}/${manga_name} -O tmp.txt
24chapters=`cat tmp.txt | grep '<td class="ch-subject"><a href="/' | awk -F '"' '{print $4}'`
25
26
27count=0
28for c in $chapters
29do
30	mkdir -p ./$c
31	count=$((count+1))
32done
33echo -e "${CYAN}${count}${NC}"
34##
35
36##parse chapter and download
37for chapter in $chapters
38do
39	pwd=`pwd`
40
41	cd ./$chapter
42
43	## initial wget
44	echo -e "${CYAN}[*]${RED} Trying to find the image base url${NC}"
45	
46	## find collect the first page in the chapter
47	wget -q -nv $main_url/$chapter -O tmp.txt
48	page=`cat tmp.txt | grep "Begin reading" | awk -F '"' '{print $2}'`
49	
50	## now go to that page & find image base
51	wget -q -nv ${main_url}${page} -O tmp.txt 2>/dev/null
52	image=`cat tmp.txt | grep "img_url" | awk -F '"' '{for(i=1;i<NF;i++){if($i ~ "jpg"){print $i}}}' | awk -F '/' '{print $NF}'`
53	image_base=`cat tmp.txt | grep "img_url" | awk -F '"' '{for(i=1;i<NF;i++){if($i ~ "jpg"){print $i}}}' | sed s/"$image"//g`
54	echo -e "${RED}>>${NC} $image_base"
55
56	## download
57	d=$((d+1))
58	names=`cat tmp.txt | awk '{for(i=1;i<=NF;i++){if($i ~ "selected")go++}{if(go>1){print}}}' | grep -e "</option>" -e 'credits</option>' -e 'extra*</option>' -e 'cover*</option>' | awk -F '"' '{print $2}'`
59
60	n=0
61	for k in $names
62	do
63		n=$((n+1))
64	done
65	
66	echo -e "${CYAN}[*]${RED} Downloading ${CYAN}$n ${RED}images from chapter ${CYAN}$chapter ${RED} ... ##${CYAN}$((count-d+1))${RED}##${CYAN}$count${RED}##${NC}"
67	for k in $names
68	do
69		#echo -e "${RED}>>${NC} ${image_base}${k}.jpg"
70		wget -nv "${image_base}${k}.jpg"
71	done
72
73	cd $pwd
74done
75##