mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2025-12-06 08:52:55 +01:00
Allow one-shot fics for ffnet.
Write epub files as mode 'b' binary so it works on Windows. Allow hr tags in epub output. Don't compress file mimetype in epub file--required by standard.
This commit is contained in:
parent
2b2e7d52ec
commit
b22d961e73
4 changed files with 23 additions and 10 deletions
0
books/place holder.txt
Normal file
0
books/place holder.txt
Normal file
6
ffnet.py
6
ffnet.py
|
|
@ -40,7 +40,7 @@ class FFNet(FanfictionSiteAdapter):
|
|||
self.path = parsedUrl.path
|
||||
|
||||
self.storyName = 'FF.Net story'
|
||||
self.storyName = 'FF.Net author'
|
||||
self.authorName = 'FF.Net author'
|
||||
|
||||
spl = self.path.split('/')
|
||||
if len(spl) == 5:
|
||||
|
|
@ -108,7 +108,9 @@ class FFNet(FanfictionSiteAdapter):
|
|||
title = o.string
|
||||
logging.debug('URL = `%s`, Title = `%s`' % (url, title))
|
||||
urls.append((url,title))
|
||||
|
||||
if len(urls) == 0:
|
||||
# no chapters found, try url by itself.
|
||||
urls.append((self.url,self.storyName))
|
||||
return urls
|
||||
|
||||
def getText(self, url):
|
||||
|
|
|
|||
10
output.py
10
output.py
|
|
@ -109,7 +109,7 @@ class EPubFanficWriter(FanficWriter):
|
|||
files = {}
|
||||
|
||||
def _writeFile(self, fileName, data):
|
||||
logging.debug('_writeFile(`%s`, data)' % fileName)
|
||||
#logging.debug('_writeFile(`%s`, data)' % fileName)
|
||||
if fileName in self.files:
|
||||
try:
|
||||
d = data.decode('utf-8')
|
||||
|
|
@ -189,7 +189,9 @@ class EPubFanficWriter(FanficWriter):
|
|||
|
||||
text = self._removeEntities(text)
|
||||
|
||||
self.soup = bs.BeautifulStoneSoup(text.decode('utf-8'))
|
||||
# BeautifulStoneSoup doesn't have any selfClosingTags by default.
|
||||
# hr needs to be if it's going to work.
|
||||
self.soup = bs.BeautifulStoneSoup(text.decode('utf-8'), selfClosingTags=('hr'))
|
||||
|
||||
allTags = self.soup.findAll(recursive=True)
|
||||
for t in allTags:
|
||||
|
|
@ -202,7 +204,7 @@ class EPubFanficWriter(FanficWriter):
|
|||
if p.string != None and (len(p.string.strip()) == 0 or p.string.strip() == ' ' ) :
|
||||
p.extract()
|
||||
|
||||
allBrs = self.soup.findAll(recursive=True, name = ["br", "hr", 'div'])
|
||||
allBrs = self.soup.findAll(recursive=True, name = ["br", 'div'])
|
||||
for br in allBrs:
|
||||
if (br.string != None and len(br.string.strip()) != 0) or (br.contents != None):
|
||||
br.name = 'p'
|
||||
|
|
@ -270,7 +272,7 @@ class EPubFanficWriter(FanficWriter):
|
|||
zipdata = zipdir.inMemoryZip(self.files)
|
||||
|
||||
if self.writeToFile:
|
||||
f = open(filename, 'w')
|
||||
f = open(filename, 'wb')
|
||||
f.write(zipdata.getvalue())
|
||||
f.close()
|
||||
else:
|
||||
|
|
|
|||
13
zipdir.py
13
zipdir.py
|
|
@ -17,6 +17,10 @@ def toZip(filename, directory):
|
|||
|
||||
if os.path.isfile(each):
|
||||
print(each)
|
||||
# epub standard requires mimetype to be uncompressed and first file.
|
||||
if entity == 'mimetype':
|
||||
zippedHelp.write(each, arcname=entity, compress_type=zipfile.ZIP_STORED)
|
||||
else:
|
||||
zippedHelp.write(each, arcname=entity)
|
||||
else:
|
||||
addFolderToZip(zippedHelp,entity, each)
|
||||
|
|
@ -51,10 +55,15 @@ def inMemoryZip(files):
|
|||
|
||||
# logging.debug(data)
|
||||
logging.debug("Writing ZIP path %s" % path)
|
||||
# epub standard requires mimetype to be uncompressed and first file.
|
||||
if path == 'mimetype':
|
||||
compress=zipfile.ZIP_STORED
|
||||
else:
|
||||
compress=zipfile.ZIP_DEFLATED
|
||||
try:
|
||||
memzip.writestr(path, data.encode('utf-8'))
|
||||
memzip.writestr(path, data.encode('utf-8'), compress_type=compress)
|
||||
except UnicodeDecodeError, e:
|
||||
memzip.writestr(path.encode('utf-8'), data.encode('utf-8'))
|
||||
memzip.writestr(path.encode('utf-8'), data.encode('utf-8'), compress_type=compress)
|
||||
|
||||
for zf in memzip.filelist:
|
||||
zf.create_system = 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue