Skip to content

Commit

Permalink
feature: cli and bump go version
Browse files Browse the repository at this point in the history
  • Loading branch information
ProfChaos committed Nov 3, 2023
1 parent 2a3d00f commit b2aebe3
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 22 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
44 changes: 44 additions & 0 deletions cmd/tnp/main.go
Original file line number Diff line number Diff line change
@@ -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 <torrent name> [-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))
}
Binary file added docs/cli.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 2 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
13 changes: 2 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
3 changes: 1 addition & 2 deletions misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package torrentparser

import (
"regexp"

"golang.org/x/exp/slices"
"slices"
)

var (
Expand Down
2 changes: 0 additions & 2 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

0 comments on commit b2aebe3

Please sign in to comment.