calibre 修改仓库存储的文件名支持中文

## 路径下

/usr/lib/calibre/calibre/db

## 修改backend.py文件

注释        #author = ascii_filename(author)[:l].decode('ascii', 'replace')

        #title  = ascii_filename(title.lstrip())[:l].decode('ascii', 'replace').rstrip()

        #author = ascii_filename(author)[:l].decode('ascii', 'replace')

        #title  = ascii_filename(title.lstrip())[:l].decode('ascii', 'replace').rstrip()


def construct_path_name(self, book_id, title, author):

        '''

        Construct the directory name for this book based on its metadata.

        '''

        book_id = ' (%d)' % book_id

        l = self.PATH_LIMIT - (len(book_id) // 2) - 2

        #author = ascii_filename(author)[:l].decode('ascii', 'replace')

        #title  = ascii_filename(title.lstrip())[:l].decode('ascii', 'replace').rstrip()

        if not title:

            title = 'Unknown'[:l]

        try:

            while author[-1] in (' ', '.'):

                author = author[:-1]

        except IndexError:

            author = ''

        if not author:

            author = ascii_filename(_('Unknown')).decode(

                    'ascii', 'replace')

        if author.upper() in WINDOWS_RESERVED_NAMES:

            author += 'w'

        return '%s/%s%s' % (author, title, book_id)

    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 = ascii_filename(author)[:l].decode('ascii', 'replace')

        #title  = ascii_filename(title.lstrip())[:l].decode('ascii', 'replace').rstrip()

        if not title:

            title = 'Unknown'[:l]

        name  = title + ' - ' + author

        while name.endswith('.'):

            name = name[:-1]

        if not name:

            name = ascii_filename(_('Unknown')).decode('ascii', 'replace')

        return name

## 重新编译该文件

python2 -m py_compile backend.py

你可能感兴趣的:(calibre 修改仓库存储的文件名支持中文)