Skip to content
This repository has been archived by the owner on Sep 25, 2022. It is now read-only.

Commit

Permalink
fix download without resume, especially for transcoding #77
Browse files Browse the repository at this point in the history
  • Loading branch information
Monschichi committed Dec 28, 2021
1 parent a5f72a2 commit 74b8143
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def video_parts(self, video: Video):
status = self.download(url=url, path=path, filename=filename, title=video.title)
if status in [200, 416]:
pass
elif status in [403, 33] and not self.no_transcoding:
elif status in [403] and not self.no_transcoding:
# try downloading via transcode
self.logger.warning('trying download via transcoding.')
status = self.download(url=video.getStreamURL(), path=path, filename=filename, title=video.title, resume=False)
Expand Down Expand Up @@ -143,8 +143,8 @@ def download(self, url: str, path: str, filename: str, title: str, resume: bool
os.unlink(path + "/." + filename)
except FileNotFoundError:
pass
file_id = open(path + "/." + filename, "wb")

file_id = open(path + "/." + filename, "xb")
self.curl.setopt(self.curl.RESUME_FROM, 0)
self.curl.setopt(self.curl.WRITEDATA, file_id)
self.logger.debug(f'timeout: {self.timeout}')
self.curl.setopt(self.curl.TIMEOUT, self.timeout)
Expand All @@ -158,7 +158,10 @@ def download(self, url: str, path: str, filename: str, title: str, resume: bool
try:
self.curl.perform()
except pycurl.error as e:
self.logger.warning(e.args[1])
self.logger.warning(f"{e.args[0]} {e.args[1]}")
if e.args[0] == 33 and resume is True:
self.logger.warning("server doesn't support resume, therefore retrying without.")
return self.download(url=url, path=path, filename=filename, title=title, resume=False)
return e.args[0]
response_code = self.curl.getinfo(self.curl.RESPONSE_CODE)
self.progressbar.clear()
Expand Down

0 comments on commit 74b8143

Please sign in to comment.