Update backend.py

Added 5 retries for files that randomly end being only 3kb's in size.
This commit is contained in:
Arctic4161 2021-10-14 16:39:16 -05:00 committed by GitHub
parent bda3ead826
commit d1348cbd95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -100,11 +100,45 @@ class Download:
def download_episodes(self, url): def download_episodes(self, url):
client = req.session() client = req.session()
with client.get(url[1], headers=self.random_headers(), stream=True, timeout=10) as workingurl: while True:
episode_name = "EP." + url[0] + ".mp4" with client.get(url[1], headers=self.random_headers(), stream=True, timeout=10) as workingurl:
file_loc = os.path.join(self.folder, episode_name) episode_name = "EP." + url[0] + ".mp4"
with open(file_loc, "w+b") as file: file_loc = os.path.join(self.folder, episode_name)
shutil.copyfileobj(workingurl.raw, file, 8192) with open(file_loc, "w+b") as file:
shutil.copyfileobj(workingurl.raw, file)
size = os.stat(file_loc).st_size
if int(size) < 5:
with client.get(url[1], headers=self.random_headers(), stream=True, timeout=10) as workingurl:
episode_name = "EP." + url[0] + ".mp4"
file_loc = os.path.join(self.folder, episode_name)
with open(file_loc, "w+b") as file:
shutil.copyfileobj(workingurl.raw, file)
size = os.stat(file_loc).st_size
if int(size) < 5:
with client.get(url[1], headers=self.random_headers(), stream=True, timeout=10) as workingurl:
episode_name = "EP." + url[0] + ".mp4"
file_loc = os.path.join(self.folder, episode_name)
with open(file_loc, "w+b") as file:
shutil.copyfileobj(workingurl.raw, file)
size = os.stat(file_loc).st_size
if int(size) < 5:
with client.get(url[1], headers=self.random_headers(), stream=True, timeout=10) as workingurl:
episode_name = "EP." + url[0] + ".mp4"
file_loc = os.path.join(self.folder, episode_name)
with open(file_loc, "w+b") as file:
shutil.copyfileobj(workingurl.raw, file)
size = os.stat(file_loc).st_size
if int(size) < 5:
with client.get(url[1], headers=self.random_headers(), stream=True, timeout=10) as workingurl:
episode_name = "EP." + url[0] + ".mp4"
file_loc = os.path.join(self.folder, episode_name)
with open(file_loc, "w+b") as file:
shutil.copyfileobj(workingurl.raw, file)
break
@dataclass(init=True) @dataclass(init=True)
@ -126,3 +160,4 @@ class CustomMessage(Exception):
print( print(
f"{Fore.RESET}[{Fore.GREEN}+{Fore.RESET}] Using {Fore.LIGHTCYAN_EX}{self.episode_quality}{Fore.RESET} as a default quality." f"{Fore.RESET}[{Fore.GREEN}+{Fore.RESET}] Using {Fore.LIGHTCYAN_EX}{self.episode_quality}{Fore.RESET} as a default quality."
) )