def AddConvert(self):
        savePath = os.path.join(self.parent.savePath,
                                ToolUtil.GetCanSaveName(self.epsTitle))
        filePath = os.path.join(
            savePath, "{:04}.{}".format(self.curPreConvertId + 1, "jpg"))
        if not os.path.isfile(filePath):
            self.status = DownloadInfo.NotFound
            self.parent.SetConvertStatu(self.status)
            return
        isConvertNext = True
        while self.curPreConvertId < self.picCnt:
            if os.path.isfile(self.curConvertPath):
                self.curPreConvertId += 1
            else:
                isConvertNext = False
                f = open(filePath, "rb")
                data = f.read()
                f.close()

                w, h = ToolUtil.GetPictureSize(data)
                model = ToolUtil.GetDownloadScaleModel(w, h)
                QtTask().AddConvertTask("",
                                        data,
                                        model,
                                        self.AddConvertBack,
                                        cleanFlag="download_{}".format(
                                            self.parent.bookId))
                break
        self.parent.UpdateTableItem()
        if isConvertNext:
            self.StartConvert()
        return
示例#2
0
    def SetData(self, pSize=None, dataLen=0, state="", waifuSize=None, waifuDataLen=0, waifuState="", waifuTick=0, isInit=False):
        self.epsLabel.setText("位置:{}/{}".format(self.parent().curIndex+1, self.parent().maxPic))
        if pSize or isInit:
            if not pSize:
                pSize = QSize(0, 0)
            self.resolutionLabel.setText("分辨率:{}x{}".format(str(pSize.width()), str(pSize.height())))

        if dataLen or isInit:
            self.sizeLabel.setText("大小: " + ToolUtil.GetDownloadSize(dataLen))

        if waifuSize or isInit:
            if not waifuSize:
                waifuSize = QSize(0, 0)
            self.resolutionWaifu.setText("分辨率:{}x{}".format(str(waifuSize.width()), str(waifuSize.height())))
        if waifuDataLen or isInit:
            self.sizeWaifu.setText("大小:" + ToolUtil.GetDownloadSize(waifuDataLen))

        if state or isInit:
            self.stateLable.setText("状态:" + state)

        if waifuState or isInit:
            self.stateWaifu.setText("状态:" + waifuState)
        if waifuTick or isInit:
            self.tickLabel.setText("耗时:" + str(waifuTick) + "s")

        self.parent().MoveTool()
示例#3
0
 def SetData(self, data, category):
     if not data:
         self.state = self.DownloadError
         return
     self.data = data
     self.w, self.h = ToolUtil.GetPictureSize(data)
     self.model = ToolUtil.GetLookScaleModel(self.w, self.h, category)
     self.state = self.DownloadSuc
     self.size = len(data)
示例#4
0
 def UpdateTable(self):
     for task in self.downloadingList:
         assert isinstance(task, DownloadInfo)
         downloadLen = task.speedDownloadLen
         size = ToolUtil.GetDownloadSize(downloadLen)
         allSize = ToolUtil.GetDownloadSize(task.downloadLen)
         task.speed = size + "/s"
         task.downSize = allSize
         self.UpdateTableItem(task)
         task.speedDownloadLen = 0
示例#5
0
 def _ShowImg(self, data):
     self.scaleCnt = 0
     self.pixMap = QPixmap()
     self.pixMap.loadFromData(data)
     self.show()
     self.graphicsItem.setPixmap(self.pixMap)
     self.graphicsView.setSceneRect(QRectF(QPointF(0, 0), QPointF(self.pixMap.width(), self.pixMap.height())))
     size = ToolUtil.GetDownloadSize(len(data))
     self.sizeLabel.setText(size)
     weight, height = ToolUtil.GetPictureSize(data)
     self.resolutionLabel.setText(str(weight) + "x" + str(height))
     self.ScalePicture()
示例#6
0
 def AddBookInfosBack(self, msg=""):
     if msg != Status.Ok:
         self.SetStatu(self.Error)
         return
     else:
         book = BookMgr().books.get(self.bookId)
         self.title = book.title
         self.savePath = os.path.join(os.path.join(config.SavePath, config.SavePathDir),
                                      ToolUtil.GetCanSaveName(self.title))
         self.savePath = os.path.join(self.savePath, "原图")
         self.convertPath = os.path.join(os.path.join(config.SavePath, config.SavePathDir),
                                      ToolUtil.GetCanSaveName(self.title))
         self.convertPath = os.path.join(self.convertPath, "waifu2x")
         self.AddBookEpsInfos()
     return
示例#7
0
    def _Download(self, task):
        try:
            if not isinstance(task.req, req.SpeedTestReq):
                for cachePath in [task.cacheAndLoadPath, task.loadPath]:
                    if cachePath and task.bakParam:
                        data = ToolUtil.LoadCachePicture(cachePath)
                        if data:
                            from src.qt.util.qttask import QtTask
                            QtTask().downloadBack.emit(task.bakParam,
                                                       len(data), data)
                            QtTask().downloadBack.emit(task.bakParam, 0, b"")
                            return
            request = task.req
            if request.params == None:
                request.params = {}

            if request.headers == None:
                request.headers = {}

            r = self.session.get(request.url,
                                 proxies=request.proxy,
                                 headers=request.headers,
                                 stream=True,
                                 timeout=task.timeout,
                                 verify=False)
            # task.res = res.BaseRes(r)
            task.res = r
        except Exception as es:
            task.status = Status.NetError
        self.handler.get(task.req.__class__)(task)
        if task.res:
            task.res.close()
示例#8
0
 def __init__(self, bookId="", page=""):
     url = config.Url + "comics/{}/eps?page={}".format(bookId, page)
     method = "GET"
     self.bookId = bookId
     super(self.__class__, self).__init__(url,
                                          ToolUtil.GetHeader(url, method),
                                          {}, method)
示例#9
0
    def AddUserItem(self,
                    content,
                    name,
                    createdTime,
                    floor,
                    url="",
                    path="",
                    originalName=""):
        index = self.count()
        iwidget = UserItemWidget(self)
        iwidget.commentLabel.setText(content)
        iwidget.label.setText(name)
        timeArray, day = ToolUtil.GetDateStr(createdTime)
        if day >= 1:
            iwidget.timeLabel.setText("{}天前".format(str(day)))
        else:
            strTime = "{}:{}:{}".format(timeArray.tm_hour, timeArray.tm_min,
                                        timeArray.tm_sec)
            iwidget.timeLabel.setText("{}".format(strTime))

        iwidget.indexLabel.setText("{}楼".format(str(floor)))

        item = QListWidgetItem(self)
        item.setSizeHint(iwidget.sizeHint())
        self.setItemWidget(item, iwidget)
        if url and path and config.IsLoadingPicture:
            QtTask().AddDownloadTask(url, path, None,
                                     self.LoadingPictureComplete, True, index,
                                     True, self.GetName())
            pass
示例#10
0
    def AddUserItem(self, commnetId, commentsCount, likesCount, content, name, createdTime, floor, url="", path="", originalName="", title="", level=1):
        index = self.count()
        iwidget = QtComment(self)
        iwidget.id = commnetId
        iwidget.commentLabel.setText(content)
        iwidget.nameLabel.setText(name)
        iwidget.numLabel.setText("({})".format(commentsCount))
        iwidget.starLabel.setText("({})".format(likesCount))
        iwidget.levelLabel.setText(" LV" + str(level) + " ")
        iwidget.titleLabel.setText(" " + title + " ")
        if createdTime:
            timeArray, day = ToolUtil.GetDateStr(createdTime)
            if day >= 1:
                iwidget.dateLabel.setText("{}天前".format(str(day)))
            else:
                strTime = "{}:{}:{}".format(timeArray.tm_hour, timeArray.tm_min, timeArray.tm_sec)
                iwidget.dateLabel.setText("{}".format(strTime))

        iwidget.indexLabel.setText("{}楼".format(str(floor)))

        item = QListWidgetItem(self)
        item.setSizeHint(iwidget.sizeHint())
        self.setItemWidget(item, iwidget)
        if url and config.IsLoadingPicture:
            QtTask().AddDownloadTask(url, path, None, self.LoadingPictureComplete, True, index, True, self.GetName())
            pass
