Finish switch to map for tags
Find date for media first then stick everything before in Title update main.go
This commit is contained in:
parent
2a11ab068e
commit
2ba1250a27
31
main.go
31
main.go
@ -15,32 +15,31 @@ var (
|
||||
)
|
||||
|
||||
func main() {
|
||||
var args struct {
|
||||
P720 bool `arg:"-7,help:Do not select 720p file if another exists."`
|
||||
NUKED bool `arg:"-N,help:Allow NUKED files."`
|
||||
DIVX bool `arg:"help:Prefer DivX encoding if available. Default x264"`
|
||||
PROPER bool `arg:"help:Do not prefer PROPER FILES."`
|
||||
INTERNAL bool `arg:"help:Prefer INTERNAL files."`
|
||||
RELEASE string `arg:"-r,help:Release group preference order. Comma seperated."`
|
||||
SHOW []string `arg:"positional,help:TV show to download"`
|
||||
NEW bool `arg:"-n,help:Only modify new torrents"`
|
||||
PATH string `arg:"-P,help:Path to torrent files"`
|
||||
}
|
||||
var (
|
||||
err error
|
||||
args struct {
|
||||
RES string `arg:"help:Resolution preference [480/720/1080]"`
|
||||
RELEASE []string `arg:"-r,help:Release group preference order."`
|
||||
Series []string `arg:"required,positional,help:TV series to download"`
|
||||
NEW bool `arg:"-n,help:Only modify new torrents"`
|
||||
PATH string `arg:"-P,help:Path to torrent files"`
|
||||
}
|
||||
)
|
||||
arg.MustParse(&args)
|
||||
scanner := bufio.NewScanner(os.Stdin)
|
||||
for err == nil {
|
||||
if !scanner.scan() {
|
||||
if !scanner.Scan() {
|
||||
panic("fail")
|
||||
}
|
||||
exec.Command("wget", scanner.Text(), "-o", args.PATH+'/')
|
||||
process(args.PATH + '/' + path.Base(scanner.Text()))
|
||||
exec.Command("wget", scanner.Text(), "-o", args.PATH+"/")
|
||||
process(args.PATH + "/" + path.Base(scanner.Text()))
|
||||
}
|
||||
}
|
||||
|
||||
func process(torrentFile string) *VideoTorrent {
|
||||
func process(torrentFile string) *MediaTorrent {
|
||||
var (
|
||||
mt *MetaTorrent = new(MetaTorrent)
|
||||
vt *VideoTorrent = new(VideoTorrent)
|
||||
vt *MediaTorrent = new(MediaTorrent)
|
||||
)
|
||||
f, _ := os.OpenFile(torrentFile, os.O_RDONLY, 755)
|
||||
mt.Load(f)
|
||||
|
125
type.go
125
type.go
@ -27,7 +27,7 @@ const (
|
||||
const (
|
||||
P480 Res = iota + 1
|
||||
P720
|
||||
P2080
|
||||
P1080
|
||||
I1080
|
||||
)
|
||||
|
||||
@ -54,47 +54,43 @@ type Torrent struct {
|
||||
Name string
|
||||
Comment string
|
||||
Creator string
|
||||
size int64
|
||||
Size int64
|
||||
}
|
||||
|
||||
type MediaTorrent struct {
|
||||
Torrent
|
||||
Title string
|
||||
Format Fmt
|
||||
Source Src
|
||||
Date string
|
||||
Tags map[string]bool //ALTERNATIVE.CUT, CONVERT, COLORIZED, DC, DIRFIX, DUBBED, EXTENDED, FINAL, INTERNAL, NFOFIX, OAR, OM, PPV, PROPER, REAL, REMASTERED, READNFO, REPACK, RERIP, SAMPLEFIX, SOURCE.SAMPLE, SUBBED, UNCENSORED, UNRATED, UNCUT, WEST.FEED, and WS
|
||||
Title string
|
||||
Format Fmt
|
||||
Source Src
|
||||
Date string
|
||||
Release string
|
||||
Tags map[string]bool //ALTERNATIVE.CUT, CONVERT, COLORIZED, DC, DIRFIX, DUBBED, EXTENDED, FINAL, INTERNAL, NFOFIX, OAR, OM, PPV, PROPER, REAL, REMASTERED, READNFO, REPACK, RERIP, SAMPLEFIX, SOURCE.SAMPLE, SUBBED, UNCENSORED, UNRATED, UNCUT, WEST.FEED, and WS
|
||||
Episode string
|
||||
Season string
|
||||
Resolution Res
|
||||
}
|
||||
|
||||
type EpisodeTorrent struct {
|
||||
VT []MediaTorrent
|
||||
Episode string
|
||||
Season string
|
||||
}
|
||||
type EpisodeTorrent []MediaTorrent
|
||||
|
||||
type SeriesTorrent struct {
|
||||
Episodes []EpisodeTorrent
|
||||
title string
|
||||
}
|
||||
type SeriesTorrent []EpisodeTorrent
|
||||
|
||||
type Interface interface {
|
||||
type SeriesInterface interface {
|
||||
Title() string
|
||||
}
|
||||
|
||||
func NewTorrent(mt MetaTorrent) (T *Torrent) {
|
||||
T = new(Torrent)
|
||||
func NewTorrent(mt MetaTorrent) (T Torrent) {
|
||||
if mt.Info.Length == 0 {
|
||||
for i, path := range mt.Info.Files {
|
||||
for _, file := range path.Path {
|
||||
if file[len(file)-3:] == "mkv" || file[len(file)-3:] == "mp4" {
|
||||
T.size = mt.Info.Files[i].Length
|
||||
T.Size = mt.Info.Files[i].Length
|
||||
T.Name = file
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
T.Name = mt.Info.Name
|
||||
T.size = mt.Info.Length
|
||||
T.Size = mt.Info.Length
|
||||
}
|
||||
T.Comment = mt.Comment
|
||||
T.Creator = mt.CreatedBy
|
||||
@ -106,65 +102,67 @@ func (Mt *MetaTorrent) Load(r io.Reader) error {
|
||||
return bencode.NewDecoder(r).Decode(Mt)
|
||||
}
|
||||
|
||||
func (T *MediaTorrent) Process() error {
|
||||
func (T *MediaTorrent) Process() {
|
||||
var (
|
||||
err error
|
||||
r rune
|
||||
exit, tag, year, month bool
|
||||
dateIndex
|
||||
indexes []integer
|
||||
//str string
|
||||
re = [4]*regexp.Regexp{regexp.MustCompile(`^[s](\d{2})[s](\d{2})$`), regexp.MustCompile(`^\d{4}$`), regexp.MustCompile(`^\d\d$`), regexp.MustCompile(`^([A-Za-z]{3,10})\[([A-Za-z]{4,6})\]$`)}
|
||||
date, tag, year, month bool
|
||||
dateIndex int
|
||||
indexes []int
|
||||
re = [3]*regexp.Regexp{regexp.MustCompile(`^[s](\d{2})[s](\d{2})$`), regexp.MustCompile(`^\d{4}$`), regexp.MustCompile(`^\d\d$`)}
|
||||
)
|
||||
strs := strings.Split(T.Name)
|
||||
strs := strings.Split(T.Name, ".")
|
||||
for i, str := range strs {
|
||||
if re[1].MatchString(strings.ToLower(str)) {
|
||||
indexes = append(indexes, i)
|
||||
}
|
||||
}
|
||||
|
||||
if len(indexes) > 0 {
|
||||
T.Date = indexes[len(indexes)-1]
|
||||
dateIndex = indexes[len(indexes)-1]
|
||||
}
|
||||
|
||||
for i, str := range strs {
|
||||
fmt.Println(str)
|
||||
if tag {
|
||||
T.tag(str)
|
||||
if i == len(strs)-1 && strings.Contains(str, "-") {
|
||||
tags := strings.Split(str, "-")
|
||||
T.tag(tags[0])
|
||||
eztv := strings.Split(tags, "[")
|
||||
T.Release = eztv[0]
|
||||
T.Creator = eztv[1][:len(eztv[1])-1]
|
||||
str = tags[0]
|
||||
if strings.Contains(tags[1], "[") {
|
||||
eztv := strings.Split(tags[1], "[")
|
||||
T.Release = eztv[0]
|
||||
T.Creator = eztv[1][:len(eztv[1])-2]
|
||||
} else {
|
||||
T.Release = tags[1]
|
||||
}
|
||||
}
|
||||
T.tag(str)
|
||||
} else {
|
||||
switch {
|
||||
case year:
|
||||
year = false
|
||||
if re[2].MatchString(strings.ToLower(str)) {
|
||||
month = true
|
||||
T.Date += "." + str
|
||||
continue
|
||||
}
|
||||
if re[1].MatchString(strings.ToLower(str)) {
|
||||
T.Title += T.Date
|
||||
T.Date = str
|
||||
case i == dateIndex:
|
||||
T.Date = str
|
||||
date = true
|
||||
year = true
|
||||
case date:
|
||||
switch {
|
||||
case year:
|
||||
year = false
|
||||
if re[2].MatchString(strings.ToLower(str)) {
|
||||
month = true
|
||||
T.Date += "." + str
|
||||
continue
|
||||
}
|
||||
date = false
|
||||
T.tag(str)
|
||||
tag = true
|
||||
case month:
|
||||
T.Date += "." + str
|
||||
date = false
|
||||
tag = true
|
||||
continue
|
||||
}
|
||||
T.tag(str)
|
||||
T.Title += " " + str
|
||||
case month:
|
||||
T.Date += "." + str
|
||||
tag = true
|
||||
case re[0].MatchString(strings.ToLower(str)):
|
||||
tag = true
|
||||
match := re[0].FindStringSubmatch(strings.ToLower(str))
|
||||
T.Season = match[1]
|
||||
T.Episode = match[2]
|
||||
case re[1].MatchString(strings.ToLower(str)):
|
||||
year = true
|
||||
T.Date = str
|
||||
continue
|
||||
default:
|
||||
T.Title += " " + str
|
||||
}
|
||||
@ -172,17 +170,22 @@ func (T *MediaTorrent) Process() error {
|
||||
}
|
||||
|
||||
T.Title = strings.TrimSpace(T.Title)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (T *MediaTorrent) tag(str string) {
|
||||
switch strings.ToLower(str) {
|
||||
case "x264", "h", "264", "h264", "h264":
|
||||
case "x264", "h", "264", "h264":
|
||||
T.Format = X264
|
||||
case "xvid", "divx":
|
||||
T.Format = XVID
|
||||
case "480p":
|
||||
T.Resolution = P480
|
||||
case "720p":
|
||||
T.P720 = true
|
||||
T.Resolution = P720
|
||||
case "1080p":
|
||||
T.Resolution = P1080
|
||||
case "1080i":
|
||||
T.Resolution = I1080
|
||||
case "hdtv":
|
||||
T.Source = HDTV
|
||||
case "ahdtv":
|
||||
@ -193,3 +196,7 @@ func (T *MediaTorrent) tag(str string) {
|
||||
T.Tags[strings.ToLower(str)] = true
|
||||
}
|
||||
}
|
||||
|
||||
func (s SeriesTorrent) Title() string {
|
||||
return s[0][0].Title
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user