mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-02 12:26:36 +08:00
feat: report STRM tree batch progress
This commit is contained in:
@@ -25,15 +25,18 @@ type GenerateSTRMOptions struct {
|
||||
}
|
||||
|
||||
type GenerateSTRMResult struct {
|
||||
LibraryID string `json:"library_id"`
|
||||
OutputDir string `json:"output_dir"`
|
||||
Generated int `json:"generated"`
|
||||
Updated int `json:"updated"`
|
||||
Skipped int `json:"skipped"`
|
||||
Cleaned int `json:"cleaned"`
|
||||
Previewed int `json:"previewed,omitempty"`
|
||||
Errors []string `json:"errors,omitempty"`
|
||||
Items []GenerateSTRMItem `json:"items,omitempty"`
|
||||
LibraryID string `json:"library_id"`
|
||||
OutputDir string `json:"output_dir"`
|
||||
Generated int `json:"generated"`
|
||||
Updated int `json:"updated"`
|
||||
Skipped int `json:"skipped"`
|
||||
Cleaned int `json:"cleaned"`
|
||||
Total int `json:"total,omitempty"`
|
||||
Remaining int `json:"remaining,omitempty"`
|
||||
BatchLimited bool `json:"batch_limited,omitempty"`
|
||||
Previewed int `json:"previewed,omitempty"`
|
||||
Errors []string `json:"errors,omitempty"`
|
||||
Items []GenerateSTRMItem `json:"items,omitempty"`
|
||||
}
|
||||
|
||||
type GenerateSTRMItem struct {
|
||||
|
||||
@@ -44,8 +44,10 @@ func (s *STRMService) GenerateFromTree(ctx context.Context, opts GenerateSTRMTre
|
||||
}
|
||||
}
|
||||
result := &GenerateSTRMResult{LibraryID: provider, OutputDir: outputDir}
|
||||
sources := collectSTRMTreeSources(opts)
|
||||
result.Total = len(sources)
|
||||
expectedFiles := make(map[string]struct{})
|
||||
for _, source := range collectSTRMTreeSources(opts) {
|
||||
for i, source := range sources {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return result, ctx.Err()
|
||||
@@ -57,6 +59,8 @@ func (s *STRMService) GenerateFromTree(ctx context.Context, opts GenerateSTRMTre
|
||||
}
|
||||
result.addItem(item)
|
||||
if strmTreeBatchLimitReached(result, opts.BatchLimit) {
|
||||
result.Remaining = len(sources) - i - 1
|
||||
result.BatchLimited = result.Remaining > 0
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,6 +155,9 @@ func TestGenerateSTRMFromTreeBatchLimitContinuesAfterExistingFiles(t *testing.T)
|
||||
if first.Generated != 2 || first.Skipped != 0 {
|
||||
t.Fatalf("first batch = %#v, want two generated", first)
|
||||
}
|
||||
if first.Total != 3 || first.Remaining != 1 || !first.BatchLimited {
|
||||
t.Fatalf("first batch progress = total %d remaining %d limited %v, want 3/1/true", first.Total, first.Remaining, first.BatchLimited)
|
||||
}
|
||||
if _, err := os.Stat(filepath.Join(outDir, "Movies", "C.strm")); !os.IsNotExist(err) {
|
||||
t.Fatalf("first batch should not write third item, stat err=%v", err)
|
||||
}
|
||||
@@ -166,6 +169,9 @@ func TestGenerateSTRMFromTreeBatchLimitContinuesAfterExistingFiles(t *testing.T)
|
||||
if second.Generated != 1 || second.Skipped != 2 {
|
||||
t.Fatalf("second batch = %#v, want two existing skips then next generated", second)
|
||||
}
|
||||
if second.Total != 3 || second.Remaining != 0 || second.BatchLimited {
|
||||
t.Fatalf("second batch progress = total %d remaining %d limited %v, want 3/0/false", second.Total, second.Remaining, second.BatchLimited)
|
||||
}
|
||||
if got := readSTRM(t, filepath.Join(outDir, "Movies", "C.strm")); !strings.Contains(got, "C.mkv") {
|
||||
t.Fatalf("second batch C.strm = %q, want generated third item", got)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user