Compare commits
2 Commits
Author | SHA1 | Date |
---|---|---|
Stein Ivar Berghei | 590df025aa | |
Stein Ivar Berghei | 5af4fca840 |
|
@ -1,9 +1,7 @@
|
|||
# guessit-go
|
||||
|
||||
``` go
|
||||
import "git.stein-ivar.net/steino/guessit-go"
|
||||
|
||||
guessit, err := guessit.New(GuessitConfig{
|
||||
guessit, err := New(GuessitConfig{
|
||||
Pip: true,
|
||||
})
|
||||
|
||||
|
|
38
guessit.go
38
guessit.go
|
@ -5,6 +5,8 @@ import (
|
|||
"fmt"
|
||||
"log"
|
||||
"os/exec"
|
||||
|
||||
_ "embed"
|
||||
)
|
||||
|
||||
type GuessitConfig struct {
|
||||
|
@ -15,7 +17,6 @@ type GuessitConfig struct {
|
|||
|
||||
type Guessit struct {
|
||||
GuessitConfig
|
||||
DefaultOptions []string
|
||||
}
|
||||
|
||||
type Match struct {
|
||||
|
@ -33,7 +34,6 @@ type Match struct {
|
|||
// Video
|
||||
ScreenSize string `json:"screen_size,omitempty"`
|
||||
Container string `json:"container,omitempty"`
|
||||
VideoCodec string `json:"video_codec,omitempty"`
|
||||
|
||||
// Audio
|
||||
AudioChannels string `json:"audio_channels,omitempty"`
|
||||
|
@ -43,37 +43,6 @@ type Match struct {
|
|||
Other []string `json:"other,omitempty"`
|
||||
}
|
||||
|
||||
func (u *Match) UnmarshalJSON(data []byte) error {
|
||||
type Alias Match
|
||||
aux := &struct {
|
||||
AudioCodec interface{} `json:"audio_codec,omitempty"`
|
||||
Other interface{} `json:"other,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
|
||||
}
|
||||
|
||||
switch oth := aux.Other.(type) {
|
||||
case string:
|
||||
u.Other = append(u.Other, oth)
|
||||
case []string:
|
||||
u.Other = oth
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g GuessitConfig) PipInstall() (err error) {
|
||||
args := []string{"-m", "pip", "install", "guessit"}
|
||||
cmd := exec.Command(g.Python, args...)
|
||||
|
@ -106,12 +75,11 @@ func New(conf GuessitConfig) (Guessit, error) {
|
|||
}
|
||||
}
|
||||
|
||||
return Guessit{conf, []string{}}, nil
|
||||
return Guessit{conf}, nil
|
||||
}
|
||||
|
||||
func (g Guessit) Guessit(s string, options ...string) (out Match, err error) {
|
||||
args := []string{"-m", "guessit", s}
|
||||
args = append(args, g.DefaultOptions...)
|
||||
args = append(args, options...)
|
||||
args = append(args, "--json")
|
||||
|
||||
|
|
Loading…
Reference in New Issue