Process function is completed . still needs testing
cleaned up structs and constants a little
This commit is contained in:
parent
f3054da51b
commit
417aa0546c
81
type.go
81
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user