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
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()
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)
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
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()
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
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()
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)
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
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
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
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())
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)
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")
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)
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)
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)
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
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
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"))
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)
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
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
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
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
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"
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
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)
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