Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skipped stats #36

Merged
merged 1 commit into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions downloader/downloader.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ func (d *Downloader) createImage(item *LibraryItem, filePath string) error {
})
} else {
log.Printf("Skipping '%v' [saved as '%v']", item.Filename, item.UsedFileName)
d.stats.UpdateStatsSkipped(1)
}
return nil
}
Expand Down Expand Up @@ -331,11 +332,11 @@ func (d *Downloader) DownloadAll(svc *photoslibrary.Service) error {
}

if hasMore {
log.Printf("Processed: %v, Downloaded: %v, Errors: %v, Total Size: %v", d.stats.Total, d.stats.Downloaded, d.stats.Errors, humanize.Bytes(d.stats.TotalSize))
log.Printf("Processed: %v, Downloaded: %v, Skipped: %v, Errors: %v, Total Size: %v", d.stats.Total, d.stats.Downloaded, d.stats.Skipped, d.stats.Errors, humanize.Bytes(d.stats.TotalSize))
time.Sleep(sleepTime)
}
}

log.Printf("Finished: %v, Downloaded: %v, Errors: %v, Total Size: %v", d.stats.Total, d.stats.Downloaded, d.stats.Errors, humanize.Bytes(d.stats.TotalSize))
log.Printf("Finished: %v, Downloaded: %v, Skipped: %v, Errors: %v, Total Size: %v", d.stats.Total, d.stats.Downloaded, d.stats.Skipped, d.stats.Errors, humanize.Bytes(d.stats.TotalSize))
return nil
}
23 changes: 16 additions & 7 deletions downloader/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,24 @@ import (

// Stats TODO
type Stats struct {
Total int
Errors int
TotalSize uint64
Total int
Errors int
TotalSize uint64
Downloaded int
Skipped int

mutex sync.Mutex
}

// UpdateStatsTotal TODO
// UpdateStatsTotal increment the total items
func (s *Stats) UpdateStatsTotal(total int) {
s.mutex.Lock()
defer s.mutex.Unlock()

s.Total += total
}

// UpdateStatsDownloaded TODO
// UpdateStatsDownloaded increment the downloaded items and size of items
func (s *Stats) UpdateStatsDownloaded(totalSize uint64, downloaded int) {
s.mutex.Lock()
defer s.mutex.Unlock()
Expand All @@ -31,10 +32,18 @@ func (s *Stats) UpdateStatsDownloaded(totalSize uint64, downloaded int) {
s.Downloaded += downloaded
}

// UpdateStatsError TODO
// UpdateStatsError increment the items that produced errors
func (s *Stats) UpdateStatsError(errors int) {
s.mutex.Lock()
defer s.mutex.Unlock()

s.Errors += errors
}
}

// UpdateStatsError increment the skipped items
func (s *Stats) UpdateStatsSkipped(skipped int) {
s.mutex.Lock()
defer s.mutex.Unlock()

s.Skipped += skipped
}