aboutsummaryrefslogtreecommitdiff
path: root/web
diff options
context:
space:
mode:
authorXe Iaso <me@xeiaso.net>2023-07-29 13:29:40 -0400
committerXe Iaso <me@xeiaso.net>2023-07-29 13:29:46 -0400
commit1b363b0bcbae86ad789285193a6630efadeca3e2 (patch)
tree3f8179d0e0b5ce159d69b673cb5cdce41eacb85f /web
parent4a254f2dbf54b84945abf403175cc844be4818e2 (diff)
downloadx-1b363b0bcbae86ad789285193a6630efadeca3e2.tar.xz
x-1b363b0bcbae86ad789285193a6630efadeca3e2.zip
import parsetorrentname
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'web')
l---------web/parsetorrentname/.#parser.go1
-rw-r--r--web/parsetorrentname/.gitignore14
-rw-r--r--web/parsetorrentname/.travis.yml19
-rw-r--r--web/parsetorrentname/LICENSE21
-rw-r--r--web/parsetorrentname/README.md160
-rw-r--r--web/parsetorrentname/parser.go100
-rw-r--r--web/parsetorrentname/parser_test.go138
-rw-r--r--web/parsetorrentname/patterns.go54
-rw-r--r--web/parsetorrentname/testdata/golden_file_000.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_001.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_002.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_003.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_004.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_005.json10
-rw-r--r--web/parsetorrentname/testdata/golden_file_006.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_007.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_008.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_009.json6
-rw-r--r--web/parsetorrentname/testdata/golden_file_010.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_011.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_012.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_013.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_014.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_015.json5
-rw-r--r--web/parsetorrentname/testdata/golden_file_016.json10
-rw-r--r--web/parsetorrentname/testdata/golden_file_017.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_018.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_019.json6
-rw-r--r--web/parsetorrentname/testdata/golden_file_020.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_021.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_022.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_023.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_024.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_025.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_026.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_027.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_028.json5
-rw-r--r--web/parsetorrentname/testdata/golden_file_029.json4
-rw-r--r--web/parsetorrentname/testdata/golden_file_030.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_031.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_032.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_033.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_034.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_035.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_036.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_037.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_038.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_039.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_040.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_041.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_042.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_043.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_044.json6
-rw-r--r--web/parsetorrentname/testdata/golden_file_045.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_046.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_047.json10
-rw-r--r--web/parsetorrentname/testdata/golden_file_048.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_049.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_050.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_051.json6
-rw-r--r--web/parsetorrentname/testdata/golden_file_052.json11
-rw-r--r--web/parsetorrentname/testdata/golden_file_053.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_054.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_055.json10
-rw-r--r--web/parsetorrentname/testdata/golden_file_056.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_057.json5
-rw-r--r--web/parsetorrentname/testdata/golden_file_058.json10
-rw-r--r--web/parsetorrentname/testdata/golden_file_059.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_060.json5
-rw-r--r--web/parsetorrentname/testdata/golden_file_061.json10
-rw-r--r--web/parsetorrentname/testdata/golden_file_062.json10
-rw-r--r--web/parsetorrentname/testdata/golden_file_063.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_064.json11
-rw-r--r--web/parsetorrentname/testdata/golden_file_065.json11
-rw-r--r--web/parsetorrentname/testdata/golden_file_066.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_067.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_068.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_069.json6
-rw-r--r--web/parsetorrentname/testdata/golden_file_070.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_071.json10
-rw-r--r--web/parsetorrentname/testdata/golden_file_072.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_073.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_074.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_075.json8
-rw-r--r--web/parsetorrentname/testdata/golden_file_076.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_077.json7
-rw-r--r--web/parsetorrentname/testdata/golden_file_078.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_079.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_080.json6
-rw-r--r--web/parsetorrentname/testdata/golden_file_081.json9
-rw-r--r--web/parsetorrentname/testdata/golden_file_082.json8
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
+
+[![GoDoc](https://godoc.org/github.com/middelink/go-parse-torrent-name?status.svg)](https://godoc.org/github.com/middelink/go-parse-torrent-name)
+[![License](https://img.shields.io/github/license/middelink/go-parse-torrent-name.svg)](https://github.com/middelink/go-parse-torrent-name/blob/master/LICENSE)
+[![Build Status](https://travis-ci.org/middelink/go-parse-torrent-name.svg?branch=master)](https://travis-ci.org/middelink/go-parse-torrent-name)
+[![Coverage Status](https://coveralls.io/repos/github/middelink/go-parse-torrent-name/badge.svg?branch=master)](https://coveralls.io/github/middelink/go-parse-torrent-name?branch=master)
+[![Go Report Card](https://goreportcard.com/badge/github.com/middelink/go-parse-torrent-name)](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, "- ") {