def decrypt(self, book): """Decrypts the book and returns the name of the output file. """ if self.outdir and not os.path.exists(self.outdir): os.makedirs(self.outdir) drmdir = os.path.join(self.outdir, 'drm') os.mkdir(drmdir) cleanbook = None mobi = None try: temp = sys.stdout sys.stdout = codecs.open(os.devnull, 'w', encoding='utf-8') if self.alfdir: sys.path.append(self.alfdir) from k4mobidedrm import decryptBook decryptBook(os.path.expanduser(book), drmdir, [], [self.serial], []) sys.stdout = temp cleanbook = os.listdir(drmdir)[0] mobi = os.path.join(self.outdir, dashify.dash_name(cleanbook.replace('_nodrm', ''))) os.rename(os.path.join(drmdir, cleanbook), mobi) finally: os.rmdir(drmdir) return mobi
def dashed_author(author): """ >>> dashed_author('Cialdini, Robert B.') 'cialdini' >>> dashed_author('Robert B. Cialdini') 'cialdini' >>> dashed_author('Robert B.Cialdini') 'cialdini' >>> dashed_author('Cialdini') 'cialdini' """ if not isinstance(author, basestring): author = author[0] if ',' in author: last, first = author.split(',') return dashify.dash_name(last) else: return dashify.dash_name(re.split(r'[\s\.]', author)[-1])
def dashed_title(title): """ >>> dashed_title(u'This Very Long and Unwieldy Title That Never Ends') u'this-very-long-and-unwieldy-title' >>> dashed_title(u'This Title: With a Subtitle') u'this-title' >>> dashed_title('this title (with paren)') u'this-title' """ title = title.split(u':')[0] title = re.sub(u'\(.*\)', '', title).strip() return reasonable_length(dashify.dash_name(title))
def dashed_author(author): """ >>> dashed_author('Cialdini, Robert B.') 'cialdini' >>> dashed_author('Robert B. Cialdini') 'cialdini' >>> dashed_author('Robert B.Cialdini') 'cialdini' >>> dashed_author('Cialdini') 'cialdini' >>> dashed_author("C{}\'ialdi\~ni") 'cialdini' """ if not isinstance(author, basestring): author = author[0] author = re.sub(u"[{}\\\\\\'~]", '', author) if ',' in author: last, first = author.split(',') return dashify.dash_name(last) else: return dashify.dash_name(re.split(r'[\s\.]', author)[-1])