diff --git a/books/place holder.txt b/books/place holder.txt new file mode 100644 index 00000000..e69de29b diff --git a/ffnet.py b/ffnet.py index d576ce64..fb1ff29e 100644 --- a/ffnet.py +++ b/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): diff --git a/output.py b/output.py index 79870c08..012b071a 100644 --- a/output.py +++ b/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,20 +189,22 @@ 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: for attr in t._getAttrMap().keys(): if attr not in acceptable_attributes: del t[attr] - + allPs = self.soup.findAll(recursive=True) for p in allPs: 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: diff --git a/zipdir.py b/zipdir.py index a0a568e6..ddaeb2f7 100644 --- a/zipdir.py +++ b/zipdir.py @@ -17,7 +17,11 @@ def toZip(filename, directory): if os.path.isfile(each): print(each) - zippedHelp.write(each, arcname=entity) + # 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