-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkat.go
More file actions
99 lines (93 loc) · 2.41 KB
/
kat.go
File metadata and controls
99 lines (93 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package main
import (
"bufio"
"compress/gzip"
"fmt"
"log"
"net/http"
"strings"
)
import "github.com/stathat/go"
type KatEntry struct {
Infohash *Infohash
Title string
Category string
Uri string
}
const KAT_HOURLY_URL = "https://kickass.to/hourlydump.txt.gz"
func GetLatestKatEntries() []KatEntry {
trackerUrlStrs := map[string]int{
"udp://12.rarbg.me:80/announce": 200,
"udp://9.rarbg.com:2710/announce": 50,
"udp://open.demonii.com:1337/announce": 200,
"udp://tracker.coppersurfer.tk:6969/announce": 200,
}
response, err := http.Get(KAT_HOURLY_URL)
if err != nil {
app.Debugf("GetLatestKatEntries()", "Failed to download KAT entries: %s", err)
return []KatEntry{}
}
reader, err := gzip.NewReader(response.Body)
if err != nil {
log.Fatalf("Failed to read KAT entries body: %s\n", err)
}
scanner := bufio.NewScanner(reader)
entries := make([]KatEntry, 0)
config := GetConfig()
for scanner.Scan() {
values := strings.Split(scanner.Text(), "|")
for _, category := range config.Kat.Categories {
if category == values[2] {
for trackerUrlStr, trackerMaxPeerCount := range trackerUrlStrs {
tracker, err := NewTracker(trackerUrlStr, trackerMaxPeerCount)
if err != nil {
panic(err)
}
entries = append(
entries,
KatEntry{
Infohash: NewInfohash(values[0], 1, tracker),
Title: values[1],
Category: values[2],
Uri: values[3],
},
)
}
break
}
}
}
return entries
}
func ProcessLatestKatEntries() {
entries := GetLatestKatEntries()
redisClient, err := app.GetRedisClient()
if err != nil {
panic(err)
}
for _, entry := range entries {
app.Debugf("ProcessLatestKatEntries()", "Entry: %v", entry.Infohash)
entry.Infohash.UpdateScore(1, redisClient)
RedisCmd(redisClient, "HSET", fmt.Sprintf("torrents.info.%s", entry.Infohash.String()), "title", entry.Title)
RedisCmd(
redisClient,
"HSET",
fmt.Sprintf("torrents.info.%s", entry.Infohash.String()),
"category",
entry.Category,
)
RedisCmd(redisClient, "HSET", fmt.Sprintf("torrents.info.%s", entry.Infohash.String()), "uri", entry.Uri)
}
torrentCount, err := RedisIntCmd(
redisClient,
"ZCOUNT",
"torrents",
"-inf",
"+inf",
)
if err != nil {
panic(err)
}
redisClient.Cmd("SET", "torrents.count", torrentCount)
stathat.PostEZValue("torrents.count", "lovek323@gmail.com", float64(torrentCount))
}