mirror of
https://github.com/v2fly/domain-list-community.git
synced 2024-11-16 17:14:52 +02:00
Remove speedtest related code due to #285
This commit is contained in:
parent
e32765570f
commit
78a6fa316b
68
main.go
68
main.go
@ -2,15 +2,11 @@ package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"compress/gzip"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
@ -156,65 +152,6 @@ func DetectPath(path string) (string, error) {
|
||||
return "", err
|
||||
}
|
||||
|
||||
func GenerateSpeedtest(path string) error {
|
||||
req, err := http.NewRequest("GET", "https://c.speedtest.net/speedtest-servers-static.php", nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("Accept-Encoding", "gzip")
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
data, err := gzip.NewReader(resp.Body)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer data.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(data)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
reg := regexp.MustCompile(`host="(.+):[0-9]+"`)
|
||||
matchList := reg.FindAllStringSubmatch(string(body), -1)
|
||||
|
||||
exist := make(map[string]bool)
|
||||
var domainList []string
|
||||
for _, match := range matchList {
|
||||
domain := match[1]
|
||||
if exist[domain] {
|
||||
continue
|
||||
}
|
||||
|
||||
ifIP, err := regexp.Match(`^([0-9]{1,3}\.){3}[0-9]{1,3}$`, []byte(domain))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if ifIP {
|
||||
continue
|
||||
}
|
||||
|
||||
domainList = append(domainList, "full:"+strings.ToLower(domain))
|
||||
exist[domain] = true
|
||||
}
|
||||
sort.Strings(domainList)
|
||||
|
||||
fPath := filepath.Join(path, "ookla-speedtest")
|
||||
b := append([]byte("include:ookla-speedtest-ads\n"), []byte(strings.Join(domainList, "\n"))...)
|
||||
err = ioutil.WriteFile(fPath, b, 0644)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func Load(path string) (*List, error) {
|
||||
file, err := os.Open(path)
|
||||
if err != nil {
|
||||
@ -285,11 +222,6 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
if err = GenerateSpeedtest(dir); err != nil {
|
||||
fmt.Println("Failed: ", err)
|
||||
return
|
||||
}
|
||||
|
||||
ref := make(map[string]*List)
|
||||
err = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user