背景
- 使用calibre管理本地書籍,然后使用margin note 、ClearView直接打開書庫的文件
- calibre為了保證跨平臺兼容,會把存入本地倉庫的書籍中文名稱解析成拼音,從而導致在margin note 、ClearView看到的文件名比較詭異。
- 由于個人沒有跨平臺的需求,因此希望本地倉庫也是用中文存儲書籍而不是拼音
calibre 源碼倉庫
- https://github.com/kovidgoyal/calibre
- 下載對應release版本的源碼
相關(guān)代碼
src/calibre/db/backend.py中可以看到construct_file_name等函數(shù)中使用calibre.utils.filenames.ascii_filename進行文件名稱的編碼,實現(xiàn)中文轉(zhuǎn)拼音的操作
-
修改源碼
-
修改backend.py中的construct_file_name函數(shù) 去掉ascii_filename調(diào)用及decode調(diào)用
def construct_file_name(self, book_id, title, author, extlen): ''' Construct the file name for this book based on its metadata. ''' extlen = max(extlen, 14) # 14 accounts for ORIGINAL_EPUB # The PATH_LIMIT on windows already takes into account the doubling # (it is used to enforce the total path length limit, individual path # components can be much longer than the total path length would allow on # windows). l = (self.PATH_LIMIT - (extlen // 2) - 2) if iswindows else ((self.PATH_LIMIT - extlen - 2) // 2) if l < 5: raise ValueError('Extension length too long: %d' % extlen) author = author[:l] title = title.lstrip()[:l].rstrip() if not title: title = 'Unknown'[:l] name = title + ' - ' + author while name.endswith('.'): name = name[:-1] if not name: name = _('Unknown').decode('ascii', 'replace') return name
-
-
修改源碼后進行編譯
cd src && python2 -O -m compileall . -
更新文件
cp ./calibre/db/backend.pyo /Applications/calibre.app/Contents/Resources/Python/site-packages/calibre/db/backend.pyo -
已經(jīng)導入的書籍名稱更新
-
在calibre中選擇數(shù)據(jù),雙擊觸發(fā)重命名操作后直接回車保存即可
image-20190424190515880.png
image-20190424190529705.png -

