TorrentFilter/main.go

74 lines
1.7 KiB
Go
Raw Normal View History

package main
import (
"bufio"
"fmt"
2017-06-20 12:25:19 -07:00
"os"
"os/exec"
"path"
"path/filepath"
"strings"
2017-06-20 12:25:19 -07:00
"github.com/alexflint/go-arg"
)
var (
current_torrents SeriesTorrent
unselectedDir string
)
func main() {
var (
torrentName string
torrentPath string
args struct {
RES string `arg:"help:Resolution preference [480/720/1080]"`
RELEASE []string `arg:"-r,help:Release group preference order."`
2017-11-30 18:20:20 -08:00
TAGS []string `arg:"-t, help:Tags to prefer -t internal would choose an internal over another"`
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-06-20 12:25:19 -07:00
arg.MustParse(&args)
2017-11-30 18:20:20 -08:00
if len(args.PATH) < 1 {
args.PATH, _ = os.Getwd()
}
unselectedDir = filepath.Clean(args.PATH + "/unselected/")
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
url := strings.TrimSpace(scanner.Text())
torrentName = filepath.Base(url)
torrentPath = filepath.Join(unselectedDir, torrentName)
2017-11-30 19:41:28 -08:00
cmd := exec.Command("wget", url, "-q", "-O", torrentPath)
2017-11-30 18:38:02 -08:00
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
2017-11-30 18:29:28 -08:00
err := cmd.Run()
2017-11-30 18:38:02 -08:00
fmt.Println()
2017-11-30 18:29:28 -08:00
if err != nil {
fmt.Println("url failed: ", url)
2017-11-30 18:29:28 -08:00
fmt.Println(err)
continue
}
process(torrentPath)
}
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
)
2017-11-30 19:03:20 -08:00
f, err := os.OpenFile(torrentFile, os.O_RDONLY, 755)
2017-11-30 19:11:26 -08:00
fmt.Println("File: ", err)
2017-11-30 19:08:54 -08:00
err = mt.ReadFile(f)
2017-11-30 19:11:26 -08:00
fmt.Println("Read: ", err)
2017-11-30 18:46:43 -08:00
fmt.Printf("%+v\n", mt)
2017-06-20 12:25:19 -07:00
vt.Torrent = NewTorrent(*mt)
vt.Parse(strings.TrimSuffix(vt.Name, path.Ext(vt.Name)))
2017-11-30 18:20:20 -08:00
fmt.Printf("%v\n", *vt)
2017-06-20 12:25:19 -07:00
return vt
}