|
![]() |
|
Thread Tools | Search this Thread |
![]() |
#1 |
Junior Member
![]() Posts: 6
Karma: 10
Join Date: Jul 2022
Device: PW5
|
Crude way to generate mobi file in python (should run on kindle directly)
Hi,
I did some work to be able to generate a mobi file in python. The lib in theory should be able to parse the mobi file as well, but it was not well tested. Code could use a lot of cleanup, but if somebody is looking for such lib, maybe he/she will want to put in that work. Hope it's going to be usefull for at least a single person. A bonus is that in theory (didn't test that yet) it could work on jailbroken kindle with python extension installed. https://gitlab.com/jmikucki/mobicreator/ This is how I use it in my code: Code:
from mobicreator.mobipublication import Publication import glob import os class OutputMobi(): def __init__(self, **kwargs): print(kwargs) self._path = kwargs.get('path', './output') self._file_name = kwargs.get('file_name', 'articles.mobi') self._img_path = kwargs.get('img_path', './img') self._cover_img_path = kwargs.get('cover_img_path', None) self._thumb_img_path = kwargs.get('thumb_img_path', None) self._title = kwargs.get('title', 'Unknown title') def output_articles(self, articles): SECTION_CUT_SIZE = 4000 print(f'Creating mobi file.') mobi = Publication() mobi.setTitle(self._title) print(f'\tAdding text sections.') for a in articles: mobi.addText(data=a.encode('utf-8'), section_bytes=SECTION_CUT_SIZE) print(f'\tAdding image sections.') img_files = glob.glob(f'{self._img_path}/img*') for img_file_path in img_files: print(f'Adding image: {img_file_path}') mobi.addImage(file=img_file_path) if self._cover_img_path is not None: mobi.setCover(file=self._cover_img_path) if self._thumb_img_path is not None: mobi.setThumb(file=self._thumb_img_path) print(f'\tWriting mobi file.') mobi.write(f'{self._path}/{self._file_name}') print(f'Done.') |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
What is a perfect procedure for generate a amazon kindle mobi file? | Zohaib Ahmed | Kindle Formats | 46 | 07-05-2019 03:24 PM |
How can i run python (standalone version? ) on my kindle fire? | ah_ha | Kindle Fire | 6 | 04-03-2013 01:36 AM |
KindleNamer: Kindle/Mobi File Naming AppleScript/Python Script | pdurrant | Kindle Formats | 1 | 11-22-2012 06:23 AM |
How to generate Mobi that can display current chapter name while read on Kindle? | forceps | Conversion | 1 | 05-18-2012 09:32 PM |
Possible to run Java .jar's directly? | CaelThunderwing | Kindle Developer's Corner | 8 | 12-07-2011 05:49 AM |