RaceNotifier/RaceNotifier.go
2024-08-30 12:34:28 +07:00

119 lines
2.8 KiB
Go

package main
import (
"encoding/json"
"log"
"net"
"os"
)
type Race struct {
TorrentName string `json:"torrentname"`
Category string `json:"category"`
Indexer string `json:"indexer"`
Type string `json:"type"`
Title string `json:"title"`
Season string `json:"season"`
Episode string `json:"episode"`
Year string `json:"year"`
Resolution string `json:"resolution"`
Source string `json:"source"`
TorrentURL string `json:"torrenturl"`
}
func main() {
file, err := os.OpenFile("racer.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777)
if err != nil {
log.Fatal(err)
}
log.SetOutput(file)
defer file.Close()
log.Println("Starting Program")
if os.Args[1] == "PreRace" || os.Args[1] == "Prerace" || os.Args[1] == "prerace" {
// This is a pre race, need to find all the details of the release
// log.Printf("[PreRace] Prerace launched with details %v, %v, %v", os.Args[1], os.Args[2], os.Args[3])
r := &Race{
TorrentName: os.Args[2],
Category: os.Args[3],
Indexer: os.Args[4],
Type: os.Args[5],
Title: os.Args[6],
Season: os.Args[7],
Episode: os.Args[8],
Year: os.Args[9],
Resolution: os.Args[10],
Source: os.Args[11],
TorrentURL: os.Args[12],
}
j, err := json.Marshal(r)
log.Println(string(j))
if err != nil {
log.Println(err)
}
tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:3000")
if err != nil {
log.Fatal("Could not parse IP address:", err)
}
conn, err := net.DialTCP("tcp", nil, tcpAddr)
if err != nil {
log.Fatal("Could not connect:", err)
}
defer conn.Close()
_, err = conn.Write([]byte(j))
if err != nil {
log.Fatal("Could not send message: ", err)
}
log.Println("Message sent...", r)
os.Exit(0)
} else if os.Args[1] == "test" {
for n, args := range os.Args {
log.Println("Arg", n, "->", args)
}
// } else {
// // This is the race thus the torrent has finished downloading.
// r := Race{Name: os.Args[1], Category: os.Args[2], Content_Path: os.Args[3], Root_Path: os.Args[4], Save_Path: os.Args[5], Hash: os.Args[6], Size: os.Args[7], Files: os.Args[8]}
// data, err := json.Marshal(r)
// if err != nil {
// fmt.Println(err)
// }
// err = os.WriteFile("test.json", data, 0644)
// if err != nil {
// log.Fatal(err)
// }
// tcpAddr, err := net.ResolveTCPAddr("tcp", "127.0.0.1:3000")
// if err != nil {
// log.Fatal("Could not parse IP address:", err)
// }
// conn, err := net.DialTCP("tcp", nil, tcpAddr)
// if err != nil {
// log.Fatal("Could not connect:", err)
// }
// defer conn.Close()
// _, err = conn.Write([]byte(data))
// if err != nil {
// log.Fatal("Could not send message: ", err)
// }
// os.Exit(0)
}
}