Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Не находит книги во вложенных zip файлах в архивах либрусека #80

Open
Gustik opened this issue Aug 9, 2021 · 0 comments

Comments

@Gustik
Copy link

Gustik commented Aug 9, 2021

Архив книг имеет такую структуру

fb2-000065-005477.zip
    - xxxx.zip (Внутри один fb2 файл)
    - xxxx.zip (Внутри один fb2 файл)

Сканер проходит по всем файлам fb2-xxxxxxx-yyyyyyy.zip, но не заглядывает во вложенные zip файлы.

Потом догадался добавить расширение .zip в параметр SOPDS_BOOK_EXTENSIONS (Список расширений файлов, для включения в коллекцию книг по умолчанию содержит: .pdf .djvu .fb2 .epub .mobi)

После чего сканер начал парсить внутренние zip файлы.
Только начал ругаться что у объекта tree нет метода getroot

src/book_tools/format/fb2.py:73

def __detect_namespaces(self, tree):
    if tree.getroot().tag.find(Namespace.FICTION_BOOK21) > 0:
        self.__namespaces['fb'] = Namespace.FICTION_BOOK21
    return None

И действительно в классе FB2Zip в методе __create_tree__ объект tree создается методом etree.fromstring (создает объект класса Element), тогда как в классе FB2 в __create_tree__ объект tree создается методом etree.parse (создает объект класса ElementTree)

Может в классе FB2Zip сделать так чтобы метод __create_tree__ возвращал Element

class FB2(FB2Base):
    def __init__(self, file, original_filename):
        FB2Base.__init__(self, file, original_filename, Mimetype.FB2)

    def __create_tree__(self):
        try:
            self.file.seek(0,0)
            # Было так return etree.parse(self.file)
            return etree.parse(self.file).getroot()
        except Exception as err:
            raise FB2StructureException('the file is not a valid XML (%s)'%err)

    def __exit__(self, kind, value, traceback):
        pass

Тогда __detect_namespaces(self, tree) можно было изменить на такое

def __detect_namespaces(self, tree):
    # Было так if tree.getroot().tag.find(Namespace.FICTION_BOOK21) > 0:
    if tree.tag.find(Namespace.FICTION_BOOK21) > 0:
        self.__namespaces['fb'] = Namespace.FICTION_BOOK21
    return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant