refactor: extract BuildSyncItems to library package, remove duplication
This commit is contained in:
parent
60176fadc2
commit
d0f2abcd74
3 changed files with 47 additions and 76 deletions
|
|
@ -573,7 +573,7 @@ func runAutoScan(ctx context.Context, cfg config.Config, interval time.Duration)
|
||||||
}
|
}
|
||||||
|
|
||||||
ac := agent.NewClient(cfg.Auth.APIURL, apiKey, "unarr/"+Version)
|
ac := agent.NewClient(cfg.Auth.APIURL, apiKey, "unarr/"+Version)
|
||||||
items := buildSyncItems(cache)
|
items := library.BuildSyncItems(cache)
|
||||||
if len(items) == 0 {
|
if len(items) == 0 {
|
||||||
log.Printf("[auto-scan] no items to sync")
|
log.Printf("[auto-scan] no items to sync")
|
||||||
return
|
return
|
||||||
|
|
@ -616,42 +616,4 @@ func runAutoScan(ctx context.Context, cfg config.Config, interval time.Duration)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// buildSyncItems converts cached library items to sync request items.
|
// buildSyncItems moved to internal/library/sync.go as library.BuildSyncItems
|
||||||
func buildSyncItems(cache *library.LibraryCache) []agent.LibrarySyncItem {
|
|
||||||
items := make([]agent.LibrarySyncItem, 0, len(cache.Items))
|
|
||||||
for _, item := range cache.Items {
|
|
||||||
if item.ScanError != "" {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
si := agent.LibrarySyncItem{
|
|
||||||
FilePath: item.FilePath,
|
|
||||||
FileName: item.FileName,
|
|
||||||
FileSize: item.FileSize,
|
|
||||||
Title: item.Title,
|
|
||||||
Year: item.Year,
|
|
||||||
ContentType: library.DeriveContentType(item),
|
|
||||||
Season: item.Season,
|
|
||||||
Episode: item.Episode,
|
|
||||||
}
|
|
||||||
|
|
||||||
if item.MediaInfo != nil {
|
|
||||||
if item.MediaInfo.Video != nil {
|
|
||||||
si.Resolution = library.ResolveResolution(item.MediaInfo.Video.Height)
|
|
||||||
si.VideoCodec = item.MediaInfo.Video.Codec
|
|
||||||
si.HDR = item.MediaInfo.Video.HDR
|
|
||||||
si.BitDepth = item.MediaInfo.Video.BitDepth
|
|
||||||
}
|
|
||||||
codec, channels := library.PrimaryAudioTrack(item.MediaInfo.Audio)
|
|
||||||
si.AudioCodec = codec
|
|
||||||
si.AudioChannels = channels
|
|
||||||
si.AudioLanguages = library.AudioLanguages(item.MediaInfo.Audio)
|
|
||||||
si.SubtitleLanguages = library.SubtitleLanguages(item.MediaInfo.Subtitles)
|
|
||||||
si.AudioTracks = item.MediaInfo.Audio
|
|
||||||
si.SubtitleTracks = item.MediaInfo.Subtitles
|
|
||||||
si.VideoInfo = item.MediaInfo.Video
|
|
||||||
}
|
|
||||||
|
|
||||||
items = append(items, si)
|
|
||||||
}
|
|
||||||
return items
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -153,42 +153,7 @@ func syncToServer(ctx context.Context, cfg config.Config, cache *library.Library
|
||||||
|
|
||||||
ac := agent.NewClient(cfg.Auth.APIURL, apiKey, "unarr/"+Version)
|
ac := agent.NewClient(cfg.Auth.APIURL, apiKey, "unarr/"+Version)
|
||||||
|
|
||||||
// Build sync items from cache
|
items := library.BuildSyncItems(cache)
|
||||||
items := make([]agent.LibrarySyncItem, 0, len(cache.Items))
|
|
||||||
for _, item := range cache.Items {
|
|
||||||
if item.ScanError != "" {
|
|
||||||
continue // skip items with scan errors
|
|
||||||
}
|
|
||||||
si := agent.LibrarySyncItem{
|
|
||||||
FilePath: item.FilePath,
|
|
||||||
FileName: item.FileName,
|
|
||||||
FileSize: item.FileSize,
|
|
||||||
Title: item.Title,
|
|
||||||
Year: item.Year,
|
|
||||||
ContentType: library.DeriveContentType(item),
|
|
||||||
Season: item.Season,
|
|
||||||
Episode: item.Episode,
|
|
||||||
}
|
|
||||||
|
|
||||||
if item.MediaInfo != nil {
|
|
||||||
if item.MediaInfo.Video != nil {
|
|
||||||
si.Resolution = library.ResolveResolution(item.MediaInfo.Video.Height)
|
|
||||||
si.VideoCodec = item.MediaInfo.Video.Codec
|
|
||||||
si.HDR = item.MediaInfo.Video.HDR
|
|
||||||
si.BitDepth = item.MediaInfo.Video.BitDepth
|
|
||||||
}
|
|
||||||
codec, channels := library.PrimaryAudioTrack(item.MediaInfo.Audio)
|
|
||||||
si.AudioCodec = codec
|
|
||||||
si.AudioChannels = channels
|
|
||||||
si.AudioLanguages = library.AudioLanguages(item.MediaInfo.Audio)
|
|
||||||
si.SubtitleLanguages = library.SubtitleLanguages(item.MediaInfo.Subtitles)
|
|
||||||
si.AudioTracks = item.MediaInfo.Audio
|
|
||||||
si.SubtitleTracks = item.MediaInfo.Subtitles
|
|
||||||
si.VideoInfo = item.MediaInfo.Video
|
|
||||||
}
|
|
||||||
|
|
||||||
items = append(items, si)
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(items) == 0 {
|
if len(items) == 0 {
|
||||||
color.Yellow("\n No valid items to sync.")
|
color.Yellow("\n No valid items to sync.")
|
||||||
|
|
|
||||||
44
internal/library/sync.go
Normal file
44
internal/library/sync.go
Normal file
|
|
@ -0,0 +1,44 @@
|
||||||
|
package library
|
||||||
|
|
||||||
|
import "github.com/torrentclaw/torrentclaw-cli/internal/agent"
|
||||||
|
|
||||||
|
// BuildSyncItems converts cached library items to sync request items.
|
||||||
|
// Shared between unarr scan (cmd/scan.go) and auto-scan (cmd/daemon.go).
|
||||||
|
func BuildSyncItems(cache *LibraryCache) []agent.LibrarySyncItem {
|
||||||
|
items := make([]agent.LibrarySyncItem, 0, len(cache.Items))
|
||||||
|
for _, item := range cache.Items {
|
||||||
|
if item.ScanError != "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
si := agent.LibrarySyncItem{
|
||||||
|
FilePath: item.FilePath,
|
||||||
|
FileName: item.FileName,
|
||||||
|
FileSize: item.FileSize,
|
||||||
|
Title: item.Title,
|
||||||
|
Year: item.Year,
|
||||||
|
ContentType: DeriveContentType(item),
|
||||||
|
Season: item.Season,
|
||||||
|
Episode: item.Episode,
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.MediaInfo != nil {
|
||||||
|
if item.MediaInfo.Video != nil {
|
||||||
|
si.Resolution = ResolveResolution(item.MediaInfo.Video.Height)
|
||||||
|
si.VideoCodec = item.MediaInfo.Video.Codec
|
||||||
|
si.HDR = item.MediaInfo.Video.HDR
|
||||||
|
si.BitDepth = item.MediaInfo.Video.BitDepth
|
||||||
|
}
|
||||||
|
codec, channels := PrimaryAudioTrack(item.MediaInfo.Audio)
|
||||||
|
si.AudioCodec = codec
|
||||||
|
si.AudioChannels = channels
|
||||||
|
si.AudioLanguages = AudioLanguages(item.MediaInfo.Audio)
|
||||||
|
si.SubtitleLanguages = SubtitleLanguages(item.MediaInfo.Subtitles)
|
||||||
|
si.AudioTracks = item.MediaInfo.Audio
|
||||||
|
si.SubtitleTracks = item.MediaInfo.Subtitles
|
||||||
|
si.VideoInfo = item.MediaInfo.Video
|
||||||
|
}
|
||||||
|
|
||||||
|
items = append(items, si)
|
||||||
|
}
|
||||||
|
return items
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue