fix media workflows and download organization

This commit is contained in:
ShukeBta
2026-06-26 08:42:16 +08:00
parent 0da96f7e4e
commit 65adca04df
102 changed files with 4063 additions and 437 deletions
+13
View File
@@ -28,6 +28,7 @@ var ErrUnsupportedOrganizeSource = errors.New("source is not a supported video f
const (
organizeSkipAlreadyOrganized = "already organized"
organizeSkipActiveDownload = "active download"
organizeSkipDuplicateLibrary = "duplicate in library"
organizeSkipTargetExists = "target file exists"
organizeSkipSampleClip = "sample/trailer clip"
@@ -60,11 +61,18 @@ func (o *OrganizerService) OrganizeDirectory(ctx context.Context, opts OrganizeO
mode := o.resolveTransferMode(ctx, opts.TransferMode)
res := &OrganizeResult{SourcePath: source, DestPath: dest, DryRun: opts.DryRun}
metadataCache := map[string]*Match{}
activeDownloads := o.newActiveDownloadGuard(ctx)
if !info.IsDir() {
ext := strings.ToLower(filepath.Ext(source))
if _, ok := videoExtensions[ext]; !ok {
return nil, fmt.Errorf("%w: %s", ErrUnsupportedOrganizeSource, source)
}
if activeDownloads.contains(source) {
res.Skipped++
res.Items = append(res.Items, OrganizePreviewItem{Source: source, Action: "skip", Reason: organizeSkipActiveDownload})
o.logOrganizeDirectoryResult("organize file finished", res, mode)
return res, nil
}
if skipped, reason := shouldSkipOrganizeSourceVideo(source, filepath.Dir(source)); skipped {
res.Skipped++
res.Items = append(res.Items, OrganizePreviewItem{Source: source, Action: "skip", Reason: reason})
@@ -97,6 +105,11 @@ func (o *OrganizerService) OrganizeDirectory(ctx context.Context, opts OrganizeO
if _, ok := videoExtensions[ext]; !ok {
return nil
}
if activeDownloads.contains(path) {
res.Skipped++
res.Items = append(res.Items, OrganizePreviewItem{Source: path, Action: "skip", Reason: organizeSkipActiveDownload})
return nil
}
if skipped, reason := shouldSkipOrganizeSourceVideo(path, source); skipped {
res.Skipped++
res.Items = append(res.Items, OrganizePreviewItem{Source: path, Action: "skip", Reason: reason})