Repository navigation
Expand file tree
/
Copy pathmain.go
More file actions
694 lines (627 loc) · 20.2 KB
/
Copy pathmain.go
File metadata and controls
694 lines (627 loc) · 20.2 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
package main
import (
"context"
"fmt"
"normalize_video/config"
"normalize_video/files"
"normalize_video/service"
"normalize_video/service/mkvmetadata"
"normalize_video/types"
"os"
"os/signal"
"path/filepath"
"strings"
"sync"
"syscall"
"time"
"github.com/k0kubun/pp"
)
// printMu serializes the per-file result blocks so parallel workers do not
// interleave their tables. Single-line progress logs stay unserialized.
var printMu sync.Mutex
// dedupIndex maps content fingerprints to library paths; nil unless -dedup.
var dedupIndex *service.DedupIndex
func main() {
config.ParseFlags()
if err := service.OpenJournal(config.JOURNAL_PATH); err != nil {
pp.Printf("Error opening journal %s: %v\n", config.JOURNAL_PATH, err)
os.Exit(1)
}
defer service.CloseJournal()
if config.DEDUP {
idx, err := service.LoadDedupIndex(filepath.Join(config.DEST_PATH, ".normalize_fingerprints.jsonl"))
if err != nil {
pp.Printf("Error loading dedup index: %v\n", err)
os.Exit(1)
}
dedupIndex = idx
}
if config.DRY_RUN {
pp.Println("DRY RUN: showing the plan, nothing will be modified")
pp.Println("________________________________________________________________________________")
}
start := time.Now()
var stats ProcessStats
if config.WATCH {
stats = watchLoop()
} else {
stats = processWithStreaming()
runCleanup(&stats)
}
printStats(stats, time.Since(start))
}
func processWithStreaming() ProcessStats {
videoChan := make(chan string, 100)
var scanErr error
var scanWg sync.WaitGroup
scanWg.Add(1)
go func() {
defer scanWg.Done()
scanErr = service.ScanVideoFilesStream(
config.ORIGIN_PATH,
config.RECURSIVE_SCAN,
config.Extensions,
videoChan,
)
}()
stats := newProcessStats()
var processWg sync.WaitGroup
var mu sync.Mutex
workerJobs := make(chan *types.Video, config.MAX_WORKERS)
for i := 0; i < config.MAX_WORKERS; i++ {
processWg.Add(1)
go func() {
defer processWg.Done()
for video := range workerJobs {
res, err := processVideo(video)
collectResult(&stats, &mu, video, res, err)
}
}()
}
go func() {
for path := range videoChan {
workerJobs <- newVideoFromPath(path)
}
close(workerJobs)
}()
scanWg.Wait()
if scanErr != nil {
pp.Printf("Scan error: %v\n", scanErr)
}
processWg.Wait()
return stats
}
// watchLoop rescans ORIGIN_PATH periodically and processes a file once its
// size and mtime are stable between two scans (download finished). Polling on
// purpose: inotify does not fire for Windows-side writes on WSL /mnt/* drvfs
// mounts. Ctrl+C stops cleanly and prints the totals.
func watchLoop() ProcessStats {
stats := newProcessStats()
var mu sync.Mutex
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
jobs := make(chan *types.Video)
var wg sync.WaitGroup
for i := 0; i < config.MAX_WORKERS; i++ {
wg.Add(1)
go func() {
defer wg.Done()
for video := range jobs {
res, err := processVideo(video)
collectResult(&stats, &mu, video, res, err)
}
}()
}
type fileState struct {
size int64
mod time.Time
}
pending := map[string]fileState{}
handled := map[string]bool{}
interval := time.Duration(config.WATCH_INTERVAL_SECONDS) * time.Second
pp.Println(fmt.Sprintf("Watching %s every %ds (Ctrl+C to stop)", config.ORIGIN_PATH, config.WATCH_INTERVAL_SECONDS))
for {
paths, err := service.ScanVideoFiles(config.ORIGIN_PATH, config.RECURSIVE_SCAN, config.Extensions)
if err != nil {
pp.Printf("Scan error: %v\n", err)
}
current := map[string]bool{}
for _, path := range paths {
current[path] = true
if handled[path] {
continue
}
st, err := os.Stat(path)
if err != nil {
continue
}
prev, seen := pending[path]
if seen && prev.size == st.Size() && prev.mod.Equal(st.ModTime()) {
handled[path] = true
delete(pending, path)
select {
case jobs <- newVideoFromPath(path):
case <-ctx.Done():
}
} else {
pending[path] = fileState{st.Size(), st.ModTime()}
if !seen {
pp.Printf(" %s: waiting for a stable size...\n", filepath.Base(path))
}
}
}
// files gone from the scan were moved away: forget them
for p := range handled {
if !current[p] {
delete(handled, p)
}
}
for p := range pending {
if !current[p] {
delete(pending, p)
}
}
mu.Lock()
runCleanup(&stats)
mu.Unlock()
select {
case <-ctx.Done():
close(jobs)
wg.Wait()
mu.Lock()
runCleanup(&stats)
mu.Unlock()
return stats
case <-time.After(interval):
}
}
}
func newVideoFromPath(path string) *types.Video {
filename := strings.ToLower(filepath.Base(path))
filenameParts := service.SplitFilename(filename)
extension := filenameParts[len(filenameParts)-1]
return files.NewVideo(filename, filenameParts, path, extension)
}
type ProcessStats struct {
MoviesCount int
SeriesCount int
SeekIndexRepaired int
DamageRepaired int
Retimed int
SubtitlesMerged int
Converted int
Skipped int
Hashed int
Salvaged int
Duplicates int
JunkRemoved int
DirsRemoved int
Errors []error
sourceDirs map[string]bool
plannedGone map[string]bool
}
func newProcessStats() ProcessStats {
return ProcessStats{sourceDirs: map[string]bool{}, plannedGone: map[string]bool{}}
}
type mediaResult struct {
SeekIndexRepaired bool
DamageRepaired bool
Retimed bool
SubtitlesMerged int
Converted bool
Skipped bool
Hashed bool
Salvaged bool
Duplicate bool
SourceDir string
// PlannedGone lists files a dry-run pretends were moved/consumed, so the
// cleanup preview matches what a real run would leave behind
PlannedGone []string
}
func collectResult(stats *ProcessStats, mu *sync.Mutex, video *types.Video, res mediaResult, err error) {
mu.Lock()
defer mu.Unlock()
switch {
case err != nil:
stats.Errors = append(stats.Errors, err)
service.Journal("move", video.OriginPath, "", "failed", err.Error())
case res.Skipped:
stats.Skipped++
default:
if video.Type == "Serie" {
stats.SeriesCount++
} else {
stats.MoviesCount++
}
if res.SourceDir != "" {
stats.sourceDirs[res.SourceDir] = true
}
for _, p := range res.PlannedGone {
stats.plannedGone[p] = true
}
}
if res.SeekIndexRepaired {
stats.SeekIndexRepaired++
}
if res.DamageRepaired {
stats.DamageRepaired++
}
if res.Retimed {
stats.Retimed++
}
if res.Converted {
stats.Converted++
}
if res.Hashed {
stats.Hashed++
}
if res.Salvaged {
stats.Salvaged++
}
if res.Duplicate {
stats.Duplicates++
}
stats.SubtitlesMerged += res.SubtitlesMerged
}
// runCleanup sweeps the source dirs of processed videos. Caller holds the
// stats lock in watch mode; batch mode calls it after all workers stopped.
func runCleanup(stats *ProcessStats) {
if !config.CLEANUP_SOURCE {
return
}
for dir := range stats.sourceDirs {
res, err := service.CleanupSourceDir(dir, config.ORIGIN_PATH, config.Extensions, config.DRY_RUN, stats.plannedGone)
if err != nil {
pp.Printf("Warning: cleanup failed for %s: %v\n", dir, err)
continue
}
delete(stats.sourceDirs, dir)
if len(res.JunkRemoved) == 0 && len(res.DirsRemoved) == 0 {
continue
}
stats.JunkRemoved += len(res.JunkRemoved)
stats.DirsRemoved += len(res.DirsRemoved)
status := "done"
if config.DRY_RUN {
status = "planned"
}
service.Journal("cleanup", dir, "", status,
fmt.Sprintf("%d junk file(s), %d dir(s)", len(res.JunkRemoved), len(res.DirsRemoved)))
for _, f := range res.JunkRemoved {
pp.Printf(" cleanup: %s\n", f)
}
}
}
func processVideo(video *types.Video) (mediaResult, error) {
var media types.Normalizable
if video.Type == "Serie" {
media = files.NewSerie(video)
} else {
media = files.NewMovie(video)
}
return processMedia(media)
}
func processMedia(media types.Normalizable) (mediaResult, error) {
var res mediaResult
video := media.GetVideo()
originPath := video.OriginPath
newPath := media.GetNormalizer().NewPath
extension := strings.ToLower(video.Extension)
res.SourceDir = filepath.Dir(originPath)
pp.Printf("-> %s\n", filepath.Base(originPath))
convert := config.CONVERT_MP4 && config.MP4Convertible[extension]
plainNewPath := newPath
if convert {
newPath = strings.TrimSuffix(newPath, filepath.Ext(newPath)) + ".mkv"
media.SetNewPath(newPath)
extension = "mkv"
}
if config.ON_COLLISION != "" {
resolved, skip := service.ResolveCollision(newPath, config.ON_COLLISION)
if skip {
pp.Printf(" %s: destination exists, skipped\n", filepath.Base(newPath))
service.Journal("collision", originPath, newPath, "skipped", "destination exists")
res.Skipped = true
return res, nil
}
if resolved != newPath {
service.Journal("collision", originPath, newPath, "suffixed", resolved)
newPath = resolved
media.SetNewPath(newPath)
}
}
if config.DRY_RUN {
return dryRunMedia(media, originPath, newPath, extension, convert)
}
ctx := context.Background()
if convert {
// A truncated or moov-less source has nothing a remux could carry
// over cleanly: skip the conversion outright, the plain-move path
// below lands it as-is and the mkvgo triage puts the re-download
// verdict on the table. That refusal is a decision, not a failure -
// the journal says so, so a reader can tell it from a broken remux.
convErr := error(nil)
convStatus := "failed"
if verdict := mkvmetadata.ConvertBlocker(ctx, originPath); verdict != "" {
convErr = fmt.Errorf("unconvertible source (%s)", verdict)
convStatus = "skipped"
} else {
convErr = mkvmetadata.ConvertToMkv(ctx, originPath, newPath)
}
if err := convErr; err != nil {
pp.Printf("Warning: MP4 conversion skipped for %s, moving as-is: %v\n", filepath.Base(originPath), err)
service.Journal("convert", originPath, newPath, convStatus, err.Error())
// fall back to a plain move under the original extension
convert = false
extension = strings.ToLower(video.Extension)
newPath, res.Skipped = service.ResolveCollision(plainNewPath, config.ON_COLLISION)
if res.Skipped {
return res, nil
}
media.SetNewPath(newPath)
if err := service.MoveFile(originPath, newPath); err != nil {
return res, fmt.Errorf("move file error for %s: %w", filepath.Base(originPath), err)
}
service.Journal("move", originPath, newPath, "done", "")
} else {
res.Converted = true
service.Journal("convert", originPath, newPath, "done", "remux to mkv")
}
} else {
if err := service.MoveFile(originPath, newPath); err != nil {
return res, fmt.Errorf("move file error for %s: %w", filepath.Base(originPath), err)
}
service.Journal("move", originPath, newPath, "done", "")
}
if extension == "mkv" {
if config.MERGE_SUBTITLE_SIDECARS {
res.SubtitlesMerged = mkvmetadata.MergeSubtitleSidecars(ctx, originPath, newPath)
if res.SubtitlesMerged > 0 {
service.Journal("merge_sub", originPath, newPath, "done",
fmt.Sprintf("%d subtitle(s) embedded", res.SubtitlesMerged))
}
}
result, err := mkvmetadata.UpdateMkvMetadata(media)
if err != nil && config.SALVAGE && !mkvmetadata.IsNotMatroska(err) {
// Last resort: the normal path refused the file, keep what is
// playable and retry once
pp.Printf("Warning: MKV processing failed for %s: %v\n", filepath.Base(newPath), err)
report, serr := mkvmetadata.SalvageFile(ctx, newPath)
if serr != nil {
service.Journal("salvage", newPath, "", "failed", serr.Error())
} else {
res.Salvaged = true
detail := fmt.Sprintf("%d cluster(s) kept, %d byte(s) skipped, %d damaged range(s), %d region(s) rebuilt losslessly",
report.ClustersCopied, report.BytesSkipped, len(report.DamagedRanges), len(report.RepairedRanges))
if report.TruncatedTail {
detail += ", tail truncated (re-download advised)"
}
service.Journal("salvage", newPath, "", "done", detail)
result, err = mkvmetadata.UpdateMkvMetadata(media)
}
}
if err != nil {
pp.Printf("Warning: MKV metadata update failed for %s: %v\n", filepath.Base(newPath), err)
} else {
res.SeekIndexRepaired = strings.HasPrefix(result.MkvSeekIndex, "rebuilt")
if res.SeekIndexRepaired {
service.Journal("repair", newPath, "", "done", result.MkvSeekIndex)
}
res.DamageRepaired = strings.HasPrefix(result.MkvDamage, "repaired")
if res.DamageRepaired {
service.Journal("repair_damage", newPath, "", "done", result.MkvDamage)
}
res.Retimed = strings.HasPrefix(result.MkvAudioSync, "retimed")
if res.Retimed {
service.Journal("retime", newPath, "", "done", result.MkvAudioSync)
}
if config.PLAYABILITY_TARGET != "" {
if verdict, perr := mkvmetadata.CheckPlayability(ctx, newPath, config.PLAYABILITY_TARGET); perr != nil {
pp.Printf("Warning: playability check failed for %s: %v\n", filepath.Base(newPath), perr)
} else {
result.MkvPlayability = verdict
}
}
setMkvMetadata(media, result)
}
if config.WRITE_CONTENT_HASHES {
if err := mkvmetadata.WriteHashes(ctx, newPath); err != nil {
pp.Printf("Warning: content hashing failed for %s: %v\n", filepath.Base(newPath), err)
} else {
res.Hashed = true
service.Journal("hash", newPath, "", "done", "CONTENT_SHA256 written")
if dedupIndex != nil {
checkDuplicate(ctx, media, newPath, &res)
}
}
}
} else if config.MP4Convertible[extension] {
// MP4 kept as MP4 still goes through mkvgo: head-only triage
// (box-layout truncation, missing moov, edit-list audio delays) and
// the opt-in retime through the moov edit list - the container is
// sniffed from the first bytes, so a mislabeled file routes right.
var result types.FileInfos
result.MkvFilePath = newPath
damage, audioSync, retimed, derr := mkvmetadata.DiagnoseMedia(ctx, newPath, config.RETIME)
if derr != nil {
pp.Printf("Warning: MP4 triage failed for %s: %v\n", filepath.Base(newPath), derr)
} else {
result.MkvDamage = damage
result.MkvAudioSync = audioSync
res.Retimed = retimed
if retimed {
service.Journal("retime", newPath, "", "done", audioSync)
}
if damage != "" {
service.Journal("diagnose", newPath, "", "detected", damage)
}
setMkvMetadata(media, result)
}
}
printMediaTable(media)
return res, nil
}
// dryRunMedia reports what the real run would do: read-only analysis, no move,
// no write. The MKV analysis runs on the file at its current location.
func dryRunMedia(media types.Normalizable, originPath, newPath, extension string, convert bool) (mediaResult, error) {
var res mediaResult
res.SourceDir = filepath.Dir(originPath)
res.PlannedGone = []string{originPath}
if convert {
if blocker := mkvmetadata.ConvertBlocker(context.Background(), originPath); blocker != "" {
pp.Printf(" would move as-is, conversion pointless (%s)\n", blocker)
service.Journal("convert", originPath, newPath, "planned", "would skip: "+blocker)
} else {
pp.Printf(" would convert to MKV: %s\n", newPath)
service.Journal("convert", originPath, newPath, "planned", "")
res.Converted = true
}
} else {
pp.Printf(" would move to: %s\n", newPath)
service.Journal("move", originPath, newPath, "planned", "")
}
if strings.ToLower(filepath.Ext(originPath)) == ".mkv" {
if config.MERGE_SUBTITLE_SIDECARS {
for _, sub := range mkvmetadata.FindSubtitleSidecars(originPath) {
pp.Printf(" would merge subtitle: %s\n", filepath.Base(sub.Path))
service.Journal("merge_sub", sub.Path, newPath, "planned", "")
res.SubtitlesMerged++
res.PlannedGone = append(res.PlannedGone, sub.Path)
}
}
result, err := mkvmetadata.PlanMkvMetadata(media, originPath)
if err != nil {
pp.Printf("Warning: MKV analysis failed for %s: %v\n", filepath.Base(originPath), err)
} else {
res.SeekIndexRepaired = strings.HasPrefix(result.MkvSeekIndex, "would rebuild")
if res.SeekIndexRepaired {
service.Journal("repair", newPath, "", "planned", result.MkvSeekIndex)
}
if strings.HasPrefix(result.MkvDamage, "would repair") {
service.Journal("repair_damage", newPath, "", "planned", result.MkvDamage)
}
if strings.HasPrefix(result.MkvAudioSync, "would retime") {
service.Journal("retime", newPath, "", "planned", result.MkvAudioSync)
}
if config.PLAYABILITY_TARGET != "" {
if verdict, perr := mkvmetadata.CheckPlayability(context.Background(), originPath, config.PLAYABILITY_TARGET); perr == nil {
result.MkvPlayability = verdict
}
}
setMkvMetadata(media, result)
}
if config.WRITE_CONTENT_HASHES {
res.Hashed = true
service.Journal("hash", newPath, "", "planned", "")
}
} else if config.MP4Convertible[strings.TrimPrefix(strings.ToLower(filepath.Ext(originPath)), ".")] {
// MP4-family plan: same head-only mkvgo triage as the real run,
// read-only at the file's current location.
damage, audioSync, terr := mkvmetadata.PlanMediaTriage(context.Background(), originPath)
if terr != nil {
pp.Printf("Warning: MP4 triage failed for %s: %v\n", filepath.Base(originPath), terr)
} else {
result := types.FileInfos{MkvFilePath: newPath, MkvDamage: damage, MkvAudioSync: audioSync}
if strings.HasPrefix(audioSync, "would retime") {
service.Journal("retime", newPath, "", "planned", audioSync)
}
if damage != "" {
service.Journal("diagnose", newPath, "", "planned", damage)
}
setMkvMetadata(media, result)
}
}
printMediaTable(media)
return res, nil
}
// checkDuplicate flags a freshly hashed file whose content (identical track
// payloads, whatever the filename/metadata/track order) is already in the
// library. Report-only: the duplicate is named in the table and the journal,
// nothing is deleted.
func checkDuplicate(ctx context.Context, media types.Normalizable, path string, res *mediaResult) {
fp, err := mkvmetadata.FingerprintFile(ctx, path)
if err != nil || fp == "" {
return
}
if existing, ok := dedupIndex.Lookup(fp); ok && existing != path {
pp.Printf(" %s: same content as %s\n", filepath.Base(path), existing)
service.Journal("duplicate", path, existing, "detected", "identical track payloads (fingerprint match)")
res.Duplicate = true
switch v := media.(type) {
case *types.Serie:
v.MkvMetadata.MkvDuplicateOf = existing
case *types.Movie:
v.MkvMetadata.MkvDuplicateOf = existing
}
return
}
if err := dedupIndex.Add(fp, path); err != nil {
pp.Printf("Warning: dedup index write failed: %v\n", err)
}
}
func setMkvMetadata(media types.Normalizable, result types.FileInfos) {
switch v := media.(type) {
case *types.Serie:
v.MkvMetadata = result
case *types.Movie:
v.MkvMetadata = result
}
}
func printMediaTable(media types.Normalizable) {
printMu.Lock()
service.PrintStructTable(media)
pp.Println("________________________________________________________________________________")
printMu.Unlock()
}
func printStats(stats ProcessStats, elapsed time.Duration) {
if len(stats.Errors) > 0 {
pp.Println("\nErrors encountered:")
for _, err := range stats.Errors {
pp.Printf(" - %v\n", err)
}
}
totalCount := stats.MoviesCount + stats.SeriesCount
if totalCount == 0 && stats.Skipped == 0 {
pp.Println("No videos found")
return
}
pp.Println("")
if config.DRY_RUN {
pp.Println("DRY RUN summary (nothing was modified):")
}
pp.Println("Movies processed:", stats.MoviesCount)
pp.Println("Series processed:", stats.SeriesCount)
if stats.Skipped > 0 {
pp.Println("Skipped (collision):", stats.Skipped)
}
if stats.Converted > 0 {
pp.Println("Converted to MKV:", stats.Converted)
}
if stats.SeekIndexRepaired > 0 {
pp.Println("Seek indexes repaired:", stats.SeekIndexRepaired)
}
if stats.DamageRepaired > 0 {
pp.Println("Damaged files repaired (surgical):", stats.DamageRepaired)
}
if stats.Retimed > 0 {
pp.Println("A/V desyncs retimed:", stats.Retimed)
}
if stats.SubtitlesMerged > 0 {
pp.Println("Subtitle sidecars merged:", stats.SubtitlesMerged)
}
if stats.Hashed > 0 {
pp.Println("Files hashed:", stats.Hashed)
}
if stats.Salvaged > 0 {
pp.Println("Damaged files salvaged:", stats.Salvaged)
}
if stats.Duplicates > 0 {
pp.Println("Content duplicates detected:", stats.Duplicates)
}
if stats.JunkRemoved > 0 || stats.DirsRemoved > 0 {
pp.Println("Cleanup: junk files:", stats.JunkRemoved, "- dirs:", stats.DirsRemoved)
}
pp.Println("Total videos processed:", totalCount)
pp.Println("Elapsed:", elapsed.Round(time.Second).String())
pp.Println("________________________________________________________________________________")
}