示例#11
0
 def UpdateFavoritesBack(self, backData):
     try:
         if backData.status != Status.Ok:
             return backData.status, self.page
         if backData.res.code == 200:
             info = backData.res.data.get("comics", {})
             self.total = info["total"]
             self.page = info["page"]
             self.pages = info["pages"]
             self.category[self.page] = []
             for bookInfo in info["docs"]:
                 data = CategoryInfo()
                 ToolUtil.ParseFromData(data, bookInfo)
                 self.category[self.page].append(data)
             Log.Info("收藏夹加载成功, page:{}, pages:{}, num:{}".format(
                 self.page, self.pages, self.total))
             return Status.Ok, self.page
         else:
             return Status.Error + backData.res.message, self.page
     except Exception as e:
         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 + e, self.page
示例#12
0
 def UpdateText(self, model):
     index, noise, scale = ToolUtil.GetModelAndScale(model)
     self.modelBox.setCurrentIndex(index)
     self.label_2.setText("去噪等级:" + str(noise))
     self.label_3.setText("放大倍数:" + str(scale))
     self.label_9.setText("转码模式:" +
                          self.readImg.owner().settingForm.GetGpuName())
示例#13
0
 def __init__(self, user: str, passwd: str):
     url = config.Url + "auth/sign-in"
     method = "POST"
     super(self.__class__, self).__init__(url,
                                          ToolUtil.GetHeader(url, method), {
                                              "email": user,
                                              "password": passwd
                                          }, method)
示例#14
0
 def __init__(self, page, categories, sort=""):
     categories = quote(categories)
     url = config.Url + "comics?page={}&c={}&s={}".format(
         page, categories, sort)
     method = "GET"
     super(self.__class__, self).__init__(url,
                                          ToolUtil.GetHeader(url, method),
                                          {}, method)
    def SetData(self,
                pSize=None,
                dataLen=0,
                state="",
                waifuSize=None,
                waifuDataLen=0,
                waifuState="",
                waifuTick=0,
                isInit=False):
        self.UpdateSlider()
        self.epsLabel.setText("位置:{}/{}".format(self.readImg.curIndex + 1,
                                                self.readImg.maxPic))
        if pSize or isInit:
            if not pSize:
                pSize = QSize(0, 0)
            self.resolutionLabel.setText("分辨率:{}x{}".format(
                str(pSize.width()), str(pSize.height())))

        if dataLen or isInit:
            self.sizeLabel.setText("大小: " + ToolUtil.GetDownloadSize(dataLen))

        if waifuSize or isInit:
            if not waifuSize:
                waifuSize = QSize(0, 0)
            self.resolutionWaifu.setText("分辨率:{}x{}".format(
                str(waifuSize.width()), str(waifuSize.height())))
        if waifuDataLen or isInit:
            self.sizeWaifu.setText("大小:" +
                                   ToolUtil.GetDownloadSize(waifuDataLen))

        if state or isInit:
            self.stateLable.setText("状态:" + state)

        if waifuState or isInit:
            if waifuState == QtFileData.WaifuStateStart:
                self.stateWaifu.setStyleSheet("color:red;")
            elif waifuState == QtFileData.WaifuStateEnd:
                self.stateWaifu.setStyleSheet("color:green;")
            elif waifuState == QtFileData.WaifuStateFail:
                self.stateWaifu.setStyleSheet("color:red;")
            else:
                self.stateWaifu.setStyleSheet("color:dark;")
            if config.CanWaifu2x:
                self.stateWaifu.setText("状态:" + waifuState)
        if waifuTick or isInit:
            self.tickLabel.setText("耗时:" + str(waifuTick) + "s")
