File tree Expand file tree Collapse file tree 3 files changed +96
-2
lines changed
Expand file tree Collapse file tree 3 files changed +96
-2
lines changed Original file line number Diff line number Diff line change 1+ aria2-trackers
2+
Original file line number Diff line number Diff line change 1- # aria2-trackers
2- create config file of aria2 , use list at ` https://github.com/ngosang/trackerslist `
1+ # auto-update for linux
2+ This tool will download the best trackers list, and auto update the config file of aria2 "~ /.aria2/aria2.conf".
3+
4+ The default url is "https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt ", you can change it by argument.
5+
6+ 这个小工具用于下载最佳tracker列表,并且自动更新aria2配置文件"~ /.aria2/aria2.conf"。
7+
8+ 默认列表文件的下载地址是:"https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt",用户可以用参数改变下载地址。
9+
10+ #### install(安装):
11+ go get -v github.com/rocket049/trackerslist/tool/auto-update
12+
13+ notice: You must install golang compiler first. 你必须先安装go语言编译器。
14+
15+ #### Usage(用法):
16+ ```
17+ //update default best list,下载默认最佳列表。
18+ auto-update
19+ //update special list,下载指定列表
20+ auto-update [url of list]
21+ ```
Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "bufio"
5+ "flag"
6+ "net/http"
7+ "os"
8+ "path/filepath"
9+ "text/template"
10+ )
11+
12+ var listUrl = "https://raw.githubusercontent.com/ngosang/trackerslist/master/trackers_best.txt"
13+
14+ var tmpl = `bt-tracker={{range $k, $v := .}}{{if eq $k 0}}{{$v}}{{else}},{{$v}}{{end}}{{end}}
15+ enable-dht=true
16+ bt-enable-lpd=true
17+ enable-peer-exchange=true
18+ `
19+
20+ func downloadList () ([]string , error ) {
21+ resp , err := http .Get (listUrl )
22+ if err != nil {
23+ return nil , err
24+ }
25+ defer resp .Body .Close ()
26+ rd := bufio .NewReader (resp .Body )
27+ res := []string {}
28+ for {
29+ line1 , _ , err := rd .ReadLine ()
30+ if err != nil {
31+ break
32+ }
33+ //fmt.Println("url:", string(line1), len(line1))
34+ if len (line1 ) > 0 {
35+ res = append (res , string (line1 ))
36+ }
37+ }
38+ return res , nil
39+ }
40+
41+ func writeConf (data []string ) error {
42+ home , err := os .UserHomeDir ()
43+ if err != nil {
44+ return err
45+ }
46+ confPath := filepath .Join (home , ".aria2" , "aria2.conf" )
47+ fp , err := os .Create (confPath )
48+ if err != nil {
49+ return err
50+ }
51+ defer fp .Close ()
52+ t := template .New ("" )
53+ t , err = t .Parse (tmpl )
54+ if err != nil {
55+ return err
56+ }
57+ return t .Execute (fp , data )
58+ }
59+
60+ func main () {
61+ flag .Parse ()
62+ if len (flag .Arg (0 )) > 0 {
63+ listUrl = flag .Arg (0 )
64+ }
65+ list1 , err := downloadList ()
66+ if err != nil {
67+ panic (err .Error ())
68+ }
69+ err = writeConf (list1 )
70+ if err != nil {
71+ panic (err .Error ())
72+ }
73+ }
You can’t perform that action at this time.
0 commit comments