Skip to content
This repository has been archived by the owner on Feb 7, 2022. It is now read-only.

Commit

Permalink
EPUB style modification and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
LordKBX committed Sep 27, 2020
1 parent 7c36e58 commit 6c2f270
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 26 deletions.
26 changes: 15 additions & 11 deletions getify.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from bs4 import BeautifulSoup
import uuid
import html
import traceback

def find_between(file):
f = open(file, "r", encoding = "utf8")
Expand Down Expand Up @@ -49,14 +50,15 @@ def clean(file_name_in, file_name_out, start):
imgext = tb[len(tb) - 1]
imgname = file_name_out + '_im{}'.format(cpt)+'.'+imgext
tb = imgname.split('/')
imgname2 = tb[len(tb) - 1]
imgname2 = imgname.replace(tb[len(tb) - 1], 'images/'+tb[len(tb) - 1])
print(img['src'])
try:
download(img['src'], imgname)
img['src'] = 'images/'+imgname2
suplementList.append(imgname2)

download(img['src'], imgname2)
img['src'] = 'images/'+tb[len(tb) - 1]
suplementList.append('images/'+tb[len(tb) - 1])
except:
{}
traceback.print_exc()
cpt += 1
soup = block
break
Expand All @@ -71,8 +73,10 @@ def clean(file_name_in, file_name_out, start):
file.write("\n"+'<link href="common.css" rel="stylesheet" type="text/css"/>')
file.write("\n</head>")
file.write("\n<body>")
file.write("\n<section>")
file.write("\n<h1>" + chapter_title + "</h1>")
file.write(str(soup).replace('<p></p>', '').replace('<p><br></p>', '').replace('<hr>', ''))
file.write("\n</section>")
file.write("\n</body>")
file.write("\n</html>")
os.remove(file_name_in)
Expand Down Expand Up @@ -249,7 +253,7 @@ def generate(html_files, novelname, author, chaptername, book, chapter_s, chapte
try: os.remove(storage_dir + os.sep + "tmp/cover.png")
except: {}

file2 = open("./ressources/common.css", "r")
file2 = open(storage_dir + os.sep + "ressources/common.css", "r")
file3 = open(storage_dir + os.sep + "tmp/common.css", "w")
ccss = file2.read()
file2.close()
Expand All @@ -259,13 +263,13 @@ def generate(html_files, novelname, author, chaptername, book, chapter_s, chapte

epub.write(storage_dir + os.sep + "tmp/common.css", "OEBPS/common.css")
for img in suplementList:
epub.write(storage_dir + os.sep + "tmp/"+img, "OEBPS/images/"+img)
epub.write(storage_dir + os.sep + "tmp/"+img, "OEBPS/"+img)
try: os.remove(storage_dir + os.sep + "tmp/common.css")
except: {}
epub.write("./ressources/fonts/"+font+"/Regular.ttf", "OEBPS/Regular.ttf")
epub.write("./ressources/fonts/"+font+"/Bold.ttf", "OEBPS/Bold.ttf")
epub.write("./ressources/fonts/"+font+"/Bold-Italic.ttf", "OEBPS/Bold-Italic.ttf")
epub.write("./ressources/fonts/"+font+"/Italic.ttf", "OEBPS/Italic.ttf")
epub.write(storage_dir + os.sep + "ressources/fonts/"+font+"/Regular.ttf", "OEBPS/Regular.ttf")
epub.write(storage_dir + os.sep + "ressources/fonts/"+font+"/Bold.ttf", "OEBPS/Bold.ttf")
epub.write(storage_dir + os.sep + "ressources/fonts/"+font+"/Bold-Italic.ttf", "OEBPS/Bold-Italic.ttf")
epub.write(storage_dir + os.sep + "ressources/fonts/"+font+"/Italic.ttf", "OEBPS/Italic.ttf")

epub.close()
# removes all the temporary files
Expand Down
4 changes: 1 addition & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,4 @@ six>=1.15.0
beautifulsoup4>=4.6.0
lxml>=4.1.1
PyQt5>=5.15.1
PyQtWebKit>=5.13.1
pywin32>=228
Pillow>=7.2.0
PyQtWebKit>=5.13.1
13 changes: 10 additions & 3 deletions ressources/common.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ img{max-width:100%;height:auto;display:block;margin:0 auto;}
.credits{position:fixed;bottom:10px;left:10px;}

/*Content Page List only*/
ol{background:#FFB656;padding-top:15px;padding-bottom:15px;}
ol li{padding:5px;width:calc(100% - 20px);color:#000000;}
ol li a{color:#000000;}
ol{
background:#57A02C;
padding-top:15px;
padding-bottom:15px;
border:#CCCCCC 1px solid;
border-radius:15px;
}
ol *{ background:#57A02C; color:#000000 !important; }
ol li{padding:5px;width:calc(100% - 20px);}
ol li a{}

p{font-weight:100;font-style:normal;}
p i{font-weight:100;font-style:italic;}
Expand Down
5 changes: 3 additions & 2 deletions ressources/themes/cream.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@font-face { font-family: "<FONT>"; src: url(Bold.ttf); font-weight: bold; }

*{font-family:"<FONT>", sans-serif;background:#FFE0AA;color:#666666;}
body, html{height:100%;background:#FFE0AA;}
h1{text-align:center;}
h2{text-align:center;}
h3{text-align:center;}
Expand All @@ -21,8 +22,8 @@ img{max-width:100%;height:auto;display:block;margin:0 auto;}
.credits{position:fixed;bottom:10px;left:10px;}

/*Content Page List only*/
ol{background:#77A4FF;padding-top:15px;padding-bottom:15px;}
ol *{background:#77A4FF;color:#ffffff;}
ol{background:#D1AF6C;padding-top:15px;padding-bottom:15px; border:#BC852D 1px solid; border-radius:10px; }
ol *{background:#D1AF6C;color:#ffffff !important;}
ol li{padding:5px;width:calc(100% - 20px);}
ol li a{}

Expand Down
3 changes: 2 additions & 1 deletion ressources/themes/dark.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@font-face { font-family: "<FONT>"; src: url(Bold.ttf); font-weight: bold; }

*{font-family:"<FONT>", sans-serif;background:#444444;color:#ffffff;}
body, html{height:100%;background:#444444;}
h1{text-align:center;}
h2{text-align:center;}
h3{text-align:center;}
Expand All @@ -22,7 +23,7 @@ img{max-width:100%;height:auto;display:block;margin:0 auto;}

/*Content Page List only*/
ol{background:#7F3300;padding-top:15px;padding-bottom:15px;}
ol *{background:#7F3300;color:#ffffff;}
ol *{background:#7F3300;color:#ffffff !important;}
ol li{padding:5px;width:calc(100% - 20px);}
ol li a{}

Expand Down
11 changes: 9 additions & 2 deletions ressources/themes/dark2.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@font-face { font-family: "<FONT>"; src: url(Bold.ttf); font-weight: bold; }

*{font-family:"<FONT>", sans-serif;background:#444444;color:#ffffff;}
body, html{background:#444444;height:100%;}
h1{text-align:center;}
h2{text-align:center;}
h3{text-align:center;}
Expand All @@ -21,8 +22,14 @@ img{max-width:100%;height:auto;display:block;margin:0 auto;}
.credits{position:fixed;bottom:10px;left:10px;}

/*Content Page List only*/
ol{background:#57A02C;padding-top:15px;padding-bottom:15px;}
ol *{background:#57A02C;color:#ffffff;}
ol{
background:#57A02C;
padding-top:15px;
padding-bottom:15px;
border:#CCCCCC 1px solid;
border-radius:15px;
}
ol *{ background:#57A02C; color:#FFFFFF !important; }
ol li{padding:5px;width:calc(100% - 20px);}
ol li a{}

Expand Down
14 changes: 11 additions & 3 deletions ressources/themes/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@font-face { font-family: "<FONT>"; src: url(Bold.ttf); font-weight: bold; }

*{font-family:"<FONT>", sans-serif;}
body, html{height:100%;}
h1{text-align:center;}
h2{text-align:center;}
h3{text-align:center;}
Expand All @@ -21,9 +22,16 @@ img{max-width:100%;height:auto;display:block;margin:0 auto;}
.credits{position:fixed;bottom:10px;left:10px;}

/*Content Page List only*/
ol{background:#FFB656;padding-top:15px;padding-bottom:15px;}
ol li{padding:5px;width:calc(100% - 20px);color:#000000;}
ol li a{color:#000000;}
ol{
background:#57A02C;
padding-top:15px;
padding-bottom:15px;
border:#CCCCCC 1px solid;
border-radius:15px;
}
ol *{ background:#57A02C; color:#000000 !important; }
ol li{padding:5px;width:calc(100% - 20px);}
ol li a{}

p{font-weight:100;font-style:normal;}
p i{font-weight:100;font-style:italic;}
Expand Down
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
27/09/2020
10:35:38,26
18:52:05,66
4 changes: 4 additions & 0 deletions wuxiaworld_export_ebook.pyw
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,8 @@ def preview():
if novel == '':
infoDialog('Information', "Function availlable only if a novel was selected")
return
if os.path.isdir(storage_dir + os.sep + "tmp" + os.sep + "images") is False:
os.mkdir(storage_dir + os.sep + "tmp" + os.sep + "images")
app.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
book = dialog.bookSelector.currentText()
if book not in data_novel['books']: book = 'Book 01'
Expand Down Expand Up @@ -392,6 +394,8 @@ def generate():
if novel == '': return
lockInterface(True)
app.setOverrideCursor(QtGui.QCursor(QtCore.Qt.WaitCursor))
if os.path.isdir(storage_dir + os.sep + "tmp" + os.sep + "images") is False:
os.mkdir(storage_dir + os.sep + "tmp" + os.sep + "images")
status = "Start ebook generation at {}".format( novel, time.asctime() )
updateStatus(status)
print(status)
Expand Down

0 comments on commit 6c2f270

Please sign in to comment.