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 /web | |
| parent | 4a254f2dbf54b84945abf403175cc844be4818e2 (diff) | |
| download | x-1b363b0bcbae86ad789285193a6630efadeca3e2.tar.xz x-1b363b0bcbae86ad789285193a6630efadeca3e2.zip | |
import parsetorrentname
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'web')
91 files changed, 1172 insertions, 0 deletions
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 +[library](https://github.com/jzjzjzj/parse-torrent-name) written in +javascript. + +Extract all possible media information present in filenames. Multiple regex +rules are applied on filename string each of which extracts correponding +information from the filename. If a regex rule matches, the corresponding part +is removed from the filename. In the end, the remaining part is taken as the +title of the content. + +## Why? + +Online APIs by providers like +[TMDb](https://www.themoviedb.org/documentation/api), +[TVDb](http://thetvdb.com/wiki/index.php?title=Programmers_API) and +[OMDb](http://www.omdbapi.com/) don't react to well to search +queries which include any kind of extra information. To get proper results from +these APIs, only the title of the content should be provided as the search +query where this library comes into play. The accuracy of the results can be +improved by passing in the year which can also be extracted using this library. + +## Usage + +```go +import PTN + +info = PTN.parse('A freakishly cool movie or TV episode') + +print info # All details that were parsed +``` + +PTN works well for both movies and TV episodes. All meaningful information is +extracted and returned together in a dictionary. The text which could not be +parsed is returned in the `excess` field. + +### Movies + +```py +PTN.parse('San Andreas 2015 720p WEB-DL x264 AAC-JYK') +# { +# 'group': 'JYK', +# 'title': 'San Andreas', +# 'resolution': '720p', +# 'codec': 'x264', +# 'year': '2015', +# 'audio': 'AAC', +# 'quality': 'WEB-DL' +# } + +PTN.parse('The Martian 2015 540p HDRip KORSUB x264 AAC2 0-FGT') +# { +# 'group': '0-FGT', +# 'title': 'The Martian', +# 'resolution': '540p', +# 'excess': ['KORSUB', '2'], +# 'codec': 'x264', +# 'year': 2015, +# 'audio': 'AAC', +# 'quality': 'HDRip' +# } +``` + +### TV episodes + +```py +PTN.parse('Mr Robot S01E05 HDTV x264-KILLERS[ettv]') +# { +# 'episode': 5, +# 'season': 1, +# 'title': 'Mr Robot', +# 'codec': 'x264', +# 'group': 'KILLERS[ettv]' +# 'quality': 'HDTV' +# } + +PTN.parse('friends.s02e01.720p.bluray-sujaidr') +# { +# 'episode': 1, +# 'season': 2, +# 'title': 'friends', +# 'resolution': '720p', +# 'group': 'sujaidr', +# 'quality': 'bluray' +# } +``` + +### Note + +PTN does not garantee the fields `group`, `excess` and `episodeName` as these +fields might be interchanged with each other. This shoudn't affect most +applications since episode name can be fetched from an online database +after getting the season and episode number correctly. + +### Parts extracted + +* audio +* codec +* container +* episode +* episodeName +* excess +* extended +* garbage +* group +* hardcoded +* language +* proper +* quality +* region +* repack +* resolution +* season +* title +* website +* widescreen +* year + +## Install + +### Automatic + +PTN can be installed using `go get`. + +```sh +$ go get github.com/middelink/go-parse-torrent-name +``` + +### Manual + +First clone the repository. + +```sh +$ git clone https://github.com/middelink/go-parse-torrent-name PTN && cd PTN +``` + +And run the command for installing the package. + +```sh +$ go install . +``` + +## Contributing + +Take a look at the open +[issues](https://github.com/jzjzjzj/parse-torrent-name/issues) on the original +project and submit a PR! + +## License + +MIT © [Pauline Middelink](http://www.polyware.nl/~middelink) diff --git a/web/parsetorrentname/parser.go b/web/parsetorrentname/parser.go new file mode 100644 index 0000000..99316f2 --- /dev/null +++ b/web/parsetorrentname/parser.go @@ -0,0 +1,100 @@ +package parsetorrentname + +import ( + "reflect" + "strconv" + "strings" +) + +// TorrentInfo is the resulting structure returned by Parse +type TorrentInfo struct { + Title string + Season int `json:"season,omitempty"` + Episode int `json:"episode,omitempty"` + Year int `json:"year,omitempty"` + Resolution string `json:"resolution,omitempty"` + Quality string `json:"quality,omitempty"` + Codec string `json:"codec,omitempty"` + Audio string `json:"audio,omitempty"` + Group string `json:"group,omitempty"` + Region string `json:"region,omitempty"` + Extended bool `json:"extended,omitempty"` + Hardcoded bool `json:"hardcoded,omitempty"` + Proper bool `json:"proper,omitempty"` + Repack bool `json:"repack,omitempty"` + Container string `json:"container,omitempty"` + Widescreen bool `json:"widescreen,omitempty"` + Website string `json:"website,omitempty"` + Language string `json:"language,omitempty"` + Sbs string `json:"sbs,omitempty"` + Unrated bool `json:"unrated,omitempty"` + Size string `json:"size,omitempty"` + ThreeD bool `json:"3d,omitempty"` +} + +func setField(tor *TorrentInfo, field, raw, val string) { + ttor := reflect.TypeOf(tor) + torV := reflect.ValueOf(tor) + field = strings.Title(field) + v, _ := ttor.Elem().FieldByName(field) + //fmt.Printf(" field=%v, type=%+v, value=%v\n", field, v.Type, val) + switch v.Type.Kind() { + case reflect.Bool: + torV.Elem().FieldByName(field).SetBool(true) + case reflect.Int: + clean, _ := strconv.ParseInt(val, 10, 64) + torV.Elem().FieldByName(field).SetInt(clean) + case reflect.Uint: + clean, _ := strconv.ParseUint(val, 10, 64) + torV.Elem().FieldByName(field).SetUint(clean) + case reflect.String: + torV.Elem().FieldByName(field).SetString(val) + } +} + +// Parse breaks up the given filename in TorrentInfo +func Parse(filename string) (*TorrentInfo, error) { + tor := &TorrentInfo{} + //fmt.Printf("filename %q\n", filename) + + var startIndex, endIndex = 0, len(filename) + cleanName := strings.Replace(filename, "_", " ", -1) + for _, pattern := range patterns { + matches := pattern.re.FindAllStringSubmatch(cleanName, -1) + if len(matches) == 0 { + continue + } + matchIdx := 0 + if pattern.last { + // Take last occurence of element. + matchIdx = len(matches) - 1 + } + //fmt.Printf(" %s: pattern:%q match:%#v\n", pattern.name, pattern.re, matches[matchIdx]) + + index := strings.Index(cleanName, matches[matchIdx][1]) + if index == 0 { + startIndex = len(matches[matchIdx][1]) + //fmt.Printf(" startIndex moved to %d [%q]\n", startIndex, filename[startIndex:endIndex]) + } else if index < endIndex { + endIndex = index + //fmt.Printf(" endIndex moved to %d [%q]\n", endIndex, filename[startIndex:endIndex]) + } + setField(tor, pattern.name, matches[matchIdx][1], matches[matchIdx][2]) + } + + // Start process for title + //fmt.Println(" title: <internal>") + raw := strings.Split(filename[startIndex:endIndex], "(")[0] + cleanName = raw + if strings.HasPrefix(cleanName, "- ") { |
