From 294d179089941db9a34bbf3d23a40f7975748adc Mon Sep 17 00:00:00 2001 From: Stein Ivar Berghei Date: Tue, 30 May 2023 16:47:42 +0900 Subject: [PATCH] audio_codec still needs to be a array --- guessit.go | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/guessit.go b/guessit.go index b1c5634..d52dfef 100644 --- a/guessit.go +++ b/guessit.go @@ -34,13 +34,37 @@ type Match struct { Container string `json:"container,omitempty"` // Audio - AudioChannels string `json:"audio_channels,omitempty"` - AudioCodec string `json:"audio_codec,omitempty"` + AudioChannels string `json:"audio_channels,omitempty"` + AudioCodec []string `json:"audio_codec,omitempty"` // Other Other []string `json:"other,omitempty"` } +func (u *Match) UnmarshalJSON(data []byte) error { + fmt.Println(u) + type Alias Match + aux := &struct { + AudioCodec interface{} `json:"audio_codec,omitempty"` + *Alias + }{ + Alias: (*Alias)(u), + } + + if err := json.Unmarshal(data, &aux); err != nil { + return err + } + + switch ac := aux.AudioCodec.(type) { + case string: + u.AudioCodec = append(u.AudioCodec, ac) + case []string: + u.AudioCodec = ac + } + + return nil +} + func (g GuessitConfig) PipInstall() (err error) { args := []string{"-m", "pip", "install", "guessit"} cmd := exec.Command(g.Python, args...)