mirror of
https://github.com/JimmXinu/FanFicFare.git
synced 2025-12-07 17:33:05 +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.path = parsedUrl.path
|
||||||
|
|
||||||
self.storyName = 'FF.Net story'
|
self.storyName = 'FF.Net story'
|
||||||
self.storyName = 'FF.Net author'
|
self.authorName = 'FF.Net author'
|
||||||
|
|
||||||
spl = self.path.split('/')
|
spl = self.path.split('/')
|
||||||
if len(spl) == 5:
|
if len(spl) == 5:
|
||||||
|
|
@ -108,7 +108,9 @@ class FFNet(FanfictionSiteAdapter):
|
||||||
title = o.string
|
title = o.string
|
||||||
logging.debug('URL = `%s`, Title = `%s`' % (url, title))
|
logging.debug('URL = `%s`, Title = `%s`' % (url, title))
|
||||||
urls.append((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
|
return urls
|
||||||
|
|
||||||
def getText(self, url):
|
def getText(self, url):
|
||||||
|
|
|
||||||
10
output.py
10
output.py
|
|
@ -109,7 +109,7 @@ class EPubFanficWriter(FanficWriter):
|
||||||
files = {}
|
files = {}
|
||||||
|
|
||||||
def _writeFile(self, fileName, data):
|
def _writeFile(self, fileName, data):
|
||||||
logging.debug('_writeFile(`%s`, data)' % fileName)
|
#logging.debug('_writeFile(`%s`, data)' % fileName)
|
||||||
if fileName in self.files:
|
if fileName in self.files:
|
||||||
try:
|
try:
|
||||||
d = data.decode('utf-8')
|
d = data.decode('utf-8')
|
||||||
|
|
@ -189,7 +189,9 @@ class EPubFanficWriter(FanficWriter):
|
||||||
|
|
||||||
text = self._removeEntities(text)
|
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)
|
allTags = self.soup.findAll(recursive=True)
|
||||||
for t in allTags:
|
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() == ' ' ) :
|
if p.string != None and (len(p.string.strip()) == 0 or p.string.strip() == ' ' ) :
|
||||||
p.extract()
|
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:
|
for br in allBrs:
|
||||||
if (br.string != None and len(br.string.strip()) != 0) or (br.contents != None):
|
if (br.string != None and len(br.string.strip()) != 0) or (br.contents != None):
|
||||||
br.name = 'p'
|
br.name = 'p'
|
||||||
|
|
@ -270,7 +272,7 @@ class EPubFanficWriter(FanficWriter):
|
||||||
zipdata = zipdir.inMemoryZip(self.files)
|
zipdata = zipdir.inMemoryZip(self.files)
|
||||||
|
|
||||||
if self.writeToFile:
|
if self.writeToFile:
|
||||||
f = open(filename, 'w')
|
f = open(filename, 'wb')
|
||||||
f.write(zipdata.getvalue())
|
f.write(zipdata.getvalue())
|
||||||
f.close()
|
f.close()
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
13
zipdir.py
13
zipdir.py
|
|
@ -17,6 +17,10 @@ def toZip(filename, directory):
|
||||||
|
|
||||||
if os.path.isfile(each):
|
if os.path.isfile(each):
|
||||||
print(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)
|
zippedHelp.write(each, arcname=entity)
|
||||||
else:
|
else:
|
||||||
addFolderToZip(zippedHelp,entity, each)
|
addFolderToZip(zippedHelp,entity, each)
|
||||||
|
|
@ -51,10 +55,15 @@ def inMemoryZip(files):
|
||||||
|
|
||||||
# logging.debug(data)
|
# logging.debug(data)
|
||||||
logging.debug("Writing ZIP path %s" % path)
|
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:
|
try:
|
||||||
memzip.writestr(path, data.encode('utf-8'))
|
memzip.writestr(path, data.encode('utf-8'), compress_type=compress)
|
||||||
except UnicodeDecodeError, e:
|
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:
|
for zf in memzip.filelist:
|
||||||
zf.create_system = 0
|
zf.create_system = 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue