Add downloading message to home screen.
Download files in the background and keep track of progress.
This commit is contained in:
@@ -30,6 +30,7 @@ func DownloadAudioFiles(progressChan chan<- DownloadStatus, filenames []string,
|
||||
// First, calculate the total size of files that need to be downloaded
|
||||
totalSize := int64(0)
|
||||
filesToDownload := []string{}
|
||||
totalDownloaded := int64(0)
|
||||
|
||||
for _, filename := range filenames {
|
||||
destPath := filepath.Join(destDir, filename)
|
||||
@@ -62,13 +63,15 @@ func DownloadAudioFiles(progressChan chan<- DownloadStatus, filenames []string,
|
||||
|
||||
// Append it to the list to download
|
||||
filesToDownload = append(filesToDownload, filename)
|
||||
// And increase the total bytes to download
|
||||
totalSize += resp.ContentLength
|
||||
} else if err != nil {
|
||||
logger.Error("unknown error: %v", err)
|
||||
} else {
|
||||
logger.Error("File %s exists, skipping...", filename)
|
||||
totalDownloaded += fileStat.Size()
|
||||
}
|
||||
// Calculate the total of ALL files to give the illusion of
|
||||
// "picking up where you left off" to the user
|
||||
totalSize += resp.ContentLength
|
||||
resp.Body.Close()
|
||||
}
|
||||
|
||||
@@ -79,8 +82,6 @@ func DownloadAudioFiles(progressChan chan<- DownloadStatus, filenames []string,
|
||||
Msg: "Starting download...",
|
||||
}
|
||||
|
||||
totalDownloaded := int64(0)
|
||||
|
||||
// Download each file that doesn't exist
|
||||
for _, filename := range filesToDownload {
|
||||
url := urlBase + filename
|
||||
|
||||
Reference in New Issue
Block a user