diff --git a/cmd/angel/main.go b/cmd/angel/main.go
index d8dd5a2..977823b 100644
--- a/cmd/angel/main.go
+++ b/cmd/angel/main.go
@@ -54,6 +54,7 @@ func main() {
&ktorrent.TorrentQQ{},
&ktorrent.TorrentSome{},
&ktorrent.TorrentRJ{},
+ &ktorrent.TorrentTop{},
}
s = common.GetAvailableSites(s)
fmt.Printf("[*] Angel found %d available site(s) ...\n", len(s))
diff --git a/common/common.go b/common/common.go
index 6cb735b..4f9a58c 100644
--- a/common/common.go
+++ b/common/common.go
@@ -50,6 +50,7 @@ var (
"torrentsome": "https://torrentsome150.com",
"ktxtorrent": "https://ktxtorrent37.com",
"torrentrj": "https://torrentrj156.com",
+ "torrenttop": "https://torrenttop118.com",
}
UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36"
)
@@ -204,6 +205,7 @@ func GetAvailableSites(oldItems []Scraping) []Scraping {
"torrentmobile", "torrentview", "torrentsir",
"torrentj", "torrentsee", "jujutorrent",
"torrentqq", "torrentsome", "torrentrj",
+ "torrenttop",
}
ch := make(chan int, len(items))
var wg sync.WaitGroup
diff --git a/ktorrent/torrenttop.go b/ktorrent/torrenttop.go
new file mode 100644
index 0000000..c9f78c2
--- /dev/null
+++ b/ktorrent/torrenttop.go
@@ -0,0 +1,90 @@
+package ktorrent
+
+import (
+ "fmt"
+ "net/url"
+ "strings"
+ "sync"
+
+ "github.com/PuerkitoBio/goquery"
+ "github.com/daite/angel/common"
+)
+
+// TorrentTop struct is for TorrentSee torrent web site
+type TorrentTop struct {
+ Name string
+ Keyword string
+ SearchURL string
+ ScrapedData *sync.Map
+}
+
+// initialize method set keyword and URL based on default url
+func (t *TorrentTop) initialize(keyword string) {
+ t.Keyword = keyword
+ t.Name = "torrenttop"
+ t.SearchURL = common.TorrentURL[t.Name] + "/search/index?keywords=" + url.QueryEscape(t.Keyword)
+}
+
+// Crawl torrent data from web site
+func (t *TorrentTop) Crawl(keyword string) map[string]string {
+ t.initialize(keyword)
+ data := t.getData(t.SearchURL)
+ if data == nil {
+ return nil
+ }
+ m := map[string]string{}
+ data.Range(
+ func(key, value interface{}) bool {
+ m[fmt.Sprint(key)] = fmt.Sprint(value)
+ return true
+ })
+ return m
+}
+
+// GetData method returns map(title, bbs url)
+func (t *TorrentTop) getData(url string) *sync.Map {
+ var wg sync.WaitGroup
+ m := &sync.Map{}
+ resp, ok := common.GetResponseFromURL(url)
+ if !ok {
+ return nil
+ }
+ defer resp.Body.Close()
+ doc, err := goquery.NewDocumentFromReader(resp.Body)
+ if err != nil {
+ return nil
+ }
+ doc.Find("l.py-4.flex.flex-row.border-b.topic-item a").Each(func(i int, s *goquery.Selection) {
+ wg.Add(1)
+ go func() {
+ defer wg.Done()
+ title, _ := s.Attr("title")
+ title = strings.TrimSpace(title)
+ link, _ := s.Attr("href")
+ link = strings.TrimSpace(common.URLJoin(common.TorrentURL[t.Name], link))
+ magnet := t.GetMagnet(link)
+ m.Store(title, magnet)
+ }()
+ })
+ wg.Wait()
+ t.ScrapedData = m
+ return m
+}
+
+// GetMagnet method returns torrent magnet
+func (t *TorrentTop) GetMagnet(url string) string {
+ resp, ok := common.GetResponseFromURL(url)
+ if !ok {
+ return "failed to fetch magnet"
+ }
+ defer resp.Body.Close()
+ doc, err := goquery.NewDocumentFromReader(resp.Body)
+ if err != nil {
+ return err.Error()
+ }
+ magnet, _ := doc.Find(".fas.fa-magnet + a").Attr("href")
+ if magnet == "" {
+ return "no magnet"
+ }
+ return magnet
+}
diff --git a/resources/torrenttop_bbs.html b/resources/torrenttop_bbs.html
new file mode 100644
index 0000000..89abf55
--- /dev/null
+++ b/resources/torrenttop_bbs.html
@@ -0,0 +1,1223 @@
+
+
+
+
+
+
+
+
+
+ 서진이네 2.E11.240906.720p-NEXT-토렌트탑-TORRENTTOP
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 서진이네 2.E11.240906.720p-NEXT 토렌트탑, torrenttop, 토렌트,torrent,토렌트사이트, 토렌트순위, 무료영화,최고의 무료토렌트사이트, 토렌트 파일공유 최강
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ 4,940
+
+ -
+
+
+ 2,176
+
+ -
+
+
+ 1,715
+
+ -
+
+
+ 1,669
+
+ -
+
+
+ 1,483
+
+ -
+
+
+ 1,076
+
+ -
+
+
+ 1,015
+
+ -
+
+
+ 969
+
+ -
+
+
+ 855
+
+ -
+
+
+ 735
+
+ -
+
+
+ 706
+
+ -
+
+
+ 630
+
+ -
+
+
+ 605
+
+ -
+
+
+ 535
+
+ -
+
+
+ 496
+
+
+
+
+
+
+ -
+
+
+ 1,772
+
+ -
+
+
+ 973
+
+ -
+
+
+ 742
+
+ -
+
+
+ 673
+
+ -
+
+
+ 579
+
+ -
+
+
+ 557
+
+ -
+
+
+ 544
+
+ -
+
+
+ 475
+
+ -
+
+
+ 460
+
+ -
+
+
+ 376
+
+ -
+
+
+ 359
+
+ -
+
+
+ 306
+
+ -
+
+
+ 273
+
+ -
+
+
+ 272
+
+ -
+
+
+ 271
+
+
+
+
+
+
+ -
+
+
+ 613
+
+ -
+
+
+ 589
+
+ -
+
+
+ 532
+
+ -
+
+
+ 499
+
+ -
+
+
+ 493
+
+ -
+
+
+ 441
+
+ -
+
+
+ 431
+
+ -
+
+
+ 409
+
+ -
+
+
+ 398
+
+ -
+
+
+ 395
+
+ -
+
+
+ 385
+
+ -
+
+
+ 367
+
+ -
+
+
+ 348
+
+ -
+
+
+ 317
+
+ -
+
+
+ 310
+
+
+
+
+
+
+ -
+
+
+ 149
+
+ -
+
+
+ 97
+
+ -
+
+
+ 91
+
+ -
+
+
+ 81
+
+ -
+
+
+ 76
+
+ -
+
+
+ 66
+
+ -
+
+
+ 64
+
+ -
+
+
+ 59
+
+ -
+
+
+ 50
+
+ -
+
+
+ 43
+
+ -
+
+
+ 42
+
+ -
+
+
+ 39
+
+ -
+
+
+ 36
+
+ -
+
+
+ 36
+
+ -
+
+
+ 35
+
+
+
+
+
+
+
+
+
+
+
+
+ 서진이네 2.E11.240906.720p-NEXT
+
+
+
예능·오락
+ 532 09.07 00:33
+
+
+
+
+
+
+
+
+
서진이네 2.E11.240906.720p-NEXT
+
+
+ 예능·오락
+
+
+
+
+
+
+
+ 127
+ 1.7GB
+ 09/07 00:33
+
+
+
+
+
+
+
+ 114
+ 1.4GB
+ 09/07 00:33
+
+
+
+
+
+
+
+ 66
+ 2.4GB
+ 09/06 23:33
+
+
+
+
+
+
+
+ 73
+ 2.4GB
+ 09/06 23:33
+
+
+
+
+
+
+
+ 73
+ 1.5GB
+ 09/06 23:33
+
+
+
+
+
+
+
+ 102
+ 1.5GB
+ 09/06 23:33
+
+
+
+
+
+
+
+ 66
+ 708.4MB
+ 09/06 22:33
+
+
+
+
+
+
+
+ 56
+ 2.9GB
+ 09/06 22:33
+
+
+
+
+
+
+
+ 117
+ 5.4GB
+ 09/06 03:33
+
+
+
+
+
+
+
+ 117
+ 3.2GB
+ 09/06 02:33
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/resources/torrenttop_search.html b/resources/torrenttop_search.html
new file mode 100644
index 0000000..020e714
--- /dev/null
+++ b/resources/torrenttop_search.html
@@ -0,0 +1,1507 @@
+
+
+
+
+
+
+
+
+
+ 서진이네2-토렌트탑-TORRENTTOP
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 토렌트탑,torrenttop,토렌트,torrent,토렌트사이트, 토렌트순위, 무료영화,최고의 무료토렌트사이트, 토렌트 파일공유 최강
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ 4,892
+
+ -
+
+
+ 2,152
+
+ -
+
+
+ 1,681
+
+ -
+
+
+ 1,648
+
+ -
+
+
+ 1,474
+
+ -
+
+
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
+ 9997
+
+
2.0GB
+
08.17
+
+
+
+
+
+
+ 9996
+
+
2.0GB
+
08.10
+
+
+
+
+
+
+ 9995
+
+
2.4GB
+
08.03
+
+
+
+
+
+
+ 9994
+
+
2.4GB
+
07.27
+
+
+
+
+
+
+ 9993
+
+
2.0GB
+
07.20
+
+
+
+
+
+
+ 9992
+
+
2.4GB
+
07.13
+
+
+
+
+
+
+ 9991
+
+
2.4GB
+
07.06
+
+
+
+
+
+
+ 9990
+
+
2.4GB
+
06.29
+
+
+
+
+
+
+ 9989
+
+
2.7GB
+
03.18
+
+
+
+
+
+
+ 9988
+
+
2.4GB
+
02.24
+
+
+
+
+
+
+ 9987
+
+
4.9GB
+
08.24
+
+
+
+
+
+
+ 9986
+
+
4.0GB
+
08.17
+
+
+
+
+
+
+ 9985
+
+
4.2GB
+
08.11
+
+
+
+
+
+
+ 9984
+
+
5.1GB
+
07.27
+
+
+
+
+
+
+ 9983
+
+
5.0GB
+
07.14
+
+
+
+
+
+
+ 9982
+
+
4.9GB
+
06.30
+
+
+
+
+
+
+ 9981
+
+
1.3GB
+
05.05
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ -
+
+
+ TOP20
+
+ -
+
+
09/03
+
+ -
+
+
09/02
+
+ -
+
+
09/03
+
+ -
+
+
09/03
+
+ -
+
+
09/07
+
+ -
+
+
09/04
+
+ -
+
+
09/07
+
+ -
+
+
09/05
+
+ -
+
+
09/04
+
+ -
+
+
09/03
+
+ -
+
+
09/04
+
+ -
+
+
09/04
+
+ -
+
+
09/04
+
+ -
+
+
09/03
+
+ -
+
+
09/04
+
+ -
+
+
09/07
+
+ -
+
+
09/02
+
+ -
+
+
09/06
+
+ -
+
+
09/01
+
+ -
+
+
09/02
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tests/torrenttop_test.go b/tests/torrenttop_test.go
new file mode 100644
index 0000000..3700ffa
--- /dev/null
+++ b/tests/torrenttop_test.go
@@ -0,0 +1,52 @@
+package tests
+
+import (
+ "log"
+ "os"
+ "strings"
+ "testing"
+
+ "github.com/PuerkitoBio/goquery"
+)
+
+func TestGetDataFuncForTorrentTop(t *testing.T) {
+ f, err := os.Open("../resources/torrenttop_search.html")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer f.Close()
+ doc, err := goquery.NewDocumentFromReader(f)
+ if err != nil {
+ log.Fatal(err)
+ }
+ got := make(map[string]string)
+ doc.Find(".py-4.flex.flex-row.border-b.topic-item a").Each(func(i int, s *goquery.Selection) {
+ title, _ := s.Attr("title")
+ title = strings.TrimSpace(title)
+ link, _ := s.Attr("href")
+ got[title] = link
+ })
+ want := map[string]string{
+ "서진이네 2.E01.240628.720p-NEXT": "/torrent/vzla5mq.html",
+ }
+ if got["서진이네 2.E01.240628.720p-NEXT"] != "/torrent/vzla5mq.html" {
+ t.Errorf("GetData() for TorrentTop = %q, want %q", got, want)
+ }
+}
+
+func TestGetMagnetFuncForTorrentTop(t *testing.T) {
+ f, err := os.Open("../resources/torrenttop_bbs.html")
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer f.Close()
+ doc, err := goquery.NewDocumentFromReader(f)
+ if err != nil {
+ log.Fatal(err)
+ }
+ got, _ := doc.Find(".fas.fa-magnet + a").Attr("href")
+ want := "magnet:?xt=urn:btih:6cf65299b5b48b077370f5675ce34b666e82cc3f"
+ if got != want {
+ t.Errorf("GetMagnet() for TorrentTop = %q, want %q", got, want)
+ }
+}