def run(self): self.start_time = time.time() self.last_update = self.start_time try: # Get file size response = requests.head(self.task.url) total_size = int(response.headers.get('content-length', 0)) self.task.total_size = total_size # Calculate chunk size chunk_size = total_size // self.task.threads self.chunks = [] for i in range(self.task.threads): start = i * chunk_size end = start + chunk_size - 1 if i < self.task.threads - 1 else total_size - 1 self.chunks.append(DownloadChunk(start, end, i)) # Resume from existing file filepath = os.path.join(self.task.save_path, self.task.filename) temp_filepath = filepath + '.eagleget' if os.path.exists(temp_filepath): self.resume_from_temp(temp_filepath) # Start downloading chunks threads = [] for chunk in self.chunks: if chunk.start > chunk.end: continue t = threading.Thread(target=self.download_chunk, args=(chunk,)) t.start() threads.append(t) # Monitor progress while not self.stopped: if self.paused: time.sleep(1) continue with self.lock: downloaded = sum(chunk.downloaded for chunk in self.chunks) self.task.downloaded_size = downloaded # Update speed now = time.time() time_diff = now - self.last_update if time_diff > 0: speed = (downloaded - self.last_downloaded) / time_diff self.task.speed = speed self.last_update = now self.last_downloaded = downloaded # Check if download completed if downloaded >= self.task.total_size: self.complete_download() break time.sleep(0.5) # Wait for all threads for t in threads: t.join() except Exception as e: self.task.status = DownloadStatus.FAILED print(f"Download failed: e")
import sys import os from PyQt5.QtWidgets import * from PyQt5.QtCore import * from PyQt5.QtGui import * from src.download_manager import DownloadManager, DownloadStatus eagleget for linux
def pause(self): self.paused = True
def load_tasks(self): conn = sqlite3.connect(self.db_path) cursor = conn.cursor() cursor.execute('SELECT * FROM downloads') for row in cursor.fetchall(): task = DownloadTask( id=row[0], url=row[1], filename=row[2], save_path=row[3], total_size=row[4], downloaded_size=row[5], status=DownloadStatus(row[6]), threads=row[7], speed=row[8], created_at=datetime.fromisoformat(row[9]), completed_at=datetime.fromisoformat(row[10]) if row[10] else None, md5=row[11] ) self.tasks[task.id] = task conn.close() def run(self): self
import threading import requests import os import time from typing import List from download_manager import DownloadTask, DownloadStatus class DownloadChunk: def (self, start: int, end: int, thread_id: int): self.start = start self.end = end self.thread_id = thread_id self.downloaded = 0 DownloadStatus class DownloadChunk: def (self
def update_progress(self): self.model.refresh() stats = self.manager.get_statistics() self.status_label.setText( f"Total: stats['total'] | " f"Downloading: stats['downloading'] | " f"Completed: stats['completed'] | " f"Size: self.format_size(stats['downloaded_size']) / self.format_size(stats['total_size'])" )