diff --git a/README.md b/README.md index 3445d2d..de41436 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Torrent name parser in Go Do feel free to create issues with sane names that fail to parse properly -Have done a little clean up and increased the test coverage to ~95% +I've done a little clean up and increased the test coverage to ~95% ## Usage @@ -36,6 +36,32 @@ func main() { Output: ```sh -torrentparser.Torrent{Title:"blade runner 2049", AlternativeTitle:"", ContentType:1, Year:2017, Resolution:"4k", Extended:false, Unrated:false, Proper:false, Repack:false, Convert:false, Hardcoded:false, Retail:false, Remastered:false, Region:"", Container:"mkv", Source:"bluray", Codec:"x265", Audio:"", Group:"terminal", Season:-1, Episode:0, Language:"", Hdr:false, ColorDepth:"", Date:""} +torrentparser.Torrent{Title:"blade runner 2049", AlternativeTitle:"", ContentType:1, Year:2017, Resolution:"4k", Extended:false, Unrated:false, Proper:false, Repack:false, Convert:false, Hardcoded:false, Retail:false, Remastered:false, Region:"", Container:"mkv", Source:"bluray", Codec:"x265", Audio:"", Group:"terminal", Season:-1, Seasons:[]int(nil), Episode:0, Languages:[]string(nil), Hdr:false, HdrTypes:[]string(nil), ColorDepth:"", Date:""} blade runner 2049 ``` + +### Binary + +```bash +go install github.com/ProfChaos/torrent-name-parser/cmd/tnp@latest +``` + +```bash +tnp blade.runner.2049.2017.2160p.uhd.bluray.x265-terminal.mkv +``` + +```json +{"title":"blade runner 2049","alternativeTitle":"","contentType":1,"year":2017,"resolution":"4k","extended":false,"unrated":false,"proper":false,"repack":false,"convert":false,"hardcoded":false,"retail":false,"remastered":false,"region":"","container":"mkv","source":"bluray","codec":"x265","audio":"","group":"terminal","season":-1,"seasons":null,"episode":0,"languages":null,"hdr":false,"hdrTypes":null,"colorDepth":"","date":""} +``` + +#### Debug + +If you want to check where in the name the parser found a certain value you can use the debug flag. This will highlight the text for each property. + +```bash +tnp blade.runner.2049.2017.2160p.uhd.bluray.x265-terminal.mkv -debug +``` + +Output: + +![cli](docs/cli.png) diff --git a/cmd/tnp/main.go b/cmd/tnp/main.go new file mode 100644 index 0000000..07a3064 --- /dev/null +++ b/cmd/tnp/main.go @@ -0,0 +1,44 @@ +package main + +import ( + "encoding/json" + "flag" + "fmt" + "os" + + tnp "github.com/ProfChaos/torrent-name-parser" +) + +var ( + flags = flag.NewFlagSet("tnp", flag.ExitOnError) + debug = flags.Bool("debug", false, "Debug the parser") +) + +func main() { + if len(os.Args) < 2 { + fmt.Println("Usage: tnp [-debug]") + return + } + + err := flags.Parse(os.Args[2:]) + if err != nil { + panic(err) + } + + if debug != nil && *debug { + tnp.DebugParser(os.Args[1]) + return + } + + torrent, err := tnp.ParseName(os.Args[1]) + if err != nil { + panic(err) + } + + b, err := json.Marshal(torrent) + if err != nil { + panic(err) + } + + fmt.Println(string(b)) +} diff --git a/docs/cli.png b/docs/cli.png new file mode 100644 index 0000000..630f2f1 Binary files /dev/null and b/docs/cli.png differ diff --git a/go.mod b/go.mod index f10200e..da41b3a 100644 --- a/go.mod +++ b/go.mod @@ -1,11 +1,8 @@ module github.com/ProfChaos/torrent-name-parser -go 1.20 +go 1.21 -require ( - github.com/stretchr/testify v1.8.2 - golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 -) +require github.com/stretchr/testify v1.8.4 require ( github.com/davecgh/go-spew v1.1.1 // indirect diff --git a/go.sum b/go.sum index 66999ab..fa4b6e6 100644 --- a/go.sum +++ b/go.sum @@ -1,19 +1,10 @@ -github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= -github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= -github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53 h1:5llv2sWeaMSnA3w2kS57ouQQ4pudlXrR0dCgw51QK9o= -golang.org/x/exp v0.0.0-20230425010034-47ecfdc1ba53/go.mod h1:V1LtkGg67GoY2N1AnLN78QLrzxkLyJw7RJb1gzOOz9w= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/misc.go b/misc.go index faf49b8..2a5245f 100644 --- a/misc.go +++ b/misc.go @@ -2,8 +2,7 @@ package torrentparser import ( "regexp" - - "golang.org/x/exp/slices" + "slices" ) var ( diff --git a/parser.go b/parser.go index d767a3a..0b1e97c 100644 --- a/parser.go +++ b/parser.go @@ -293,7 +293,6 @@ func (p *parser) parseNumber(attr string, loc []int, options FindNumberOptions) number, err := strconv.Atoi(lastName) if err != nil { - fmt.Println("FindNumber:", err) return options.NilValue } @@ -323,7 +322,6 @@ func (p *parser) parseNumbers(attr string, loc [][]int, options FindNumbersOptio for i, n := range names { number, err := strconv.Atoi(n) if err != nil { - fmt.Println("FindNumber:", err) return options.NilValue } numbers[i] = number diff --git a/parser_test.go b/parser_test.go index 1aed984..6173cf1 100644 --- a/parser_test.go +++ b/parser_test.go @@ -494,3 +494,7 @@ func TestTorrentScanAndValue(t *testing.T) { } } + +func TestDebugParser(t *testing.T) { + DebugParser("Star.Wars.Episode.IX.The.Rise.of.Skywalker.2019.2160p.WEB-DL.DDP5.1.Atmos.HEVC-BLUTONiUM.mkv") +}