Some checks failed
Pipeline: Test, Lint, Build / Get version info (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test Go code (push) Has been cancelled
Pipeline: Test, Lint, Build / Test JS code (push) Has been cancelled
Pipeline: Test, Lint, Build / Lint i18n files (push) Has been cancelled
Pipeline: Test, Lint, Build / Check Docker configuration (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (darwin/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v5) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v6) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm/v7) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (linux/arm64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/386) (push) Has been cancelled
Pipeline: Test, Lint, Build / Build (windows/amd64) (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to GHCR (push) Has been cancelled
Pipeline: Test, Lint, Build / Push to Docker Hub (push) Has been cancelled
Pipeline: Test, Lint, Build / Cleanup digest artifacts (push) Has been cancelled
Pipeline: Test, Lint, Build / Build Windows installers (push) Has been cancelled
Pipeline: Test, Lint, Build / Package/Release (push) Has been cancelled
Pipeline: Test, Lint, Build / Upload Linux PKG (push) Has been cancelled
Close stale issues and PRs / stale (push) Has been cancelled
POEditor import / update-translations (push) Has been cancelled
80 lines
1.9 KiB
Go
80 lines
1.9 KiB
Go
package cmd
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/navidrome/navidrome/core"
|
|
"github.com/navidrome/navidrome/log"
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/pelletier/go-toml/v2"
|
|
"github.com/spf13/cobra"
|
|
"gopkg.in/yaml.v3"
|
|
)
|
|
|
|
var (
|
|
format string
|
|
)
|
|
|
|
func init() {
|
|
inspectCmd.Flags().StringVarP(&format, "format", "f", "jsonindent", "output format (pretty, toml, yaml, json, jsonindent)")
|
|
rootCmd.AddCommand(inspectCmd)
|
|
}
|
|
|
|
var inspectCmd = &cobra.Command{
|
|
Use: "inspect [files to inspect]",
|
|
Short: "Inspect tags",
|
|
Long: "Show file tags as seen by Navidrome",
|
|
Args: cobra.MinimumNArgs(1),
|
|
Run: func(cmd *cobra.Command, args []string) {
|
|
runInspector(args)
|
|
},
|
|
}
|
|
|
|
var marshalers = map[string]func(interface{}) ([]byte, error){
|
|
"pretty": prettyMarshal,
|
|
"toml": toml.Marshal,
|
|
"yaml": yaml.Marshal,
|
|
"json": json.Marshal,
|
|
"jsonindent": func(v interface{}) ([]byte, error) {
|
|
return json.MarshalIndent(v, "", " ")
|
|
},
|
|
}
|
|
|
|
func prettyMarshal(v interface{}) ([]byte, error) {
|
|
out := v.([]core.InspectOutput)
|
|
var res strings.Builder
|
|
for i := range out {
|
|
res.WriteString(fmt.Sprintf("====================\nFile: %s\n\n", out[i].File))
|
|
t, _ := toml.Marshal(out[i].RawTags)
|
|
res.WriteString(fmt.Sprintf("Raw tags:\n%s\n\n", t))
|
|
t, _ = toml.Marshal(out[i].MappedTags)
|
|
res.WriteString(fmt.Sprintf("Mapped tags:\n%s\n\n", t))
|
|
}
|
|
return []byte(res.String()), nil
|
|
}
|
|
|
|
func runInspector(args []string) {
|
|
marshal := marshalers[format]
|
|
if marshal == nil {
|
|
log.Fatal("Invalid format", "format", format)
|
|
}
|
|
var out []core.InspectOutput
|
|
for _, filePath := range args {
|
|
if !model.IsAudioFile(filePath) {
|
|
log.Warn("Not an audio file", "file", filePath)
|
|
continue
|
|
}
|
|
output, err := core.Inspect(filePath, 1, "")
|
|
if err != nil {
|
|
log.Warn("Unable to process file", "file", filePath, "error", err)
|
|
continue
|
|
}
|
|
|
|
out = append(out, *output)
|
|
}
|
|
data, _ := marshal(out)
|
|
fmt.Println(string(data))
|
|
}
|