Files
music-agregator/internal/musicfs/sync.go
T
Alexander 76e426c5d3 feat: integrate musicfs for post-download metadata enrichment
- Add internal/musicfs package: gRPC client, TriggerRescan (stream consumer), EnrichFiles (BatchUpdateMetadata), DeriveSubdir helper
- Add MusicFS config section (enabled, endpoint, origin_id, origin_root, timeout)
- Wire MusicFSClient into PollDownloadWorker: on download completion, trigger scoped rescan then push enriched metadata
- Fix album auto-persist in monitor workflow: persist artist+album from metadata-agregator before saving torrent/download
- Add filterByActiveSeeders: skip torrents where magnet resolution found 0 real active seeders
- Add musicfs proto to buf.gen.yaml inputs
- Enricher only sends non-empty fields to avoid overwriting existing file tag data with empty values
2026-05-17 23:32:44 +02:00

63 lines
1.2 KiB
Go

package musicfs
import (
"context"
"fmt"
"io"
"github.com/rs/zerolog/log"
pb "homelab.lan/music-agregator/gen/musicfs/v1"
)
type SyncedFile struct {
Path string
FileID int64
VirtualPath string
}
type RescanResult struct {
NewFiles []SyncedFile
BytesSynced uint64
}
func (c *Client) TriggerRescan(ctx context.Context, originID string, subdir string) (*RescanResult, error) {
stream, err := c.MusicFS.RescanOrigin(ctx, &pb.OriginRequest{
OriginId: originID,
Subdir: &subdir,
})
if err != nil {
return nil, fmt.Errorf("rescan origin: %w", err)
}
var result RescanResult
for {
progress, err := stream.Recv()
if err == io.EOF {
break
}
if err != nil {
return nil, fmt.Errorf("rescan stream: %w", err)
}
log.Trace().
Str("phase", progress.GetPhase()).
Uint32("current", progress.GetCurrent()).
Uint32("total", progress.GetTotal()).
Msg("rescan progress")
if progress.GetPhase() == "complete" {
for _, sf := range progress.GetNewFiles() {
result.NewFiles = append(result.NewFiles, SyncedFile{
Path: sf.GetPath(),
FileID: sf.GetFileId(),
VirtualPath: sf.GetVirtualPath(),
})
}
result.BytesSynced = progress.GetBytesSynced()
}
}
return &result, nil
}