mirror of
				https://github.com/devine-dl/devine.git
				synced 2025-11-04 03:44:49 +00:00 
			
		
		
		
	Add missing while loop to Requests downloader
This commit is contained in:
		
							parent
							
								
									2056e056a4
								
							
						
					
					
						commit
						172ab64017
					
				@ -67,40 +67,41 @@ def requests(
 | 
			
		||||
        out_path.parent.mkdir(parents=True, exist_ok=True)
 | 
			
		||||
        attempts = 1
 | 
			
		||||
 | 
			
		||||
        try:
 | 
			
		||||
            stream = session.get(url, stream=True)
 | 
			
		||||
            stream.raise_for_status()
 | 
			
		||||
        while True:
 | 
			
		||||
            try:
 | 
			
		||||
                stream = session.get(url, stream=True)
 | 
			
		||||
                stream.raise_for_status()
 | 
			
		||||
 | 
			
		||||
            if len(uri) == 1 and progress:
 | 
			
		||||
                content_length = int(stream.headers.get("Content-Length", "0"))
 | 
			
		||||
                if content_length > 0:
 | 
			
		||||
                    progress(total=math.ceil(content_length / 1024))
 | 
			
		||||
                if len(uri) == 1 and progress:
 | 
			
		||||
                    content_length = int(stream.headers.get("Content-Length", "0"))
 | 
			
		||||
                    if content_length > 0:
 | 
			
		||||
                        progress(total=math.ceil(content_length / 1024))
 | 
			
		||||
 | 
			
		||||
            with open(out_path, "wb") as f:
 | 
			
		||||
                written = 0
 | 
			
		||||
                for chunk in stream.iter_content(chunk_size=1024):
 | 
			
		||||
                    download_size = len(chunk)
 | 
			
		||||
                    f.write(chunk)
 | 
			
		||||
                    written += download_size
 | 
			
		||||
                    if progress:
 | 
			
		||||
                        progress(advance=1)
 | 
			
		||||
                with open(out_path, "wb") as f:
 | 
			
		||||
                    written = 0
 | 
			
		||||
                    for chunk in stream.iter_content(chunk_size=1024):
 | 
			
		||||
                        download_size = len(chunk)
 | 
			
		||||
                        f.write(chunk)
 | 
			
		||||
                        written += download_size
 | 
			
		||||
                        if progress:
 | 
			
		||||
                            progress(advance=1)
 | 
			
		||||
 | 
			
		||||
                        now = time.time()
 | 
			
		||||
                        time_since = now - last_speed_refresh
 | 
			
		||||
                            now = time.time()
 | 
			
		||||
                            time_since = now - last_speed_refresh
 | 
			
		||||
 | 
			
		||||
                        download_sizes.append(download_size)
 | 
			
		||||
                        if time_since > 5 or download_size < 1024:
 | 
			
		||||
                            data_size = sum(download_sizes)
 | 
			
		||||
                            download_speed = data_size / (time_since or 1)
 | 
			
		||||
                            progress(downloaded=f"{filesize.decimal(download_speed)}/s")
 | 
			
		||||
                            last_speed_refresh = now
 | 
			
		||||
                            download_sizes.clear()
 | 
			
		||||
            break
 | 
			
		||||
        except Exception as e:
 | 
			
		||||
            if DOWNLOAD_CANCELLED.is_set() or attempts == MAX_ATTEMPTS:
 | 
			
		||||
                raise e
 | 
			
		||||
            time.sleep(RETRY_WAIT)
 | 
			
		||||
            attempts += 1
 | 
			
		||||
                            download_sizes.append(download_size)
 | 
			
		||||
                            if time_since > 5 or download_size < 1024:
 | 
			
		||||
                                data_size = sum(download_sizes)
 | 
			
		||||
                                download_speed = data_size / (time_since or 1)
 | 
			
		||||
                                progress(downloaded=f"{filesize.decimal(download_speed)}/s")
 | 
			
		||||
                                last_speed_refresh = now
 | 
			
		||||
                                download_sizes.clear()
 | 
			
		||||
                break
 | 
			
		||||
            except Exception as e:
 | 
			
		||||
                if DOWNLOAD_CANCELLED.is_set() or attempts == MAX_ATTEMPTS:
 | 
			
		||||
                    raise e
 | 
			
		||||
                time.sleep(RETRY_WAIT)
 | 
			
		||||
                attempts += 1
 | 
			
		||||
 | 
			
		||||
    return 0
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user