From 417aa0546cdb9dc7fa963adfe4299303a05d5da7 Mon Sep 17 00:00:00 2001 From: lordwelch Date: Mon, 19 Jun 2017 00:27:17 -0700 Subject: [PATCH] Process function is completed . still needs testing cleaned up structs and constants a little --- type.go | 81 ++++++++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 69 insertions(+), 12 deletions(-) diff --git a/type.go b/type.go index f94500a..0dd2eda 100644 --- a/type.go +++ b/type.go @@ -1,6 +1,8 @@ package main import ( + "io" + "regexp" "strings" "github.com/zeebo/bencode" @@ -8,16 +10,13 @@ import ( type Src int type Fmt int -type Std int const ( HDTV Src = iota CAM DVD X264 Fmt = iota - Xvid - Ntsc Std = iota - Pal + XVID ) type MetaTorrent struct { @@ -46,18 +45,16 @@ type Torrent struct { type TorrentVideo struct { *Torrent + Episode string + Season string Release string Source Src Format Fmt - Standard Std - Retail bool Proper bool Internal bool - Dl bool - Recode bool Repack bool Nuked bool - p720 bool + P720 bool } func NewTorrent(mt MetaTorrent) (T *Torrent) { @@ -78,7 +75,67 @@ func NewTorrent(mt MetaTorrent) (T *Torrent) { T.Creator = mt.CreatedBy } -func (T TorrentVideo) Process() { - reader := strings.NewReader(T.Name) - +func (Mt *MetaTorrent) Load(r io.Reader) error { + return bencode.NewDecoder(r).Decode(Mt) +} + +func (T *TorrentVideo) Process() error { + var ( + err error + r rune + exit, tag = bool + str string + i int + re = [...]regexp.Regexp{regexp.MustCompile(`[Ss](\d{2})[Ee](\d{2})`), regexp.MustCompile(`([A-Za-z]{3-10})\[([A-Z]{4-6})\]`)} + ) + reader := strings.NewReader(T.Name) + for err == nil && !exit { + for err == nil && r != '.' && r != '-' { + r, _, err = reader.ReadRune() + if err != nil { + return err + } + if r != '.' && r != '-' { + str += string(r) + } + } + if tag { + switch str { + case "NUKED": + T.Nuked = true + case "INTERNAL": + T.Internal = true + case "REPACK": + T.Repack = true + case "x264", "H", "264": + T.Format = X264 + case "XviD", "DivX": + T.Format = XVID + case "720p": + T.P720 = true + case "PROPER", "READ", "NFO": + T.Proper = true + case "INTERNAL": + T.Internal = true + case "HDTV", "DVDRip": + T.Source = HDTV + case "CAM": + T.Source = CAM + case "DVD": + T.Source = DVD + } + switch { + case re[0].Match(str): + tag = true + match := re[1].FindStringSubmatch(str) + T.Season = match[1] + T.Episode = match[2] + case re[1].Match(str): + match := re[1].FindStringSubmatch(str) + T.Release = match[1] + T.Creator = match[2] + } + } + } + return nil }