Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
ProgressBar resume from where it stopped
monamour last edited by SGaist
I have created a desktop application by PYQT5 and python 3.7 to download a video by clicking the download button and save it locally in the PC.
The code will fetch the video link from (lineEdit.text()) which is labeled "URL" and save it in the local directory in (lineEdit_2.text()) which is labeled "SAVE AS". If the download stops for any reason, it will be resumed again by press the start download button. In addition, the ProgressBar start from 1% until 100% along with downloading the video. Everything working smoothly.
The question is, once the video stops in the middle for any reason then it resumes the downloading again but the ProgressBar should start from where it stopped but it is not. For example, if it stops in 50% then should be resumed from 50% and continue. However, it starts from 0% (from the beginning).
def curl_progress(self,total, existing, totalfrac,fracmb): global frac,tsize,size,save_location try: frac= float(existing)/float(total) self.progressBar.setValue(totalfrac) QApplication.processEvents() except (ZeroDivisionError, RuntimeError, TypeError, NameError): frac = 0 self.textBrowser.append("Downloaded %d/%d %d%%" % (existing, total, totalfrac)) if frac ==1.0: self.textBrowser.append("") size = os.path.getsize(save_location) tsize= (size /1024 /1024) QMessageBox.information(self,"Download Completed", "The Download is Finished and the size is %03.2f MB" %(tsize,)) self.textBrowser.append('Size of file is %03.2f MB' %(tsize,)) self.progressBar.setValue(0) self.lineEdit.setText('') self.lineEdit_2.setText('') QMessageBox.close(self) else: self.textBrowser.append("Downloaded %d/%d %d%%" % (existing, total, totalfrac)) def curl_limit_rate(self,rate_limit): global tsize,size,save_location url= self.lineEdit.text() save_location = self.lineEdit_2.text() if len(url) == 0 and len(save_location) == 0: QMessageBox.information(self, "Error", "Please put the links") return if len(url) > 0 and len(save_location) == 0: QMessageBox.information(self, "Error", "Please put the location") return if len(url) == 0 and len(save_location) > 0: QMessageBox.information(self, "Error", "Please put the link") return if len(url) > 0 and len(save_location) > 0: c = pycurl.Curl() c.setopt(pycurl.CAINFO, certifi.where()) c.setopt(c.URL,url) c.setopt(c.MAX_RECV_SPEED_LARGE, rate_limit) if os.path.exists(save_location): file_id = open(save_location, "ab") c.setopt(c.RESUME_FROM, os.path.getsize(save_location)) else: file_id = open(save_location, "wb") c.setopt(c.WRITEDATA, file_id) c.setopt(c.NOPROGRESS, 0) c.setopt(c.PROGRESSFUNCTION, self.curl_progress) c.perform() c.close() else: QMessageBox.information(self, "Error", "Unknown error!")
Many thanks in advance,
[edit: fixed text paragraph SGaist]
@monamour Hod do you resume?
If existing/total are correct then it should just work.
monamour last edited by monamour
By using this function
curl_limit_rate(self,rate_limit)it will resume without any problem but the progressbar will start from 0.
If the video file size is 100MB and download just 50MB in the same time the progressbar stops in 50% as well . However, once I start the download again it will continue from 50MB by the function above and in the same time the progressbar starts from 0%. So, the progressbar is not sync with resume function, this what I want.
@monamour How is curl_progress called? Is it a callback/slot?
@jsulm By pycurl, callbacks are defined using the setopt() method for Curl objects with options "PROGRESSFUNCTION" .
@monamour Then I guess you will need to write some code for that (unless there is a way to tell libcurl to not to reset progress). You will need to save last total/existing and use them also to calculate frac.
@jsulm Ok I will try. Many thanks,
@jsulm I have tried but no success. May you give me the clue please?
Denni 0 Banned last edited by
Please supply an MRE (Minimal Reproducible Example) of your last attempt to get this to work so we can help you troubleshoot your code.
@Denni-0 The code that I've posted is the last update because I don't know what is the logic I have to use and update it in the previous code.
Actually. the part that related to the resume the progress bar is not in the code.
Denni 0 Banned last edited by Denni 0
okay the code you supplied cannot by copy/pasted and ran as such is not an MRE as it needs to reproduce your issue and that cannot even be ran. So please update your code snippets to make it a MRE along with the part that is related to the resume progress bar since I believe that is part of, if not your base issue ??
well, great! Thanks for sharing the answer as well, don't forget to use the topic tools to set the topic to solved!