Exemple #1
0
    def books(self, oncard=None, end_session=True):
        """
        Return a list of ebooks on the device.

        :param oncard:  If 'carda' or 'cardb' return a list of ebooks on the
                        specific storage card, otherwise return list of ebooks
                        in main memory of device. If a card is specified and no
                        books are on the card return empty list.

        :return: A BookList.

        """
        logger.debug(sys._getframe().f_code.co_name)
        card_id = self._convert_oncard_to_cardid(oncard)
        storage_type = self.qt_settings.get(card_id,
                                            {}).get('storage_type', "")
        storage_id = self.qt_settings.get(card_id, {}).get('storage_id', None)
        if storage_id is not None:
            qt_response = ApiClient().books_all(storage_id)['data']
            qt_booklist = qt_response['Items']
        else:
            qt_booklist = []

        booklist = BookList(None, None, None)

        placeholderBook = Book()
        placeholderBook.title = "## {0} books ##".format(
            storage_type.capitalize())
        placeholderBook.authors = ['QuietThyme']
        placeholderBook.comments = "All Books in this list are actually stored on {0} cloud storage".format(
            storage_type.capitalize())

        placeholderBook.size = 0
        placeholderBook.thumbnail = get_resources(
            "images/{0}.png".format(storage_type))
        placeholderBook.tags = [storage_type]
        placeholderBook.identifiers = {}
        placeholderBook.path = "placeholder.ignore"

        booklist.add_book(placeholderBook, False)

        for i, qt_metadata in enumerate(qt_booklist):
            self.report_progress((i + 1) / float(len(qt_booklist)),
                                 _('Loading books from device...'))
            if qt_metadata['storage_identifier']:
                #logger.debug(qt_metadata)
                booklist.add_book(Book.from_quietthyme_metadata(qt_metadata),
                                  False)
        self.report_progress(1.0, _('Loaded book from device'))
        return booklist