This repository has been archived by the owner on Jun 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chapterDownloader.py
97 lines (83 loc) · 2.4 KB
/
chapterDownloader.py
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
import os
from PIL import Image
import sys
import requests as req
from bs4 import BeautifulSoup
import PIL.Image
from StringIO import StringIO
import urlparse
from Tkinter import *
from ttk import *
import threading
#global
arguments = sys.argv
maxPageNo = 0
imagePageLinks = []
imageLinks = []
baseUrl = 'http://www.mangareader.net'
def chapterInfo(chapterLink, mangaName, chapterNumber, progressBar):
global imagePageLinks
global baseUrl
global maxPageNo
html = req.get(chapterLink)
soup = BeautifulSoup(html.text)
select = soup.find(id="pageMenu")
options = select.find_all('option')
for option in options:
imagePageLinks.append(urlparse.urljoin(baseUrl,option.get('value').encode('utf-8')))
maxPageNo = len(imagePageLinks)
start()
imagesDownloadLinks(progressBar,mangaName, chapterNumber)
def imagesDownloadLinks(progressBar, mangaName, chapterNumber):
global imagePageLinks
global maxPageNo
global done
progIncrease = (500/maxPageNo)
path = os.path.dirname(os.path.abspath(__file__))+'/temp/Downloads/'+mangaName+'/'+chapterNumber+'/'
for idx,link in enumerate(imagePageLinks):
html = req.get(link)
soup = BeautifulSoup(html.text)
imageDiv = soup.find(id="imgholder")
imageLink = imageDiv.find_all('img')[0]
imageLink = imageLink.get('src')
imageLinks.append(imageLink)
progressBar["value"]+= progIncrease
done.set(str((progressBar["value"]*100)/500)+" %")
try:
imagePage = req.get(imageLink)
image = PIL.Image.open(StringIO(imagePage.content))
except req.exceptions.RequestException as e:
print e
if not os.path.exists(path):
os.makedirs(path)
try:
image.save(path+str(idx)+'.gif',"GIF")
except Exception as e:
print "Error "+str(e)
global root
root.destroy()
quit()
def start():
global progressBar
progressBar["value"] = 0
if len(arguments) == 3:
chapterLink = arguments[1]
mangaName = arguments[2]
chapterNumber = chapterLink.split('/')[-1]
root = Tk()
root.title(mangaName+" "+chapterNumber)
done = StringVar()
done.set("0 %")
howMuchDone = Label(root, textvariable=done,background="white")
howMuchDone.pack(side=TOP)
progressBar = Progressbar(root,orient="horizontal",mode="determinate",length=500,maximum=500)
progressBar.pack()
t = threading.Thread(target=chapterInfo,args = (chapterLink, mangaName, chapterNumber, progressBar))
t.daemon = True
t.start()
root.lift()
root.mainloop()
quit()
else:
print arguments
quit()