diff options
| author | Xe Iaso <me@xeiaso.net> | 2023-07-29 13:29:40 -0400 |
|---|---|---|
| committer | Xe Iaso <me@xeiaso.net> | 2023-07-29 13:29:46 -0400 |
| commit | 1b363b0bcbae86ad789285193a6630efadeca3e2 (patch) | |
| tree | 3f8179d0e0b5ce159d69b673cb5cdce41eacb85f | |
| parent | 4a254f2dbf54b84945abf403175cc844be4818e2 (diff) | |
| download | x-1b363b0bcbae86ad789285193a6630efadeca3e2.tar.xz x-1b363b0bcbae86ad789285193a6630efadeca3e2.zip | |
import parsetorrentname
Signed-off-by: Xe Iaso <me@xeiaso.net>
94 files changed, 1186 insertions, 83 deletions
diff --git a/cmd/sanguisuga/main.go b/cmd/sanguisuga/main.go index 069962c..9ae145b 100644 --- a/cmd/sanguisuga/main.go +++ b/cmd/sanguisuga/main.go @@ -20,6 +20,7 @@ import ( "tailscale.com/hostinfo" "tailscale.com/jsondb" "within.website/x/internal" + "within.website/x/web/parsetorrentname" ) var ( @@ -27,76 +28,8 @@ var ( tysonConfig = flag.String("tyson-config", "./config.ts", "path to configuration secrets (TySON)") annRegex = regexp.MustCompile(`^New Torrent Announcement: <([^>]*)>\s+Name:'(.*)' uploaded by '.*' ?(freeleech)?\s+-\s+https://\w+.\w+.\w+./\w+./([0-9]+)$`) - showName = regexp.MustCompile(`^(.*)\s+(S[0-9]+E[0-9]+)\s+([0-9]+p)\s+(\w+)\s+(.*)$`) ) -type ShowMeta struct { - Name string - SeasonEpisode *SeasonEpisode - Quality string - Kind string - Group string -} - -func (sm ShowMeta) StateKey() string { - return fmt.Sprintf("%s %s", sm.Name, sm.SeasonEpisode) -} - -func ParseShowMeta(input string) (*ShowMeta, error) { - match := showName.FindStringSubmatch(input) - - if match == nil { - return nil, fmt.Errorf("invalid input for TV show name: %q", input) - } - - result := ShowMeta{ - Name: strings.TrimSpace(match[1]), - Quality: match[3], - Kind: match[4], - Group: match[5], - } - - se, err := ParseSeasonEpisode(match[2]) - if err != nil { - return nil, err - } - - result.SeasonEpisode = se - - return &result, nil -} - -type SeasonEpisode struct { - Season string - Episode string -} - -func (se SeasonEpisode) GetFormattedSeason() string { - return "Season " + se.Season -} - -func (se *SeasonEpisode) String() string { - return "S" + se.Season + "E" + se.Episode -} - -func ParseSeasonEpisode(input string) (*SeasonEpisode, error) { - re := regexp.MustCompile(`S([0-9]+)E([0-9]+)`) - match := re.FindStringSubmatch(input) - - if match == nil { - return nil, fmt.Errorf("invalid input for SeasonEpisode: %q", input) - } - - season := match[1] - episode := match[2] - se := &SeasonEpisode{ - Season: season, - Episode: episode, - } - - return se, nil -} - func ConvertURL(torrentID, rssKey, name string) string { name = strings.ReplaceAll(name, " ", ".") + ".torrent" return fmt.Sprintf("https://www.torrentleech.org/rss/download/%s/%s/%s", torrentID, rssKey, name) @@ -212,13 +145,15 @@ func (s *Sanguisuga) HandleIRCMessage(ev *irc.Event) { slog.Debug("found torrent announcment", "category", ta.Category, "freeleech", ta.Freeleech, "name", ta.Name) if ta.Category == "TV :: Episodes HD" { - sm, err := ParseShowMeta(ta.Name) + ti, err := parsetorrentname.Parse(ta.Name) if err != nil { slog.Debug("can't parse ShowMeta", "err", err, "name", ta.Name) return } - id := sm.SeasonEpisode.String() - slog.Debug("found ShowMeta", "title", sm.Name, "id", id, "quality", sm.Quality, "group", sm.Group) + id := fmt.Sprintf("S%2dE%2d", ti.Season, ti.Episode) + slog.Debug("found ShowMeta", "title", ti.Title, "id", id, "quality", ti.Resolution, "group", ti.Group) + + stateKey := fmt.Sprintf("%s %d", ti.Title, id) for _, show := range s.Config.Shows { if s.db.Data == nil { @@ -226,25 +161,25 @@ func (s *Sanguisuga) HandleIRCMessage(ev *irc.Event) { Seen: map[string]TorrentAnnouncement{}, } } - if _, found := s.db.Data.Seen[sm.StateKey()]; found { - slog.Info("already snatched", "title", sm.Name, "id", id) + if _, found := s.db.Data.Seen[stateKey]; found { + slog.Info("already snatched", "title", ti.Title, "id", id) return } - if show.Title != sm.Name { + if show.Title != ti.Title { slog.Debug("wrong name") continue } - if show.Quality != sm.Quality { - slog.Debug("wrong quality") + if show.Quality != ti.Resolution { + slog.Debug("wrong resolution") continue } torrentURL := ConvertURL(ta.TorrentID, s.Config.RSSKey, ta.Name) slog.Debug("found url", "url", torrentURL) - downloadDir := filepath.Join(show.DiskPath, sm.SeasonEpisode.GetFormattedSeason()) + downloadDir := filepath.Join(show.DiskPath, fmt.Sprintf("Season %2d", ti.Season)) var buf bytes.Buffer resp, err := http.Get(torrentURL) @@ -278,9 +213,9 @@ func (s *Sanguisuga) HandleIRCMessage(ev *irc.Event) { return } - slog.Info("added torrent", "title", sm.Name, "id", id, "path", downloadDir, "infohash", t.Hash, "dupe", dupe) + slog.Info("added torrent", "title", ti.Title, "id", id, "path", downloadDir, "infohash", t.Hash, "dupe", dupe) - s.db.Data.Seen[sm.StateKey()] = *ta + s.db.Data.Seen[stateKey] = *ta if err := s.db.Save(); err != nil { slog.Error("error saving state", "err", err) } @@ -61,8 +61,6 @@ require ( github.com/goccy/go-json v0.10.2 // indirect github.com/gogs/chardet v0.0.0-20211120154057-b7413eaefb8f // indirect github.com/google/nftables v0.1.1-0.20230115205135-9aa6fdf5a28c // indirect - github.com/hashicorp/go-cleanhttp v0.5.2 // indirect - github.com/hekmon/cunits/v2 v2.1.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect github.com/jackc/puddle/v2 v2.2.0 // indirect @@ -340,7 +340,6 @@ github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFb github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I= github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= -github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-multierror v1.0.0/go.mod h1:dHtQlpGsu+cZNNAkkCN/P3hoUDHhCYQXV3UM06sGGrk= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= @@ -348,7 +347,6 @@ github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8= github.com/hdevalence/ed25519consensus v0.1.0 h1:jtBwzzcHuTmFrQN6xQZn6CQEO/V9f7HsjsjeEZ6auqU= github.com/hdevalence/ed25519consensus v0.1.0/go.mod h1:w3BHWjwJbFU29IRHL1Iqkw3sus+7FctEyM4RqDxYNzo= -github.com/hekmon/cunits/v2 v2.1.0/go.mod h1:9r1TycXYXaTmEWlAIfFV8JT+Xo59U96yUJAYHxzii2M= github.com/hullerob/go.farbfeld v0.0.0-20181222022525-3661193c725f h1:1LkiAnH6RhOEbQAcfcEcixM5IsegqFi6IH0Nz0ZGqYs= github.com/hullerob/go.farbfeld v0.0.0-20181222022525-3661193c725f/go.mod h1:mQEoc766DxPTAwQ54neWTK/lFqIeSO7OU6bqZsceglw= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= diff --git a/web/parsetorrentname/.#parser.go b/web/parsetorrentname/.#parser.go new file mode 120000 index 0000000..67b910b --- /dev/null +++ b/web/parsetorrentname/.#parser.go @@ -0,0 +1 @@ +cadey@pneuma.62020:1690585730
\ No newline at end of file diff --git a/web/parsetorrentname/.gitignore b/web/parsetorrentname/.gitignore new file mode 100644 index 0000000..a1338d6 --- /dev/null +++ b/web/parsetorrentname/.gitignore @@ -0,0 +1,14 @@ +# Binaries for programs and plugins +*.exe +*.dll +*.so +*.dylib + +# Test binary, build with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736 +.glide/ diff --git a/web/parsetorrentname/.travis.yml b/web/parsetorrentname/.travis.yml new file mode 100644 index 0000000..35976ef --- /dev/null +++ b/web/parsetorrentname/.travis.yml @@ -0,0 +1,19 @@ +nguage: go + +go: + - 1.7.x + - 1.8.x + - master + +branches: + only: + - master + +before_install: + - go get github.com/mattn/goveralls + +script: + - go vet -v . + - go build -v . + - go test -v -covermode=count -coverprofile=coverage.out + - $HOME/gopath/bin/goveralls -coverprofile=coverage.out -service=travis-ci diff --git a/web/parsetorrentname/LICENSE b/web/parsetorrentname/LICENSE new file mode 100644 index 0000000..462fc6d --- /dev/null +++ b/web/parsetorrentname/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Pauline Middelink + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/web/parsetorrentname/README.md b/web/parsetorrentname/README.md new file mode 100644 index 0000000..75d4288 --- /dev/null +++ b/web/parsetorrentname/README.md @@ -0,0 +1,160 @@ +# parse-torrent-name + +[](https://godoc.org/github.com/middelink/go-parse-torrent-name) +[](https://github.com/middelink/go-parse-torrent-name/blob/master/LICENSE) +[](https://travis-ci.org/middelink/go-parse-torrent-name) +[](https://coveralls.io/github/middelink/go-parse-torrent-name?branch=master) +[](https://goreportcard.com/report/github.com/middelink/go-parse-torrent-name) + +> Extract media information from torrent-like filename + +A Go port of [Jānis](https://github.com/jzjzjzj)' awesome |
