コード例 #1
0
    def OpenBookBack(self, msg):
        self.loadingForm.close()
        self.listWidget.UpdatePage(1, 1)
        self.childrenListWidget.UpdatePage(1, 1)
        self.childrenListWidget.UpdateState()
        self.listWidget.UpdateState()
        self.categoriesList.clear()
        self.tagsList.clear()
        self.autorList.clear()
        info = BookMgr().books.get(self.bookId)
        if msg == Status.Ok and info:
            # self.autor.setText(info.author)
            self.autorList.AddItem(info.author)
            self.title.setText(info.title)
            self.bookName = info.title
            self.description.setText(info.description)
            self.isFinished.setText("完本" if info.finished else "未完本")
            for name in info.categories:
                self.categoriesList.AddItem(name)
            # self.categories.setText(','.join(info.categories))
            # self.tags.setText(','.join(info.tags))
            for name in info.tags:
                self.tagsList.AddItem(name)
            self.likes.setText(str(info.totalLikes))
            self.views.setText(str(info.totalViews))

            if info.isFavourite:
                self.favorites.setEnabled(False)
            else:
                self.favorites.setEnabled(True)
            self.picture.setText("图片加载中...")
            fileServer = info.thumb.get("fileServer")
            path = info.thumb.get("path")
            name = info.thumb.get("originalName")
            self.url = fileServer
            self.path = path
            timeArray, day = ToolUtil.GetDateStr(info.updated_at)
            self.updateTick.setText(str(day) + "天前更新")
            if config.IsLoadingPicture:

                self.owner().qtTask.AddDownloadTask(
                    fileServer,
                    path,
                    completeCallBack=self.UpdatePicture,
                    cleanFlag=self.closeFlag)
            self.owner().qtTask.AddHttpTask(lambda x: Server().Send(
                req.GetComments(self.bookId), bakParam=x),
                                            self.GetCommnetBack,
                                            cleanFlag=self.closeFlag)

            self.owner().qtTask.AddHttpTask(
                lambda x: BookMgr().AddBookEpsInfo(self.bookId, x),
                self.GetEpsBack,
                cleanFlag=self.closeFlag)
            self.startRead.setEnabled(False)
        else:
            # QtWidgets.QMessageBox.information(self, '加载失败', msg, QtWidgets.QMessageBox.Yes)
            self.msgForm.ShowError(msg)
            self.hide()
        return
コード例 #2
0
    def __call__(self, backData):
        if backData.status != Status.Ok:
            if backData.bakParam:
                QtTask().taskBack.emit(backData.bakParam, "")
        else:
            r = backData.res
            try:
                if r.status_code != 200:
                    if backData.bakParam:
                        QtTask().taskBack.emit(backData.bakParam, "")
                    return

                fileSize = int(r.headers.get('Content-Length', 0))
                getSize = 0
                now = time.time()
                consume = 1
                for chunk in r.iter_content(chunk_size=10240):
                    getSize += len(chunk)
                    consume = time.time() - now
                    if consume >= 2:
                        break

                downloadSize = getSize / consume
                speed = ToolUtil.GetDownloadSize(downloadSize)
                if backData.bakParam:
                    QtTask().taskBack.emit(backData.bakParam, speed)

            except Exception as es:
                Log.Error(es)
                if backData.bakParam:
                    QtTask().taskBack.emit(backData.bakParam, "")
コード例 #3
0
 def AddBookByIdBack(self, backData):
     try:
         if backData.res.data.get("comic"):
             info = self.books.get(backData.res.data['comic']['_id'])
             if not info:
                 info = Book()
             ToolUtil.ParseFromData(info, backData.res.data['comic'])
             self.books[info.id] = info
             return Status.Ok
         else:
             Log.Warn("未找到书籍, bookId:{}".format(backData))
             return Status.NotFoundBook
     except Exception as es:
         Log.Error(es)
         return Status.NetError
コード例 #4
0
ファイル: book.py プロジェクト: 2572724988/picacg-windows
    def AddBookEpsPicInfoBack(self, backData):
        # 此处在线程中加载后续分页 TODO 分页太多时会导致太慢
        try:
            r = backData.res
            bookId = backData.req.bookId
            epsId = backData.req.epsId

            bookInfo = self.books.get(bookId)

            epsInfo = bookInfo.eps[epsId - 1]
            page = r.data['pages']["page"]
            pages = r.data['pages']["pages"]
            limit = r.data['pages']["limit"]

            # 重新初始化
            # if page == 1:
            #     del epsInfo.pics[:]

            for i, data in enumerate(r.data['pages']['docs']):
                index = (page - 1) * limit + i
                if len(epsInfo.pics) > index:
                    picInfo = epsInfo.pics[index]
                else:
                    picInfo = Picture()
                    epsInfo.pics.append(picInfo)
                ToolUtil.ParseFromData(picInfo, data['media'])

            loadPage = int((len(epsInfo.pics) - 1) / limit + 1)
            nextPage = page + 1
            # 如果已经有了,则从最后那一页加载起就可以了
            if loadPage > nextPage:
                nextPage = loadPage

            if nextPage <= pages:
                self.server.Send(req.GetComicsBookOrderReq(
                    bookId, epsId, nextPage),
                                 bakParam=backData.bakParam,
                                 isASync=False)
                return Status.WaitLoad
            return Status.Ok
        except Exception as es:
            import sys
            cur_tb = sys.exc_info()[
                2]  # return (exc_type, exc_value, traceback)
            e = sys.exc_info()[1]
            Log.Error(cur_tb, e)
            return Status.Error
コード例 #5
0
ファイル: book.py プロジェクト: 2572724988/picacg-windows
    def AddBookEpsInfoBack(self, backData):
        # 此处在线程中加载后续章节 TODO 章节太多时会导致太慢
        try:
            r = backData.res
            bookId = backData.req.bookId
            info = self.books.get(bookId)
            info.epsCount = r.data['eps']["total"]
            page = r.data['eps']["page"]

            # 重新初始化
            pages = r.data['eps']["pages"]
            limit = r.data['eps']["limit"]
            # 优化,如果分页已经加载好了,只需要重新加载更新最后一页即可

            for i, data in enumerate(r.data['eps']['docs']):
                index = (page - 1) * limit + i
                if len(info.eps) > index:
                    epsInfo = info.eps[index]
                else:
                    epsInfo = BookEps()
                    info.eps.append(epsInfo)
                ToolUtil.ParseFromData(epsInfo, data)

            loadPage = int((len(info.eps) - 1) / limit + 1)
            nextPage = page + 1
            # 如果已经有了,则从最后那一页加载起就可以了
            if loadPage > nextPage:
                nextPage = loadPage

            info.eps.sort(key=lambda a: a.order)

            if nextPage <= pages:
                self.server.Send(req.GetComicsBookEpsReq(bookId, nextPage),
                                 bakParam=backData.bakParam,
                                 isASync=False)
                return Status.WaitLoad
            return Status.Ok
        except Exception as es:
            import sys
            cur_tb = sys.exc_info()[
                2]  # return (exc_type, exc_value, traceback)
            e = sys.exc_info()[1]
            Log.Error(cur_tb, e)
            return Status.Error
コード例 #6
0
 def _DownloadBoos(self, bookId):
     bookInfo = self.books.get(bookId)
     if not bookInfo:
         return
     for index, eps in enumerate(bookInfo.eps):
         if eps.pics:
             continue
         page = 0
         pages = 1
         while page < pages:
             r = self.server.Send(
                 req.GetComicsBookOrderReq(bookId, index + 1, page + 1))
             page = r.data['pages']["page"]
             pages = r.data['pages']["pages"]
             for data in r.data['pages']['docs']:
                 epsInfo = Picture()
                 ToolUtil.ParseFromData(epsInfo, data['media'])
                 eps.pics.append(epsInfo)
     pass
コード例 #7
0
ファイル: book.py プロジェクト: 2572724988/picacg-windows
 def AddBookByIdBack(self, backData):
     try:
         if backData.res.data.get("comic"):
             info = self.books.get(backData.res.data['comic']['_id'])
             if not info:
                 info = Book()
             ToolUtil.ParseFromData(info, backData.res.data['comic'])
             self.books[info.id] = info
             return Status.Ok
         else:
             Log.Warn("未找到书籍, bookId:{}".format(backData))
             return Status.NotFoundBook
     except Exception as es:
         import sys
         cur_tb = sys.exc_info()[
             2]  # return (exc_type, exc_value, traceback)
         e = sys.exc_info()[1]
         Log.Error(cur_tb, e)
         return Status.NetError
コード例 #8
0
ファイル: book.py プロジェクト: LegendAdmin/picacg-windows
    def AddBookEpsInfoBack(self, backData):
        # 此处在线程中加载后续章节 TODO 章节太多时会导致太慢
        try:
            r = backData.res
            bookId = backData.req.bookId
            info = self.books.get(bookId)
            info.epsCount = r.data['eps']["total"]
            page = r.data['eps']["page"]

            # 重新初始化
            pages = r.data['eps']["pages"]
            limit = r.data['eps']["limit"]
            # 优化,如果分页已经加载好了,只需要重新加载更新最后一页即可

            for i, data2 in enumerate(r.data['eps']['docs']):
                # index = (page -1) * limit + i
                epsId = data2.get('id')
                if epsId in info.epsDict:
                    epsInfo = info.epsDict[epsId]
                else:
                    epsInfo = BookEps()
                    info.epsDict[epsId] = epsInfo
                    # info.eps.append(epsInfo)
                ToolUtil.ParseFromData(epsInfo, data2)

            loadPage = int((len(info.epsDict) - 1) / limit + 1)
            nextPage = page + 1
            # 如果已经有了,则从最后那一页加载起就可以了
            if loadPage > nextPage:
                nextPage = loadPage

            info.eps = list(info.epsDict.values())
            info.eps.sort(key=lambda a: a.order)

            if nextPage <= pages:
                self.server.Send(req.GetComicsBookEpsReq(bookId, nextPage),
                                 bakParam=backData.bakParam,
                                 isASync=False)
                return Status.WaitLoad
            return Status.Ok
        except Exception as es:
            Log.Error(es)
            return Status.Error