Compare commits
9 Commits
Author | SHA1 | Date |
---|---|---|
Stein Ivar Berghei | c4f1163a94 | |
Stein Ivar Berghei | 7b4bf1563c | |
Stein Ivar Berghei | 7d34e678ac | |
Stein Ivar Berghei | b81c62af15 | |
Stein Ivar Berghei | 74fdf1601a | |
Stein Ivar Berghei | 294d179089 | |
Stein Ivar Berghei | 95c0ba95cc | |
Stein Ivar Berghei | eb166f5e1a | |
Stein Ivar Berghei | e6aaace483 |
|
@ -1,7 +1,9 @@
|
||||||
# guessit-go
|
# guessit-go
|
||||||
|
|
||||||
``` go
|
``` go
|
||||||
guessit, err := New(GuessitConfig{
|
import "git.stein-ivar.net/steino/guessit-go"
|
||||||
|
|
||||||
|
guessit, err := guessit.New(GuessitConfig{
|
||||||
Pip: true,
|
Pip: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
38
guessit.go
38
guessit.go
|
@ -5,8 +5,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
_ "embed"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type GuessitConfig struct {
|
type GuessitConfig struct {
|
||||||
|
@ -17,6 +15,7 @@ type GuessitConfig struct {
|
||||||
|
|
||||||
type Guessit struct {
|
type Guessit struct {
|
||||||
GuessitConfig
|
GuessitConfig
|
||||||
|
DefaultOptions []string
|
||||||
}
|
}
|
||||||
|
|
||||||
type Match struct {
|
type Match struct {
|
||||||
|
@ -34,6 +33,7 @@ type Match struct {
|
||||||
// Video
|
// Video
|
||||||
ScreenSize string `json:"screen_size,omitempty"`
|
ScreenSize string `json:"screen_size,omitempty"`
|
||||||
Container string `json:"container,omitempty"`
|
Container string `json:"container,omitempty"`
|
||||||
|
VideoCodec string `json:"video_codec,omitempty"`
|
||||||
|
|
||||||
// Audio
|
// Audio
|
||||||
AudioChannels string `json:"audio_channels,omitempty"`
|
AudioChannels string `json:"audio_channels,omitempty"`
|
||||||
|
@ -43,6 +43,37 @@ type Match struct {
|
||||||
Other []string `json:"other,omitempty"`
|
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) {
|
func (g GuessitConfig) PipInstall() (err error) {
|
||||||
args := []string{"-m", "pip", "install", "guessit"}
|
args := []string{"-m", "pip", "install", "guessit"}
|
||||||
cmd := exec.Command(g.Python, args...)
|
cmd := exec.Command(g.Python, args...)
|
||||||
|
@ -75,11 +106,12 @@ func New(conf GuessitConfig) (Guessit, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return Guessit{conf}, nil
|
return Guessit{conf, []string{}}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g Guessit) Guessit(s string, options ...string) (out Match, err error) {
|
func (g Guessit) Guessit(s string, options ...string) (out Match, err error) {
|
||||||
args := []string{"-m", "guessit", s}
|
args := []string{"-m", "guessit", s}
|
||||||
|
args = append(args, g.DefaultOptions...)
|
||||||
args = append(args, options...)
|
args = append(args, options...)
|
||||||
args = append(args, "--json")
|
args = append(args, "--json")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue