Thu, 17 Apr 2008 17:54:48 +0200 <thp@perli.net>

Calculate total percentage based on byte size instead of percentage

	* src/gpodder/download.py: Make sure we save the right size of a
	currently in-progress download of an episode
	* src/gpodder/services.py: Calculate the total percentage for all
	episodes based on their file size instead of their percentage done;
	this is especially important when downloading small files mixed with
	large files; this makes the estimated download time more reliable;
	thanks to Jérôme Chabod, who has done this patch
	(Closes: http://bugs.gpodder.org/show_bug.cgi?id=46)



git-svn-id: svn://svn.berlios.de/gpodder/trunk@675 b0d088ad-0a06-0410-aad2-9ed5178a7e87
This commit is contained in:
Thomas Perl 2008-04-17 15:59:38 +00:00
parent d3d7adf099
commit 2f6c16e636
3 changed files with 27 additions and 6 deletions

View File

@ -1,3 +1,15 @@
Thu, 17 Apr 2008 17:54:48 +0200 <thp@perli.net>
Calculate total percentage based on byte size instead of percentage
* src/gpodder/download.py: Make sure we save the right size of a
currently in-progress download of an episode
* src/gpodder/services.py: Calculate the total percentage for all
episodes based on their file size instead of their percentage done;
this is especially important when downloading small files mixed with
large files; this makes the estimated download time more reliable;
thanks to Jérôme Chabod, who has done this patch
(Closes: http://bugs.gpodder.org/show_bug.cgi?id=46)
Thu, 17 Apr 2008 17:42:31 +0200 <thp@perli.net>
Clean up preferences dialog + Move download settings to downloads tab

View File

@ -82,6 +82,9 @@ class DownloadThread(threading.Thread):
self.filename = self.episode.local_filename()
self.tempname = os.path.join( os.path.dirname( self.filename), '.tmp-' + os.path.basename( self.filename))
# Make an educated guess about the total file size
self.total_size = self.episode.length
self.cancelled = False
self.start_time = 0.0
self.speed = _('Queued')
@ -100,6 +103,11 @@ class DownloadThread(threading.Thread):
def status_updated( self, count, blockSize, totalSize):
if totalSize:
self.progress = 100.0*float(count*blockSize)/float(totalSize)
# We see a different "total size" while downloading,
# so correct the total size variable in the thread
if totalSize != self.total_size:
log('Correcting file size for %s from %d to %d while downloading.', self.url, self.total_size, totalSize, sender=self)
self.total_size = totalSize
else:
self.progress = 100.0

View File

@ -78,7 +78,7 @@ class DownloadStatusManager(ObservableService):
self.last_progress_status = ( 0, 0 )
# use to correctly calculate percentage done
self.downloads_done_count = 0
self.downloads_done_bytes = 0
self.max_downloads = gl.config.max_downloads
self.semaphore = threading.Semaphore( self.max_downloads)
@ -172,7 +172,7 @@ class DownloadStatusManager(ObservableService):
del self.status_list[id]
if not self.has_items():
# Reset the counter now
self.downloads_done_count = 0
self.downloads_done_bytes = 0
self.notify( 'list-changed')
self.notify_progress()
@ -186,8 +186,9 @@ class DownloadStatusManager(ObservableService):
if not len(self.status_list):
return 0
done = self.downloads_done_count*100 + sum([status['progress'] for status in self.status_list.values()])
return done / (len(self.status_list) + self.downloads_done_count)
done = sum(status['progress']/100. * status['thread'].total_size for status in self.status_list.values())
total = sum(status['thread'].total_size for status in self.status_list.values())
return float(done + self.downloads_done_bytes) / float(total + self.downloads_done_bytes) * 100
def update_status( self, id, **kwargs):
if not id in self.status_list:
@ -210,7 +211,7 @@ class DownloadStatusManager(ObservableService):
def download_completed(self, id):
if id in self.status_list:
self.notify('download-complete', self.status_list[id]['episode'])
self.downloads_done_count += 1
self.downloads_done_bytes += self.status_list[id]['thread'].total_size
def request_progress_detail( self, url):
for status in self.status_list.values():
@ -231,7 +232,7 @@ class DownloadStatusManager(ObservableService):
self.status_list[element]['thread'].cancel()
# clear the tree model after cancelling
util.idle_add(self.tree_model.clear)
self.downloads_done_count = 0
self.downloads_done_bytes = 0
def cancel_by_url( self, url):
for element in self.status_list: