2017-06-17 02:11:46 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-07-16 23:48:06 -07:00
|
|
|
"bufio"
|
2017-06-17 02:11:46 -07:00
|
|
|
"fmt"
|
2017-06-20 12:25:19 -07:00
|
|
|
"os"
|
2017-07-16 23:48:06 -07:00
|
|
|
"os/exec"
|
2017-08-08 11:07:36 -07:00
|
|
|
"path/filepath"
|
|
|
|
"strings"
|
2017-06-20 12:25:19 -07:00
|
|
|
|
|
|
|
"github.com/alexflint/go-arg"
|
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
2017-07-22 22:53:12 -07:00
|
|
|
current_torrents SeriesTorrent
|
2017-08-08 11:07:36 -07:00
|
|
|
unselectedDir string
|
2017-06-17 02:11:46 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2017-07-23 23:21:25 -07:00
|
|
|
var (
|
2017-08-08 11:07:36 -07:00
|
|
|
torrentName string
|
|
|
|
torrentPath string
|
|
|
|
args struct {
|
2017-07-23 23:21:25 -07:00
|
|
|
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"`
|
|
|
|
}
|
|
|
|
)
|
2017-09-22 17:47:50 -07:00
|
|
|
|
2017-06-20 12:25:19 -07:00
|
|
|
arg.MustParse(&args)
|
2017-09-22 17:47:50 -07:00
|
|
|
if len(args.PATH < 1) {
|
|
|
|
args.PATH, _ = os.Getwd()
|
|
|
|
}
|
2017-08-08 11:07:36 -07:00
|
|
|
unselectedDir = filepath.Clean(args.PATH + "/unselected/")
|
2017-09-22 17:47:50 -07:00
|
|
|
|
2017-07-22 22:53:12 -07:00
|
|
|
scanner := bufio.NewScanner(os.Stdin)
|
2017-08-08 11:07:36 -07:00
|
|
|
for scanner.Scan() {
|
|
|
|
url := strings.TrimSpace(scanner.Text())
|
|
|
|
torrentName = filepath.Base(url)
|
|
|
|
torrentPath = filepath.Join(unselectedDir, torrentName)
|
|
|
|
cmd := exec.Command("wget", url, "-o", torrentPath)
|
|
|
|
if cmd.Run() != nil {
|
|
|
|
fmt.Println("url failed: ", url)
|
|
|
|
continue
|
2017-07-16 23:48:06 -07:00
|
|
|
}
|
2017-08-08 11:07:36 -07:00
|
|
|
process(torrentPath)
|
2017-07-16 23:48:06 -07:00
|
|
|
}
|
2017-06-20 12:25:19 -07:00
|
|
|
}
|
|
|
|
|
2017-09-27 13:17:58 -07:00
|
|
|
func process(torrentFile string) *SceneVideoTorrent {
|
2017-06-20 12:25:19 -07:00
|
|
|
var (
|
2017-09-27 13:17:58 -07:00
|
|
|
mt *MetaTorrent = new(MetaTorrent)
|
|
|
|
vt *SceneVideoTorrent = new(SceneVideoTorrent)
|
2017-06-20 12:25:19 -07:00
|
|
|
)
|
|
|
|
f, _ := os.OpenFile(torrentFile, os.O_RDONLY, 755)
|
2017-09-22 17:47:50 -07:00
|
|
|
mt.ReadFile(f)
|
2017-06-20 12:25:19 -07:00
|
|
|
fmt.Printf("%+v\n", mt)
|
|
|
|
vt.Torrent = NewTorrent(*mt)
|
2017-09-20 17:40:27 -07:00
|
|
|
vt.Parse(vt.Name)
|
2017-06-20 12:25:19 -07:00
|
|
|
fmt.Printf("%+v\n", *vt)
|
|
|
|
return vt
|
2017-06-17 02:11:46 -07:00
|
|
|
}
|