Skip to content

Commit

Permalink
Merge pull request #49 from theslavicbear/css
Browse files Browse the repository at this point in the history
Css
  • Loading branch information
theslavicbear authored Feb 9, 2020
2 parents c8ad937 + bf0e82c commit dba66af
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
11 changes: 10 additions & 1 deletion Ebook-Publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def MakeHTML(site):
published=open(wd+site.title+'.html', 'w')
published.write('<!DOCTYPE html>\n')
published.write('<html lang="en">\n')
published.write('<style>\n'+styleSheet+'\n</style>')
published.write('<head>\n<title>'+site.title+' by '+site.author+'</title>\n</head>\n')
published.write('<h1>'+site.title+'</h1><h3>by '+site.author+'</h3><br /><a href='+site.url+'>'+site.url+'</a>\n')
if type(site) not in (Nhentai.Nhentai, Literotica.Literotica):
Expand Down Expand Up @@ -106,6 +107,7 @@ def MakeEpub(site):
book.set_title(site.title)
book.set_language('en')
book.add_author(site.author)
book.add_style_sheet(styleSheet)
c=[]

if type(site) is not Literotica.Literotica and type(site) is not Nhentai.Nhentai:
Expand Down Expand Up @@ -195,6 +197,12 @@ def ListURLs(url):
return fi.read().splitlines()
else:
return (url,)
def getCSS():
if os.path.isfile(os.path.join(cwd,args.css)):
with open(cwd+'/'+args.css, 'r') as fi:
return fi.read()
else:
return args.css


#setting up commandline argument parser
Expand All @@ -207,6 +215,7 @@ def ListURLs(url):
parser.add_argument('-t', help="Turns on multithreading mode. Recommend also enabling --quiet", action='store_true')
parser.add_argument('-i', '--insert-images', help="Downloads and inserts images for Chyoa stories", action='store_true')
parser.add_argument('-n', '--no-duplicates', help='Skips stories if they have already been downloaded', action='store_true')
parser.add_argument('-s', '--css', '--style-sheet', help='either a CSS string or a .css file to use for formatting', default='')
args=parser.parse_args()

#print(args.output_type)
Expand Down Expand Up @@ -249,7 +258,7 @@ def ListURLs(url):
os.makedirs(wd)



styleSheet=getCSS()

ftype=args.output_type
if ftype == None:
Expand Down
13 changes: 9 additions & 4 deletions EpubMaker/epub.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ def __init__(self):
#self.authors = []
self.toc = []
self.author = ''
#self.hasStyle=False
self.styleString = ''

def set_identifier(self, identifier):
self.identifier=identifier
Expand All @@ -32,6 +34,8 @@ def set_language(self, lang):
def add_author(self, author):
self.author = author

def add_style_sheet(self, styleString):
self.styleString=styleString


class EpubHtml:
Expand Down Expand Up @@ -65,7 +69,7 @@ def write_epub(title, book):
i = 0
for item in book.item_list:
if type(item) is not EpubNav and type(item) is not EpubNcx:
Zip.writestr('EPUB/'+item.file_name,'<?xml version="1.0" encoding="utf-8"?>\n <!DOCTYPE html>\n <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" epub:prefix="z3998: http://www.daisy.org/z3998/2012/vocab/structure/#" lang="'+item.lang+'" xml:lang="'+item.lang+'">\n <head>\n <title>'+item.title+'</title>\n </head>\n <body>'+item.content+'</body>\n </html>''')
Zip.writestr('EPUB/'+item.file_name,'<?xml version="1.0" encoding="utf-8"?>\n <!DOCTYPE html>\n <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" epub:prefix="z3998: http://www.daisy.org/z3998/2012/vocab/structure/#" lang="'+item.lang+'" xml:lang="'+item.lang+'">\n <head>\n <title>'+item.title+'</title>\n <link rel="stylesheet" type="text/css" href="style.css" />\n </head>\n <body>'+item.content+'</body>\n </html>''')
opf_content +='<item href="'+item.file_name+'" id="chapter_'+str(i)+'" media-type="application/xhtml+xml"/>\n'
i += 1
elif type(item) is EpubNcx:
Expand All @@ -82,9 +86,9 @@ def write_epub(title, book):
elif type(item) is EpubNav:
opf_content += '<item href="nav.xhtml" id="nav" media-type="application/xhtml+xml" properties="nav"/>\n'
if not isTOC:
Zip.writestr('EPUB/nav.xhtml', '<?xml version="1.0" encoding="utf-8"?>\n <!DOCTYPE html>\n <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="en" xml:lang="en">\n <head>\n <title>'+book.title+'</title>\n </head>\n <body>\n <nav id="id" role="doc-toc" epub:type="toc">\n <h2>'+book.title+'</h2>\n <ol/>\n </nav>\n </body>\n </html>\n ')
Zip.writestr('EPUB/nav.xhtml', '<?xml version="1.0" encoding="utf-8"?>\n <!DOCTYPE html>\n <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="en" xml:lang="en">\n <head>\n <title>'+book.title+'</title>\n <link rel="stylesheet" type="text/css" href="style.css" />\n </head>\n <body>\n <nav id="id" role="doc-toc" epub:type="toc">\n <h2>'+book.title+'</h2>\n <ol/>\n </nav>\n </body>\n </html>\n ')
elif isTOC:
navstring = '<?xml version="1.0" encoding="utf-8"?>\n <!DOCTYPE html>\n <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="en" xml:lang="en">\n <head>\n <title>'+book.title+'</title>\n </head>\n <body>\n <nav id="id" role="doc-toc" epub:type="toc">\n <h2>'+book.title+'</h2>\n <ol>\n'
navstring = '<?xml version="1.0" encoding="utf-8"?>\n <!DOCTYPE html>\n <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops" lang="en" xml:lang="en">\n <head>\n <title>'+book.title+'</title>\n <link rel="stylesheet" type="text/css" href="style.css" />\n </head>\n <body>\n <nav id="id" role="doc-toc" epub:type="toc">\n <h2>'+book.title+'</h2>\n <ol>\n'
for item in book.toc:
navstring += '<li>\n<a href="'+item.file_name+'">'+item.title+'</a>\n</li>\n'
navstring += '</ol>\n</nav>\n</body>\n</html>'
Expand All @@ -99,7 +103,8 @@ def write_epub(title, book):
opf_content += '<itemref idref="chapter_'+str(i)+'"/>\n'
i+=1
opf_content += '</spine>\n</package>'
Zip.writestr('EPUB/style.css', book.styleString)
Zip.writestr('EPUB/content.opf', opf_content)

if __name__ == '__main__':
pass
print('You have mistakenly run this file, epub.py. It is not meant to be run. It must be impported by another python file (or an implementation can be added to this __main__ section).')

0 comments on commit dba66af

Please sign in to comment.