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...)