diff --git a/main.go b/main.go index 1c48a4a..2d535e3 100644 --- a/main.go +++ b/main.go @@ -11,7 +11,7 @@ import ( ) var ( - current_torrents [][]TorrentVideo + current_torrents SeriesTorrent ) func main() { @@ -27,20 +27,20 @@ func main() { PATH string `arg:"-P,help:Path to torrent files"` } arg.MustParse(&args) - scnr := bufio.NewScanner(os.Stdin) + scanner := bufio.NewScanner(os.Stdin) for err == nil { - if !scnr.scan() { + if !scanner.scan() { panic("fail") } - exec.Command("wget", scnr.Text(), "-o", args.PATH+'/') - process(args.PATH + '/' + path.Base(scnr.Text())) + exec.Command("wget", scanner.Text(), "-o", args.PATH+'/') + process(args.PATH + '/' + path.Base(scanner.Text())) } } -func process(torrentFile string) *TorrentVideo { +func process(torrentFile string) *VideoTorrent { var ( mt *MetaTorrent = new(MetaTorrent) - vt *TorrentVideo = new(TorrentVideo) + vt *VideoTorrent = new(VideoTorrent) ) f, _ := os.OpenFile(torrentFile, os.O_RDONLY, 755) mt.Load(f) diff --git a/torrentFiles/The.Librarians.US.S02E09.720p.HDTV.x264-0SEC[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S02E09.720p.HDTV.x264-0SEC[eztv].mkv.torrent new file mode 100644 index 0000000..4dc0dc0 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S02E09.720p.HDTV.x264-0SEC[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S02E09.HDTV.x264-KILLERS[eztv].mp4.torrent b/torrentFiles/The.Librarians.US.S02E09.HDTV.x264-KILLERS[eztv].mp4.torrent new file mode 100644 index 0000000..7873c7e Binary files /dev/null and b/torrentFiles/The.Librarians.US.S02E09.HDTV.x264-KILLERS[eztv].mp4.torrent differ diff --git a/torrentFiles/The.Librarians.US.S02E10.720p.HDTV.x264-KILLERS[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S02E10.720p.HDTV.x264-KILLERS[eztv].mkv.torrent new file mode 100644 index 0000000..4b40dd6 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S02E10.720p.HDTV.x264-KILLERS[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S02E10.HDTV.x264-KILLERS[eztv].mp4.torrent b/torrentFiles/The.Librarians.US.S02E10.HDTV.x264-KILLERS[eztv].mp4.torrent new file mode 100644 index 0000000..338d61d Binary files /dev/null and b/torrentFiles/The.Librarians.US.S02E10.HDTV.x264-KILLERS[eztv].mp4.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E01.720p.HDTV.x264-AVS[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E01.720p.HDTV.x264-AVS[eztv].mkv.torrent new file mode 100644 index 0000000..efc5187 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E01.720p.HDTV.x264-AVS[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E01.HDTV.x264-FLEET[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E01.HDTV.x264-FLEET[eztv].mkv.torrent new file mode 100644 index 0000000..01b813a Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E01.HDTV.x264-FLEET[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E02.720p.HDTV.x264-BRISK[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E02.720p.HDTV.x264-BRISK[eztv].mkv.torrent new file mode 100644 index 0000000..5b58f88 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E02.720p.HDTV.x264-BRISK[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E02.HDTV.x264-FLEET[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E02.HDTV.x264-FLEET[eztv].mkv.torrent new file mode 100644 index 0000000..ee72207 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E02.HDTV.x264-FLEET[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E04.720p.HDTV.x264-AVS[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E04.720p.HDTV.x264-AVS[eztv].mkv.torrent new file mode 100644 index 0000000..6b06281 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E04.720p.HDTV.x264-AVS[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E04.HDTV.x264-BRISK[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E04.HDTV.x264-BRISK[eztv].mkv.torrent new file mode 100644 index 0000000..8b0e8da Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E04.HDTV.x264-BRISK[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E05.720p.HDTV.x264-AVS[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E05.720p.HDTV.x264-AVS[eztv].mkv.torrent new file mode 100644 index 0000000..4e75503 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E05.720p.HDTV.x264-AVS[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E05.HDTV.x264-FLEET[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E05.HDTV.x264-FLEET[eztv].mkv.torrent new file mode 100644 index 0000000..02c9669 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E05.HDTV.x264-FLEET[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E06.720p.HDTV.x264-AVS[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E06.720p.HDTV.x264-AVS[eztv].mkv.torrent new file mode 100644 index 0000000..1565ffc Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E06.720p.HDTV.x264-AVS[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E06.HDTV.x264-FLEET[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E06.HDTV.x264-FLEET[eztv].mkv.torrent new file mode 100644 index 0000000..667f4d7 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E06.HDTV.x264-FLEET[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E07.720p.HDTV.x264-AVS[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E07.720p.HDTV.x264-AVS[eztv].mkv.torrent new file mode 100644 index 0000000..3657afe Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E07.720p.HDTV.x264-AVS[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E07.HDTV.x264-FLEET[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E07.HDTV.x264-FLEET[eztv].mkv.torrent new file mode 100644 index 0000000..aecde79 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E07.HDTV.x264-FLEET[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E08.720p.HDTV.x264-FLEET[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E08.720p.HDTV.x264-FLEET[eztv].mkv.torrent new file mode 100644 index 0000000..ed9da3b Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E08.720p.HDTV.x264-FLEET[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E08.HDTV.x264-FLEET[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E08.HDTV.x264-FLEET[eztv].mkv.torrent new file mode 100644 index 0000000..0e83f67 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E08.HDTV.x264-FLEET[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E09.720p.HDTV.x264-AVS[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E09.720p.HDTV.x264-AVS[eztv].mkv.torrent new file mode 100644 index 0000000..2214e9a Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E09.720p.HDTV.x264-AVS[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E09.HDTV.x264-KILLERS[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E09.HDTV.x264-KILLERS[eztv].mkv.torrent new file mode 100644 index 0000000..d003a86 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E09.HDTV.x264-KILLERS[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E10.720p.HDTV.x264-AVS[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E10.720p.HDTV.x264-AVS[eztv].mkv.torrent new file mode 100644 index 0000000..3355326 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E10.720p.HDTV.x264-AVS[eztv].mkv.torrent differ diff --git a/torrentFiles/The.Librarians.US.S03E10.HDTV.x264-FLEET[eztv].mkv.torrent b/torrentFiles/The.Librarians.US.S03E10.HDTV.x264-FLEET[eztv].mkv.torrent new file mode 100644 index 0000000..6d2e1a2 Binary files /dev/null and b/torrentFiles/The.Librarians.US.S03E10.HDTV.x264-FLEET[eztv].mkv.torrent differ diff --git a/type.go b/type.go index 5416ac7..3fc8c91 100644 --- a/type.go +++ b/type.go @@ -11,18 +11,28 @@ import ( type Src int type Fmt int +type Res int const ( HDTV Src = iota + 1 - CAM - DVD + AHDTV + HRPDTV ) + const ( X264 Fmt = iota + 1 XVID ) +const ( + P480 Res = iota + 1 + P720 + P2080 + I1080 +) + type MetaTorrent struct { + Path string Announce string `bencode:"announce"` Announcelist [][]string `bencode:"announce-list"` Comment string `bencode:"comment"` @@ -40,36 +50,35 @@ type MetaTorrent struct { } type Torrent struct { + Meta MetaTorrent Name string Comment string Creator string size int64 } -type TorrentVideo struct { - *Torrent - Title string - Release string - Source Src - Format Fmt - Proper bool - Internal bool - Repack bool - Nuked bool - P720 bool +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 } -type TorrentEpisode struct { - *TorrentVideo +type EpisodeTorrent struct { + VT []MediaTorrent Episode string Season string } +type SeriesTorrent struct { + Episodes []EpisodeTorrent + title string +} + type Interface interface { - ReleaseGroup() string - Len() int - Swap(i, j int) - Less(i, j int) bool + Title() string } func NewTorrent(mt MetaTorrent) (T *Torrent) { @@ -89,6 +98,7 @@ func NewTorrent(mt MetaTorrent) (T *Torrent) { } T.Comment = mt.Comment T.Creator = mt.CreatedBy + T.Meta = mt return T } @@ -96,74 +106,90 @@ func (Mt *MetaTorrent) Load(r io.Reader) error { return bencode.NewDecoder(r).Decode(Mt) } -func (T *TorrentVideo) Process() error { +func (T *MediaTorrent) Process() error { var ( - err error - r rune - exit, tag bool - str string - re = [2]*regexp.Regexp{regexp.MustCompile(`[Ss](\d{2})[Ee](\d{2})`), regexp.MustCompile(`([A-Za-z]{3,10})\[([A-Za-z]{4,6})\]`)} + 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})\]$`)} ) - reader := strings.NewReader(T.Name) - for err == nil && !exit { - for err == nil && r != '.' && r != '-' { - r, _, err = reader.ReadRune() - if err == io.EOF { - exit = true - break - } else if err != nil { - return err - } - if r != '.' && r != '-' { - str += string(r) - } - } - fmt.Println(str) - if tag { - switch str { - case "NUKED": - T.Nuked = true - case "REPACK": - T.Repack = true - case "x264", "H", "264", "h264", "H264": - 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 - } - if re[1].MatchString(str) { - match := re[1].FindStringSubmatch(str) - T.Release = match[1] - T.Creator = match[2] - } - } else { - if re[0].MatchString(str) { - tag = true - match := re[0].FindStringSubmatch(str) - T.Season = match[1] - T.Episode = match[2] - } else { - T.Title += str - } - } - fmt.Println(re[1]) - fmt.Printf("tag: %t\n", re[1].MatchString(str)) - - if r == '.' || r == '-' { - r = ' ' - str = "" + 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] + } + 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] + } + } 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 + 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 + } + } + } + + T.Title = strings.TrimSpace(T.Title) return nil } + +func (T *MediaTorrent) tag(str string) { + switch strings.ToLower(str) { + case "x264", "h", "264", "h264", "h264": + T.Format = X264 + case "xvid", "divx": + T.Format = XVID + case "720p": + T.P720 = true + case "hdtv": + T.Source = HDTV + case "ahdtv": + T.Source = AHDTV + case "hrpdtv": + T.Source = HRPDTV + default: + T.Tags[strings.ToLower(str)] = true + } +}