Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module github.com/Unpackerr/unpackerr

go 1.26.0

//nolint:gomoddirectives // we need to use our own iso9660 package until we fix the issue with the original package.
// we need to use our own iso9660 package until we fix the issue with the original package.
replace github.com/kdomanski/iso9660 => github.com/Unpackerr/iso9660 v0.0.1

require (
Expand All @@ -22,9 +22,9 @@ require (
golift.io/cnfg v0.2.5
golift.io/cnfgfile v0.0.0-20240713024420-a5436d84eb48
golift.io/rotatorr v0.0.0-20260217050959-f6ac6fc7b38e
golift.io/starr v1.3.0
golift.io/starr v1.3.1-0.20260220055600-a1399516cfeb
golift.io/version v0.0.2
golift.io/xtractr v0.3.1-0.20260218060125-b814a941badb
golift.io/xtractr v0.3.1-0.20260219054943-e6f0434c2d7a
gopkg.in/yaml.v3 v3.0.1
)

Expand Down Expand Up @@ -84,4 +84,3 @@ require (
golift.io/udf v0.0.1 // indirect
google.golang.org/protobuf v1.36.11 // indirect
)

10 changes: 4 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -242,22 +242,20 @@ golang.org/x/tools v0.42.0/go.mod h1:Ma6lCIwGZvHK6XtgbswSoWroEkhugApmsXyrUmBhfr0
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golift.io/cnfg v0.2.4 h1:AfSueg0p6DTCufZjxRWlMSeSAL2eMJ6lN/ySmvpTl50=
golift.io/cnfg v0.2.4/go.mod h1:iMzXYjvZI7iZphzY75hkFR/VShYeuZznXiQtFsBOSCU=
golift.io/cnfg v0.2.5 h1:NwhQ+REL9BSTiHYU4MKMawCEzvtjmhE8RlNiE7XroqE=
golift.io/cnfg v0.2.5/go.mod h1:iMzXYjvZI7iZphzY75hkFR/VShYeuZznXiQtFsBOSCU=
golift.io/cnfgfile v0.0.0-20240713024420-a5436d84eb48 h1:c7cJWRr0cUnFHKtq072esKzhQHKlFA5YRY/hPzQrdko=
golift.io/cnfgfile v0.0.0-20240713024420-a5436d84eb48/go.mod h1:zHm9o8SkZ6Mm5DfGahsrEJPsogyR0qItP59s5lJ98/I=
golift.io/rotatorr v0.0.0-20260217050959-f6ac6fc7b38e h1:FgfNgbg2EUhFzAWPycsbh1dYiFJNLJFDDkn+E298DFQ=
golift.io/rotatorr v0.0.0-20260217050959-f6ac6fc7b38e/go.mod h1:l/fgYTDxyEw15tRLjAtc13M3is1SXMU4hAIE0tdduAQ=
golift.io/starr v1.3.0 h1:dmIt27th+LWIPWHdiHXvDeG8H1h9TT+PQE1ID3DssFY=
golift.io/starr v1.3.0/go.mod h1:W8A/49qhVfoU0HgZyJla4NKRCM5eUHuhSesc+buPIBU=
golift.io/starr v1.3.1-0.20260220055600-a1399516cfeb h1:sRpFSdVj+mb3/ZG57GVDwEzWZlF0UdhGZqFtPrwgaxs=
golift.io/starr v1.3.1-0.20260220055600-a1399516cfeb/go.mod h1:W8A/49qhVfoU0HgZyJla4NKRCM5eUHuhSesc+buPIBU=
golift.io/udf v0.0.1 h1:kEcJVzqqR+IEWGMuPjuVPT9DzXRDukEgsizKAKn1LF8=
golift.io/udf v0.0.1/go.mod h1:ndK7AlWOh+u+nW9tNsQR95dfHsfASG5Y3dMyzVqmPjw=
golift.io/version v0.0.2 h1:i0gXRuSDHKs4O0sVDUg4+vNIuOxYoXhaxspftu2FRTE=
golift.io/version v0.0.2/go.mod h1:76aHNz8/Pm7CbuxIsDi97jABL5Zui3f2uZxDm4vB6hU=
golift.io/xtractr v0.3.1-0.20260218060125-b814a941badb h1:03V2/jDBm5QJTAFB6NxF0esrOJ85u6Vo0DIzQUk069Q=
golift.io/xtractr v0.3.1-0.20260218060125-b814a941badb/go.mod h1:+eMxkIVQjwJENgn9XCSqmsPGuzWOPvn3Ez5YSRM2Dgw=
golift.io/xtractr v0.3.1-0.20260219054943-e6f0434c2d7a h1:GvHGPVvHxogdT4Jf6v4t85tQ5+VULd0gX4kYHh3dsJ8=
golift.io/xtractr v0.3.1-0.20260219054943-e6f0434c2d7a/go.mod h1:bDBgCgojMc0HncBUMD29MYIaupCq9enUbeAYeB8AuNY=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/Knetic/govaluate.v3 v3.0.0/go.mod h1:csKLBORsPbafmSCGTEh3U7Ozmsuq8ZSIlKk1bcqph0E=
Expand Down
8 changes: 7 additions & 1 deletion pkg/unpackerr/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,8 @@ func (u *Unpackerr) checkExtractDone(now time.Time) {
// handleXtractrCallback handles callbacks from the xtractr library for starr apps (not folders).
// This takes the provided info and logs it then sends it the queue update method.
func (u *Unpackerr) handleXtractrCallback(resp *xtractr.Response) {
if item := u.Map[resp.X.Name]; resp.Done && item != nil {
item := u.Map[resp.X.Name]
if resp.Done && item != nil {
u.updateMetrics(resp, item.App, item.URL)
} else if item != nil {
item.XProg.Archives = resp.Archives.Count() + resp.Extras.Count()
Expand All @@ -235,6 +236,11 @@ func (u *Unpackerr) handleXtractrCallback(resp *xtractr.Response) {
resp.Archives.Count(), resp.Extras.Count(), len(resp.NewFiles), bytefmt.ByteSize(resp.Size))
u.Debugf("Extraction Finished: %d files in path: %s", len(files), files)
u.updateQueueStatus(&newStatus{Name: resp.X.Name, Status: EXTRACTED, Resp: resp}, now, true)

if item != nil && item.App == starr.Lidarr && item.SplitFlac &&
extractionHasFlacFiles(resp.NewFiles) {
go u.importSplitFlacTracks(item, u.lidarrServerByURL(item.URL))
}
}
}

Expand Down
70 changes: 70 additions & 0 deletions pkg/unpackerr/lidarr.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package unpackerr

import (
"errors"
"strings"
"time"

"golift.io/starr"
Expand Down Expand Up @@ -136,3 +137,72 @@ func (u *Unpackerr) haveLidarrQitem(name string) bool {

return false
}

// lidarrServerByURL returns the Lidarr server config that matches the given URL, or nil.
func (u *Unpackerr) lidarrServerByURL(url string) *LidarrConfig {
for _, server := range u.Lidarr {
if server.URL == url {
return server
}
}

return nil
}

// extractionHasFlacFiles returns true if any path in files has a .flac extension.
// Used to only trigger manual import after a FLAC+CUE split, not for e.g. zip-of-mp3s.
func extractionHasFlacFiles(files []string) bool {
for _, p := range files {
if strings.HasSuffix(strings.ToLower(p), ".flac") {
return true
}
}

return false
}

// importSplitFlacTracks runs in a goroutine after a Lidarr FLAC+CUE split extraction completes.
// It asks Lidarr for the manual import list for the extract folder and sends the ManualImport command
// so Lidarr imports the split track files.
func (u *Unpackerr) importSplitFlacTracks(item *Extract, server *LidarrConfig) {
if server == nil {
u.Printf("[Lidarr] No Lidarr server found for manual import, this might be a bug: %s", item.Path)
return
}

downloadID, _ := item.IDs["downloadId"].(string)
artistID, _ := item.IDs["artistId"].(int64)

params := &lidarr.ManualImportParams{
Folder: item.Path,
DownloadID: downloadID,
ArtistID: artistID,
FilterExistingFiles: false,
ReplaceExistingFiles: true,
}

outputs, err := server.ManualImport(params)
if err != nil {
u.Errorf("[Lidarr] Manual import list failed for %s: %v", item.Path, err)
return
}

if len(outputs) == 0 {
u.Printf("[Lidarr] No files returned for manual import (folder: %s); import manually in Lidarr", item.Path)
return
}

cmd := lidarr.ManualImportCommandFromOutputs(outputs, true)
if cmd == nil {
u.Printf("[Lidarr] No importable files for manual import: %s", item.Path)
return
}

_, err = server.SendManualImportCommand(cmd)
if err != nil {
u.Errorf("[Lidarr] Manual import command failed for %s: %v", item.Path, err)
return
}

u.Printf("[Lidarr] Manual import triggered for %d files: %s", len(cmd.Files), item.Path)
}