示例#16
0
 def __init__(self, page, categories, keyword="", sort=""):
     url = config.Url + "comics/advanced-search?page={}".format(page)
     method = "POST"
     super(self.__class__, self).__init__(url,
                                          ToolUtil.GetHeader(url, method), {
                                              "categories": categories,
                                              "keyword": keyword,
                                              "sort": sort
                                          }, method)
示例#17
0
 def __init__(self, url, path="", isSaveCache=False):
     url = url + "/static/{}".format(path)
     method = "Download"
     self.url = url
     self.path = path
     self.isSaveCache = isSaveCache
     super(self.__class__, self).__init__(url,
                                          ToolUtil.GetHeader(url, method),
                                          {}, method)
示例#18
0
 def __init__(self, data, isParseRes) -> None:
     super().__init__()
     self.raw = data
     self.data = {}
     self.code = 0
     self.message = ""
     self.reqBak = None
     if isParseRes:
         ToolUtil.ParseFromData(self, self.raw.text)
示例#19
0
    def AddConvert(self):
        savePath = os.path.join(self.parent.savePath, ToolUtil.GetCanSaveName(self.epsTitle))
        filePath = os.path.join(savePath, "{:04}.{}".format(self.curPreConvertId + 1, "jpg"))
        if not os.path.isfile(filePath):
            self.status = DownloadInfo.Error
            self.parent.SetConvertStatu(self.status)
            return
        if os.path.isfile(self.curConvertPath):
            self.curPreConvertId += 1
            return self.StartConvert()
        f = open(filePath, "rb")
        data = f.read()
        f.close()

        w, h = ToolUtil.GetPictureSize(data)
        model = ToolUtil.GetDownloadScaleModel(w, h)
        QtTask().AddConvertTask("", data, model, self.AddConvertBack,
                                cleanFlag="download_".format(self.parent.bookId))
        return
示例#20
0
 def SetWaifuData(self, data, tick):
     if not data:
         self.waifuState = self.WaifuStateFail
         return
     self.waifuData = data
     self.waifuState = self.WaifuStateEnd
     self.waifuDataSize = len(self.waifuData)
     self.scaleW, self.scaleH = ToolUtil.GetPictureSize(data)
     self.waifuTick = tick
     return
示例#21
0
 def GetDonwloadFilePath(self, bookId, epsId, index):
     if bookId not in self.downloadDict:
         return ""
     task = self.downloadDict[bookId]
     if epsId not in task.epsInfo:
         return ""
     epsTitle = task.epsInfo[epsId].epsTitle
     savePath = os.path.join(task.savePath,
                             ToolUtil.GetCanSaveName(epsTitle))
     return os.path.join(savePath, "{:04}.{}".format(index + 1, "jpg"))
示例#22
0
 def __init__(self):
     url = SpeedTestReq.URLS[SpeedTestReq.Index]
     SpeedTestReq.Index += 1
     if SpeedTestReq.Index >= len(SpeedTestReq.URLS):
         SpeedTestReq.Index = 0
     method = "Download"
     header = ToolUtil.GetHeader(url, method)
     header['cache-control'] = 'no-cache'
     header['expires'] = '0'
     header['pragma'] = 'no-cache'
     super(self.__class__, self).__init__(url, header,
                                          {}, method)
示例#23
0
 def UpdateCateGoryBack(self, backData):
     for info in backData.res.data.get("categories", {}):
         if info.get("isWeb"):
             continue
         # 兼容下图片加载失败
         if info.get("thumb").get('fileServer') == "https://wikawika.xyz/static/":
             info["thumb"]["fileServer"] = 'https://storage1.picacomic.com'
         newInfo = CateGoryBase()
         ToolUtil.ParseFromData(newInfo, info)
         self.idToCateGoryBase.append(newInfo)
     Log.Info("初始化目录成功。。。")
     return
示例#24
0
 def StartWaifu2x(self):
     if not QtImgMgr().data:
         return
     self.comboBox.setEnabled(False)
     self.changeButton.setEnabled(False)
     self.index = self.comboBox.currentIndex()
     index = self.comboBox.currentIndex()
     model = ToolUtil.GetModelByIndex(index)
     QtTask().AddConvertTask("", QtImgMgr().data, model, self.AddConvertBack,
                             cleanFlag="QtImg")
     self.changeButton.setText("正在转换")
     return
示例#25
0
 def SwitchModel(self, index):
     data = self.readImg.pictureData.get(self.readImg.curIndex)
     if not data:
         return
     if not data.model:
         return
     if not data.data:
         return
     index2, _, _ = ToolUtil.GetModelAndScale(data.model)
     if index2 == index:
         return
     data.model = ToolUtil.GetModelByIndex(index)
     data.waifuData = None
     data.waifuState = data.WaifuStateStart
     data.waifuDataSize = 0
     data.scaleW, data.scaleH = 0, 0
     data.waifuTick = 0
     self.label_2.setText("去噪等级:" + str(1))
     self.label_3.setText("放大倍数:" + str(1))
     self.SetData(waifuSize=QSize(), waifuDataLen=0, waifuTick=0)
     self.readImg.ShowImg()
     self.readImg.CheckLoadPicture()
     return
示例#26
0
    def InitImageServer(self, backData):
        try:
            if backData.res.code == 200:
                # 选择了分流才设置
                if self.server.address:
                    self.server.imageServer = ToolUtil.GetUrlHost(
                        backData.res.data["imageServer"])
                    Log.Info("初始化图片服务器成功, info:{}".format(
                        self.server.imageServer))

                return Status.Ok
            else:
                return Status.Error
        except Exception as es:
            Log.Error(es)
            return Status.Error
示例#27
0
    def __DealHeaders(self, request, token):
        if self.token:
            request.headers["authorization"] = self.token
        if token:
            request.headers["authorization"] = token

        if self.address:
            host = ToolUtil.GetUrlHost(request.url)
            if host in config.Url:
                request.url = request.url.replace(host, self.address).replace("https://", "http://")
                request.headers["Host"] = host
            else:
                request.url = request.url.replace(host, self.imageServer)

        if request.method.lower() == "post":
            request.headers["Content-Type"] = "application/json; charset=UTF-8"
示例#28
0
    def InitSetting(self):
        for bookId in self.settings.childKeys():
            data = self.settings.value(bookId)
            task = DownloadInfo()
            task.bookId = bookId
            task.status = DownloadStatus.Pause

            ToolUtil.ParseFromData(task, data)

            self.downloadDict[task.bookId] = task
            self.downloadList.append(task)
            rowCont = self.tableWidget.rowCount()
            task.tableRow = rowCont
            self.tableWidget.insertRow(rowCont)
            self.UpdateTableItem(task)
            pass
示例#29
0
 def __init__(self, data):
     # data = {
     #     "email": email,
     #     "password": password,
     #     "name": name,
     #     "birthday": birthday,
     #     "gender": gender,  # m, f, bot
     #     "answer1": answer1,
     #     "answer2": answer2,
     #     "answer3": answer3,
     #     "question1": question1,
     #     "question2": question2,
     #     "question3": question3
     # }
     url = config.Url + "auth/register"
     method = "POST"
     super(self.__class__, self).__init__(url, ToolUtil.GetHeader(url, method),
                                          data, method)
示例#30
0
    def InitImageServer(self, backData):
        try:
            if backData.res.code == 200:
                # 选择了分流才设置
                if self.server.address:
                    self.server.imageServer = ToolUtil.GetUrlHost(
                        backData.res.data["imageServer"])
                    Log.Info("初始化图片服务器成功, info:{}".format(
                        self.server.imageServer))

                return Status.Ok
            else:
                return Status.Error
        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