mirror of
https://github.com/SubtitleEdit/subtitleedit.git
synced 2024-11-22 03:02:35 +01:00
Refactor progress report in WhisperModelDownload
This commit optimizes the code in WhisperModelDownload.cs by pulling out the progress reporting into a separate variable. This new implementation enhances code readability and prevents code redundancy. Now, the 'progressReport' variable is used while calling the 'DownloadAsync' method. Signed-off-by: Ivandro Jao <ivandrofly@gmail.com>
This commit is contained in:
parent
9d9f55de68
commit
8179cee693
@ -103,6 +103,11 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
}
|
||||
}
|
||||
|
||||
var progressReport = new Progress<float>((progress) =>
|
||||
{
|
||||
var pct = (int)Math.Round(progress * 100.0, MidpointRounding.AwayFromZero);
|
||||
labelPleaseWait.Text = LanguageSettings.Current.General.PleaseWait + " " + pct + "%";
|
||||
});
|
||||
foreach (var url in LastDownloadedModel.Urls)
|
||||
{
|
||||
using (var httpClient = DownloaderFactory.MakeHttpClient())
|
||||
@ -112,11 +117,8 @@ namespace Nikse.SubtitleEdit.Forms.AudioToText
|
||||
labelFileName.Text = url.Split('/').Last();
|
||||
using (var downloadStream = new FileStream(_downloadFileName, FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
var downloadTask = httpClient.DownloadAsync(url, downloadStream, new Progress<float>((progress) =>
|
||||
{
|
||||
var pct = (int)Math.Round(progress * 100.0, MidpointRounding.AwayFromZero);
|
||||
labelPleaseWait.Text = LanguageSettings.Current.General.PleaseWait + " " + pct + "%";
|
||||
}), _cancellationTokenSource.Token);
|
||||
var downloadTask = httpClient.DownloadAsync(url, downloadStream, progressReport,
|
||||
_cancellationTokenSource.Token);
|
||||
|
||||
while (!downloadTask.IsCompleted && !downloadTask.IsCanceled)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user