mirror of
https://github.com/Ernous/TorrServerJellyfin.git
synced 2025-12-19 21:46:11 +05:00
add dns resoler
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -18,7 +17,6 @@ import (
|
|||||||
type args struct {
|
type args struct {
|
||||||
Port string `arg:"-p" help:"web server port"`
|
Port string `arg:"-p" help:"web server port"`
|
||||||
Path string `arg:"-d" help:"database path"`
|
Path string `arg:"-d" help:"database path"`
|
||||||
Add string `arg:"-a" help:"add torrent link and exit"`
|
|
||||||
RDB bool `arg:"-r" help:"start in read-only DB mode"`
|
RDB bool `arg:"-r" help:"start in read-only DB mode"`
|
||||||
DontKill bool `arg:"-k" help:"dont kill program on signal"`
|
DontKill bool `arg:"-k" help:"dont kill program on signal"`
|
||||||
}
|
}
|
||||||
@@ -40,10 +38,8 @@ func main() {
|
|||||||
params.Port = "8090"
|
params.Port = "8090"
|
||||||
}
|
}
|
||||||
|
|
||||||
if params.Add != "" {
|
|
||||||
add()
|
|
||||||
}
|
|
||||||
settings.Path = params.Path
|
settings.Path = params.Path
|
||||||
|
dnsResolve()
|
||||||
Preconfig(params.DontKill)
|
Preconfig(params.DontKill)
|
||||||
|
|
||||||
server.Start(params.Port, params.RDB)
|
server.Start(params.Port, params.RDB)
|
||||||
@@ -52,28 +48,21 @@ func main() {
|
|||||||
os.Exit(0)
|
os.Exit(0)
|
||||||
}
|
}
|
||||||
|
|
||||||
func add() {
|
func dnsResolve() {
|
||||||
err := addRemote()
|
addrs, err := net.LookupHost("www.themoviedb.org")
|
||||||
if err != nil {
|
if len(addrs) == 0 {
|
||||||
fmt.Println("Error add torrent:", err)
|
fmt.Println("Check dns", addrs, err)
|
||||||
os.Exit(-1)
|
|
||||||
|
fn := func(ctx context.Context, network, address string) (net.Conn, error) {
|
||||||
|
d := net.Dialer{}
|
||||||
|
return d.DialContext(ctx, "udp", "1.1.1.1:53")
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Added ok")
|
net.DefaultResolver = &net.Resolver{
|
||||||
os.Exit(0)
|
Dial: fn,
|
||||||
}
|
}
|
||||||
|
|
||||||
func addRemote() error {
|
addrs, err = net.LookupHost("www.themoviedb.org")
|
||||||
url := "http://localhost:" + params.Port + "/torrent/add"
|
fmt.Println("Check new dns", addrs, err)
|
||||||
fmt.Println("Add torrent link:", params.Add, "\n", url)
|
|
||||||
|
|
||||||
json := `{"Link":"` + params.Add + `"}`
|
|
||||||
resp, err := http.Post(url, "text/html; charset=utf-8", bytes.NewBufferString(json))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
if resp.StatusCode != 200 {
|
|
||||||
return errors.New(resp.Status)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user