calibre修改倉庫存儲的文件名支持中文

背景


  • 使用calibre管理本地書籍,然后使用margin note 、ClearView直接打開書庫的文件
  • calibre為了保證跨平臺兼容,會把存入本地倉庫的書籍中文名稱解析成拼音,從而導致在margin note 、ClearView看到的文件名比較詭異。
  • 由于個人沒有跨平臺的需求,因此希望本地倉庫也是用中文存儲書籍而不是拼音

calibre 源碼倉庫


相關(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

參考資料


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

友情鏈接更多精彩內(nèi)容