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,토렌트사이트, 토렌트순위, 무료영화,최고의 무료토렌트사이트, 토렌트 파일공유 최강 +

+ + + + + +
+ +
+ + +
+
+ + ad-4-22 + +
+
+ + ad-0423 + +
+
+ + game418 + +
+
+ + game418 + +
+
+ + ad-212 + +
+
+ + ad-5-5-벳16 + +
+
+ + ad-5-5-벳위즈 + +
+
+ + telegram + +
+
+ + ad-0810 + +
+
+ + ad-0810 + +
+
+ + ad-0810 + +
+
+ +
+ +
+
+ + + +
+
+ + + +
+ +
+ +
+ +
+ +
+
+ + + +

+ 서진이네 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
+
+
+
+
+
+ + + +
+
+ +
+
+
+
+ + + +
+
+
+ +
+ 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
+
+
+
+ + +
+ + + + +
+
+
+ + medicine ad + +
+
+ + ad + +
+
+ + ad + +
+
+ + game ad + +
+ +
+
+ + + +
+
+ +
+ + +
+ +
+

+ 광고문의 텔레그램 : @protime1 + +

+
+ +
+ + + + +
+ +
+ + + + 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,토렌트사이트, 토렌트순위, 무료영화,최고의 무료토렌트사이트, 토렌트 파일공유 최강 +

+ + + + + +
+ +
+ + +
+
+ + ad-4-22 + +
+
+ + ad-0423 + +
+
+ + game418 + +
+
+ + game418 + +
+
+ + ad-212 + +
+
+ + ad-5-5-벳16 + +
+
+ + ad-5-5-벳위즈 + +
+
+ + telegram + +
+
+ + ad-0810 + +
+
+ + ad-0810 + +
+
+ + ad-0810 + +
+
+ +
+ +
+
+ + + +
+
+ + + +
+ +
+ +
+ +
+ +
+
+ + +
+
+ +
+ " 서진이네2 " + 검색결과 10000개 +
+ +
+ +
+ +
+ +
제목
+
용량
+ +
+ + + +
+ + +
2.4GB
+ +
+ + + +
+ + +
2.5GB
+ +
+ + + +
+ + +
2.4GB
+ +
+ + + +
+ + +
2.0GB
+ +
+ + + +
+ + +
2.0GB
+ +
+ + + +
+ + +
2.4GB
+ +
+ + + +
+ + +
2.4GB
+ +
+ + + +
+ + +
2.0GB
+ +
+ + + +
+ + +
2.4GB
+ +
+ + + +
+ + +
2.4GB
+ +
+ + + +
+ + +
2.4GB
+ +
+ + + +
+ + +
2.7GB
+ +
+ + + +
+ + +
2.4GB
+ +
+ + + +
+ + +
4.9GB
+ +
+ + + +
+ + +
4.0GB
+ +
+ + + +
+ + +
4.2GB
+ +
+ + + +
+ + +
5.1GB
+ +
+ + + +
+ + +
5.0GB
+ +
+ + + +
+ + +
4.9GB
+ +
+ + + +
+ + +
1.3GB
+ +
+ + + +
+ + + +
+
+
+
+ + medicine ad + +
+
+ + ad + +
+
+ + ad + +
+
+ + game ad + +
+ +
+
+ +
+
+
+ + medicine ad + +
+
+ + ad + +
+
+ + ad + +
+
+ + game ad + +
+ +
+
+ + + +
+
+ +
+ + +
+ +
+

+ 광고문의 텔레그램 : @protime1 + +

+
+ +
+ + + + +
+ +
+ + + + + + 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) + } +}