first commit

This commit is contained in:
Gregory Salaun 2024-08-28 10:56:58 +07:00
commit 77b64d7378

123
RaceNotifier.go Normal file
View File

@ -0,0 +1,123 @@
package main
import (
"encoding/json"
"fmt"
"log"
"net"
"os"
)
type Race struct {
Id int `json:"id"`
Hash string `json:"hash"`
Name string `json:"name"`
Category string `json:"category"`
Content_Path string `json:"content_path"`
Root_Path string `json:"root_path"`
Save_Path string `json:"save_path"`
Size string `json:"size"`
Files string `json:"files"`
}
type PreRace struct {
Name string `json:"name"`
Indexer string `json:"indexer"`
}
func main() {
file, err := os.OpenFile("racer.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0777)
if err != nil {
log.Fatal(err)
}
// wrt := io.MultiWriter(os.Stdout, file)
log.SetOutput(file)
defer file.Close()
log.Println("Starting Program")
if len(os.Args) == 0 {
log.Println("Program launched without args")
os.Exit(0)
}
if len(os.Args) == 1 {
log.Println("Program launched with 1 arg")
os.Exit(0)
}
if len(os.Args) == 2 {
log.Println("Program launched with 2 arg")
os.Exit(0)
}
if len(os.Args) == 3 {
log.Println("Program launched with 3 arg")
os.Exit(0)
}
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 := PreRace{Name: os.Args[2], Indexer: os.Args[3]}
tcpAddr, err := net.ResolveTCPAddr("tcp", "212.7.203.107: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(r.Indexer + " " + r.Name))
if err != nil {
log.Fatal("Could not send message: ", err)
}
log.Println("Message sent...")
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", "212.7.203.107: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)
}
}