aboutsummaryrefslogtreecommitdiff
path: root/web/parsetorrentname/patterns.go
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/parsetorrentname/patterns.go
parent4a254f2dbf54b84945abf403175cc844be4818e2 (diff)
downloadx-1b363b0bcbae86ad789285193a6630efadeca3e2.tar.xz
x-1b363b0bcbae86ad789285193a6630efadeca3e2.zip
import parsetorrentname
Signed-off-by: Xe Iaso <me@xeiaso.net>
Diffstat (limited to 'web/parsetorrentname/patterns.go')
-rw-r--r--web/parsetorrentname/patterns.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/web/parsetorrentname/patterns.go b/web/parsetorrentname/patterns.go
new file mode 100644
index 0000000..a2e2328
--- /dev/null
+++ b/web/parsetorrentname/patterns.go
@@ -0,0 +1,54 @@
+package parsetorrentname
+
+import (
+ "fmt"
+ "os"
+ "reflect"
+ "regexp"
+)
+
+var patterns = []struct {
+ name string
+ // Use the last matching pattern. E.g. Year.
+ last bool
+ kind reflect.Kind
+ // REs need to have 2 sub expressions (groups), the first one is "raw", and
+ // the second one for the "clean" value.
+ // E.g. Epiode matching on "S01E18" will result in: raw = "E18", clean = "18".
+ re *regexp.Regexp
+}{
+ {"season", false, reflect.Int, regexp.MustCompile(`(?i)(s?([0-9]{1,2}))[ex]`)},
+ {"episode", false, reflect.Int, regexp.MustCompile(`(?i)([ex]([0-9]{2})(?:[^0-9]|$))`)},
+ {"episode", false, reflect.Int, regexp.MustCompile(`(-\s+([0-9]{1,})(?:[^0-9]|$))`)},
+ {"year", true, reflect.Int, regexp.MustCompile(`\b(((?:19[0-9]|20[0-9])[0-9]))\b`)},
+
+ {"resolution", false, reflect.String, regexp.MustCompile(`\b(([0-9]{3,4}p))\b`)},
+ {"quality", false, reflect.String, regexp.MustCompile(`(?i)\b(((?:PPV\.)?[HP]DTV|(?:HD)?CAM|B[DR]Rip|(?:HD-?)?TS|(?:PPV )?WEB-?DL(?: DVDRip)?|HDRip|DVDRip|DVDRIP|CamRip|W[EB]BRip|BluRay|DvDScr|telesync))\b`)},
+ {"codec", false, reflect.String, regexp.MustCompile(`(?i)\b((xvid|[hx]\.?26[45]))\b`)},
+ {"audio", false, reflect.String, regexp.MustCompile(`(?i)\b((MP3|DD5\.?1|Dual[\- ]Audio|LiNE|DTS|AAC[.-]LC|AAC(?:\.?2\.0)?|AC3(?:\.5\.1)?))\b`)},
+ {"region", false, reflect.String, regexp.MustCompile(`(?i)\b(R([0-9]))\b`)},
+ {"size", false, reflect.String, regexp.MustCompile(`(?i)\b((\d+(?:\.\d+)?(?:GB|MB)))\b`)},
+ {"website", false, reflect.String, regexp.MustCompile(`^(\[ ?([^\]]+?) ?\])`)},
+ {"language", false, reflect.String, regexp.MustCompile(`(?i)\b((rus\.eng|ita\.eng))\b`)},
+ {"sbs", false, reflect.String, regexp.MustCompile(`(?i)\b(((?:Half-)?SBS))\b`)},
+ {"container", false, reflect.String, regexp.MustCompile(`(?i)\b((MKV|AVI|MP4))\b`)},
+
+ {"group", false, reflect.String, regexp.MustCompile(`\b(- ?([^-]+(?:-={[^-]+-?$)?))$`)},
+
+ {"extended", false, reflect.Bool, regexp.MustCompile(`(?i)\b(EXTENDED(:?.CUT)?)\b`)},
+ {"hardcoded", false, reflect.Bool, regexp.MustCompile(`(?i)\b((HC))\b`)},
+ {"proper", false, reflect.Bool, regexp.MustCompile(`(?i)\b((PROPER))\b`)},
+ {"repack", false, reflect.Bool, regexp.MustCompile(`(?i)\b((REPACK))\b`)},
+ {"widescreen", false, reflect.Bool, regexp.MustCompile(`(?i)\b((WS))\b`)},
+ {"unrated", false, reflect.Bool, regexp.MustCompile(`(?i)\b((UNRATED))\b`)},
+ {"threeD", false, reflect.Bool, regexp.MustCompile(`(?i)\b((3D))\b`)},
+}
+
+func init() {
+ for _, pat := range patterns {
+ if pat.re.NumSubexp() != 2 {
+ fmt.Printf("Pattern %q does not have enough capture groups. want 2, got %d\n", pat.name, pat.re.NumSubexp())
+ os.Exit(1)
+ }
+ }
+}