/
runner_executor_scan.go
77 lines (65 loc) · 1.91 KB
/
runner_executor_scan.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package backup
import (
log "github.com/sirupsen/logrus"
"sort"
)
func newScanReceiver(mdc *log.Entry, volume SourceVolume) *scanReceiver {
return &scanReceiver{
mdc: mdc,
volume: volume,
albums: make(map[string]*ScannedFolder),
}
}
type scanReceiver struct {
mdc *log.Entry
volume SourceVolume
albums map[string]*ScannedFolder
rejects []FoundMedia
}
func (s *scanReceiver) receive(buffer []*BackingUpMediaRequest, progressChannel chan *ProgressEvent) error {
for _, media := range buffer {
foundMedia := media.AnalysedMedia.FoundMedia
if media.AnalysedMedia.Details.DateTime.IsZero() {
log.Warnf("Media timestamp cannot be found within the file %s", foundMedia)
s.rejects = append(s.rejects, foundMedia)
} else {
mediaPath := foundMedia.MediaPath()
if _, ok := s.albums[mediaPath.Path]; !ok {
s.albums[mediaPath.Path] = s.newFoundAlbum(mediaPath)
}
s.albums[mediaPath.Path].PushBoundaries(media.AnalysedMedia.Details.DateTime, foundMedia.Size())
}
progressChannel <- &ProgressEvent{
Type: ProgressEventUploaded,
Count: 1,
Size: foundMedia.Size(),
Album: media.FolderName,
MediaType: media.AnalysedMedia.Type,
}
}
return nil
}
func (s *scanReceiver) collect() []*ScannedFolder {
suggestions := make([]*ScannedFolder, len(s.albums))
i := 0
for _, album := range s.albums {
suggestions[i] = album
i++
}
sort.Slice(suggestions, func(i, j int) bool {
if suggestions[i].Start != suggestions[j].Start {
return suggestions[i].Start.Before(suggestions[j].Start)
}
return suggestions[i].End.Before(suggestions[j].End)
})
return suggestions
}
func (s *scanReceiver) newFoundAlbum(mediaPath MediaPath) *ScannedFolder {
return &ScannedFolder{
Name: mediaPath.ParentDir,
RelativePath: mediaPath.Path,
FolderName: mediaPath.ParentDir,
AbsolutePath: mediaPath.ParentFullPath,
Distribution: make(map[string]MediaCounter),
}
}