aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRagnis Armus <ragnis@aragnis.com>2018-04-14 23:46:57 +0300
committerRagnis Armus <ragnis@aragnis.com>2018-04-14 23:46:57 +0300
commitb9f111747e4d4a04b4163b10ace3a51fa879e584 (patch)
tree7855a50f9a137e780b3e5229a812bd9370a728ec
parent49ed3a5539768732d97f4dba4793d5fc0e76b496 (diff)
Add ETTV searcher
-rw-r--r--search/ettv.go86
-rw-r--r--sync.go1
2 files changed, 87 insertions, 0 deletions
diff --git a/search/ettv.go b/search/ettv.go
new file mode 100644
index 0000000..d671bd9
--- /dev/null
+++ b/search/ettv.go
@@ -0,0 +1,86 @@
+package search
+
+import (
+ "context"
+ "errors"
+ "net/url"
+ "strconv"
+
+ "github.com/PuerkitoBio/goquery"
+)
+
+// ETTV is a Searcher for ETTV
+type ETTV struct {
+}
+
+// Search performs a search
+func (s ETTV) Search(ctx context.Context, query string) (results Results, err error) {
+ doc, err := newGoqueryDocument(ctx, s.newSearchURL(query).String())
+ if err != nil {
+ return
+ }
+ doc.Find("#main .right_column .myFrame-content table > tbody > tr").Each(func(i int, tr *goquery.Selection) {
+ seeders, err := strconv.Atoi(tr.Find("td:nth-child(6) b").Text())
+ if err != nil || seeders < 0 {
+ return
+ }
+ link := tr.Find("td:nth-child(2) > a")
+ linkURL, ok := link.Attr("href")
+ if !ok {
+ return
+ }
+ name := link.Text()
+ results = append(results, &Result{
+ Name: name,
+ MagnetURL: func(ctx context.Context) (string, error) {
+ u, err := s.newRelativeURL(linkURL)
+ if err != nil {
+ return "", err
+ }
+ return s.magnetURL(ctx, u.String())
+ },
+ Seeders: uint(seeders),
+ Resolution: getNameResolution(name),
+ })
+ })
+ return
+}
+
+func (s ETTV) newURL(u *url.URL) *url.URL {
+ return &url.URL{
+ Scheme: "https",
+ Host: "www.ettv.tv",
+ Path: u.Path,
+ RawQuery: u.RawQuery,
+ }
+}
+
+func (s ETTV) newRelativeURL(rel string) (*url.URL, error) {
+ u, err := url.Parse(rel)
+ if err != nil {
+ return nil, err
+ }
+ return s.newURL(u), nil
+}
+
+func (s ETTV) newSearchURL(q string) *url.URL {
+ return s.newURL(&url.URL{
+ Path: "/torrents-search.php",
+ RawQuery: "search=" + url.QueryEscape(q),
+ })
+}
+
+func (s ETTV) magnetURL(ctx context.Context, url string) (magnet string, err error) {
+ doc, err := newGoqueryDocument(ctx, url)
+ if err != nil {
+ return
+ }
+ doc.Find("#downloadbox ").Each(func(i int, tr *goquery.Selection) {
+ var ok bool
+ magnet, ok = tr.Find("a[href^=magnet]").Attr("href")
+ if !ok {
+ err = errors.New("magnet link not found")
+ }
+ })
+ return
+}
diff --git a/sync.go b/sync.go
index 052790a..8c1e6b1 100644
--- a/sync.go
+++ b/sync.go
@@ -94,6 +94,7 @@ func cmdSync(db *DB, argv []string) int {
func syncShow(show *Show, out chan<- *search.Result, fin chan<- bool) {
aggr := &search.Aggregator{}
+ aggr.AddSearcher(&search.ETTV{})
aggr.AddSearcher(&search.Thepiratebay{})
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)