Skip to content

Commit

Permalink
fix auto-search update, show uptime
Browse files Browse the repository at this point in the history
  • Loading branch information
jpillora committed Jul 12, 2017
1 parent 075c6f7 commit 734ca13
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
36 changes: 17 additions & 19 deletions server/server_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package server

import (
"bytes"
"encoding/json"
"io/ioutil"
"log"
"net/http"
Expand All @@ -27,19 +28,23 @@ func (s *Server) fetchSearchConfigLoop() {
}

var fetches = 0
var currentConfig = defaultSearchConfig
var currentConfig, _ = normalize(defaultSearchConfig)

func (s *Server) fetchSearchConfig() error {
resp, err := http.Get(searchConfigURL)
if err != nil {
return err
}
fetches++
defer resp.Body.Close()
newConfig, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
newConfig, err = normalize(newConfig)
if err != nil {
return err
}
fetches++
if bytes.Equal(currentConfig, newConfig) {
return nil //skip
}
Expand All @@ -48,29 +53,22 @@ func (s *Server) fetchSearchConfig() error {
}
s.state.SearchProviders = s.scraper.Config
s.state.Push()
if fetches >= 2 {
log.Printf("Loaded new search providers")
}
currentConfig = newConfig
log.Printf("Loaded new search providers")
return nil
}

func normalize(input []byte) ([]byte, error) {
output := bytes.Buffer{}
if err := json.Indent(&output, input, "", " "); err != nil {
return nil, err
}
return output.Bytes(), nil
}

//see github.com/jpillora/scraper for config specification
//cloud-torrent uses "<id>-item" handlers
var defaultSearchConfig = []byte(`{
"et": {
"name": "ExtraTorrent",
"url": "https://extratorrent.cc/search/?search={{query}}&s_cat=&pp=&srt=seeds&order=desc&page={{page:1}}",
"list": "table.tl tr.tlr",
"result": {
"name":["td.tli > a"],
"torrent": ["td:nth-child(1) a","@href","s/torrent_download/download/"],
"url": ["td.tli > a","@href"],
"size": "td:nth-child(5)",
"seeds": "td.sy",
"peers": "td.ly"
}
},
"zq": {
"name": "Zooqle",
"url": "https://zooqle.com/search?q={{query}}&pg={{page:1}}&s=ns&v=t&sd=d",
Expand Down Expand Up @@ -123,7 +121,7 @@ var defaultSearchConfig = []byte(`{
"name": "1337X (Item)",
"url": "http://1337x.to{{item}}",
"result": {
"magnet": ["a.btn-magnet","@href"]
"magnet": [".download-links-dontblock a.btn","@href"]
}
},
"abb": {
Expand Down
4 changes: 2 additions & 2 deletions static/files.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions static/files/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ <h2>
<section class="downloads" ng-controller="DownloadsController" ng-include src="'template/downloads.html'"></section>

<footer>
<span ng-if="state.Stats.Uptime">up {{ ago(state.Stats.Uptime) }} - </span>
<span>github.com/<a href="https://github.com/jpillora" target="_blank">jpillora</a>/<a href="https://github.com/jpillora/cloud-torrent" target="_blank">cloud-torrent</a> version {{ state.Stats.Version }} - </span>
<span ng-if="numKeys(state.Users) > 1">{{ numKeys(state.Users) }} users connected - </span>
<span><a href="https://golang.org" target="_blank">Go</a> {{ state.Stats.Runtime }}</span>
Expand Down

0 comments on commit 734ca13

Please sign in to comment.