Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chyoarecode #45

Merged
merged 5 commits into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions Ebook-Publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,17 @@ def MakeEpub(site):
if type(site) is not Literotica.Literotica and type(site) is not Nhentai.Nhentai:
toc=[]
for i in range(len(site.rawstoryhtml)):
c.append(epub.EpubHtml(title=site.chapters[i], file_name='Chapter '+str(i+1)+'.xhtml', lang='en'))
if type(site) is Nhentai.Nhentai:
if type(site) is Chyoa.Chyoa and not site.backwards:
if i == 0:
c.append(epub.EpubHtml(title=site.chapters[i], file_name='Chapter '+str(i+1)+'.xhtml', lang='en'))
else:
c.append(epub.EpubHtml(title=site.chapters[i], file_name=str(site.depth[i-1])+'.xhtml', lang='en'))
c[i].content='<h2>\n'+site.chapters[i]+'\n</h2>\n'+str(site.rawstoryhtml[i])
elif type(site) is Nhentai.Nhentai:
c.append(epub.EpubHtml(title=site.chapters[i], file_name='Chapter '+str(i+1)+'.xhtml', lang='en'))
c[i].content=site.truestoryhttml[i]
else:
c.append(epub.EpubHtml(title=site.chapters[i], file_name='Chapter '+str(i+1)+'.xhtml', lang='en'))
c[i].content='<h2>\n'+site.chapters[i]+'\n</h2>\n'+str(site.rawstoryhtml[i])
book.add_item(c[i])
toc.append(c[i])
Expand Down
101 changes: 92 additions & 9 deletions Site/Chyoa.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,31 @@ def __init__(self, url):
self.images=[] #testing images
self.hasimages = False
self.duplicate = False
self.backwards = True
self.depth = []
try:
page=requests.get(self.url)
except:
print('Error accessing website: try checking internet connection and url')
soup=BeautifulSoup(page.content, 'html.parser')
self.title=soup.find('h3').get_text()
if self.title=='Log In':
try:
self.title=soup.find('h1').get_text()
self.backwards = False

except:
pass

if Common.dup:
if Common.CheckDuplicate(self.title):
self.duplicate = True
return None

self.authors.insert(0,soup.find_all('a')[7].get_text())
if self.backwards:
self.authors.insert(0,soup.find_all('a')[7].get_text())
else:
self.authors.insert(0,soup.find_all('a')[5].get_text())
self.chapters.insert(0, soup.find('h1').get_text())
self.summary=soup.find('p', attrs={'class': 'synopsis'}).get_text()

Expand Down Expand Up @@ -75,8 +87,8 @@ def __init__(self, url):
#if args.quiet:
Common.prnt(self.title+'\n'+str(self.authors)+'\n'+self.summary)
#print(self.chapters)

self.pbar=Common.Progress(self.length)
if self.backwards:
self.pbar=Common.Progress(self.length)


#for name in self.renames:
Expand All @@ -96,14 +108,35 @@ def __init__(self, url):
self.questions.insert(0, soup.find_all('h2')[1].get_text())
temp+='<h2>'+self.questions[0]+'</h2>'
self.temp.insert(0, temp)
self.pbar.Update()
if self.backwards:
self.pbar.Update()


#if soup.find('a').text.strip()==
self.backwards = False
for i in soup.find_all('a'):
if i.text.strip()=='Previous Chapter':
self.AddNextPage(i.get('href'))
self.AddPrevPage(i.get('href'))
self.backwards = True
break
self.pbar.End()

#Gets here if it's the intro page that is used
if not self.backwards:
j = 1
self.temp[0]+='\n<br />'
for i in soup.find('div', attrs={'class':'question-content'}).find_all('a'):
if i.get_text().strip() != 'Add a new chapter':
if Common.opf == 'epub':
self.temp[0]+='\n<a href="'+str(j)+'.xhtml">'+i.get_text().strip()+'</a>\n<br />\n'
else:
self.temp[0]+='\n<a href="#'+str(j)+'">'+i.get_text().strip()+'</a>\n<br />\n'
self.AddNextPage(i.get('href'), j)
j+=1



if self.backwards:
self.pbar.End()

#band-aid fix for names in chapter titles
#WARNING DO NOT PUT THIS TO PRODUCTION
Expand Down Expand Up @@ -142,13 +175,14 @@ def __init__(self, url):

for i in range(0,len(self.truestoryhttml)):
self.rawstoryhtml[i]=BeautifulSoup(self.truestoryhttml[i], 'html.parser')


if Common.images and self.hasimages and Common.opf=='html':
for i in range(0,len(self.images)):
Common.imageDL(self.title, self.images[i], i+1, size=len(self.images))


def AddNextPage(self, url):
def AddPrevPage(self, url):
try:
page=requests.get(url)
except:
Expand All @@ -163,7 +197,6 @@ def AddNextPage(self, url):
self.images.append(simg.get('src'))
simg['src']='img'+str(len(self.images))+'.jpg'
self.hasimages = True

temp=str(soup.find('div', attrs={'class': 'chapter-content'}))
self.questions.insert(0, soup.find_all('h2')[1].get_text())
temp+='<h2>'+self.questions[0]+'</h2>'
Expand All @@ -173,8 +206,58 @@ def AddNextPage(self, url):
self.pbar.Update()
for i in soup.find_all('a'):
if i.text.strip()=='Previous Chapter':
self.AddNextPage(i.get('href'))
self.AddPrevPage(i.get('href'))
return
#gets author name if on last/first page I guess
self.authors[0]=soup.find_all('a')[5].get_text()
#print(self.authors)


def AddNextPage(self, url, depth):
try:
page=requests.get(url)
except:
print('Error accessing website: try checking internet connection and url')
soup=BeautifulSoup(page.content, 'html.parser')
self.authors.append(soup.find_all('a')[7].get_text())
self.chapters.append(soup.find('h1').get_text())

if Common.images:
if soup.find('div', attrs={'class': 'chapter-content'}).find('img'):
for simg in soup.find('div', attrs={'class': 'chapter-content'}).find_all('img'):
self.images.append(simg.get('src'))
simg['src']='img'+str(len(self.images))+'.jpg'
self.hasimages = True

temp2 = soup.find('div', attrs={'class': 'chapter-content'})
self.depth.append(str(depth))
temp='<div id="'+str(depth)+'">'+str(temp2)
self.questions.append(soup.find_all('h2')[1].get_text())
temp+='<h2>'+self.questions[-1]+'</h2>\n</div>'
Common.prnt(str(depth))
j = 1

nextpages=[]
nextpagesurl=[]
nextpagesdepth=[]
temp+='<br />'
for i in soup.find('div', attrs={'class':'question-content'}).find_all('a'):
if i.get_text().strip() != 'Add a new chapter':
if Common.opf == 'epub':
nextpages.append('\n<a href="'+str(depth)+'.'+str(j)+'.xhtml">'+i.get_text().strip()+'</a>\n<br />')
else:
nextpages.append('\n<a href="#'+str(depth)+'.'+str(j)+'">'+i.get_text().strip()+'</a>\n<br />')
nextpagesurl.append(i)
nextpagesdepth.append(j)
j+=1

for j in nextpages:
temp+=j
self.temp.append(temp)
for i,j in zip(nextpagesurl, nextpagesdepth):
self.AddNextPage(i.get('href'), str(depth)+'.'+str(j))


#gets author name if on last/first page I guess
#self.authors[0]=soup.find_all('a')[5].get_text()
#print(self.authors)