-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathurlpaser.go
49 lines (45 loc) · 1.49 KB
/
urlpaser.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"regexp";
"strings";
"url";
"fmt";
)
type URLParse struct {
id int
size int
}
func (up *URLParse) urlparser(c chan string, tf chan map[string]string) {
ed2k,_ := regexp.Compile("href=\"ed2k://");
re,_ := regexp.Compile("<([^>]|\n)*>|\t|\r");
parsedlink:= make(map[string]string)
for i := 0; i < up.size; i++ {
if pas,err := ContGet(<-c); err == nil {
pas = ed2k.ReplaceAllString(pas,">\ned2k://");
pas = re.ReplaceAllString(pas,"\n");
pasarray := strings.Split(pas,"\n");
for is := 1; is < len(pasarray); is++ {
if strings.HasPrefix(pasarray[is],"ed2k://") {
stringindex:=strings.Index(pasarray[is],"\"")
var edurl string
if stringindex < 1{
edurl = pasarray[is];
edurl,_ = url.QueryUnescape(edurl);
}else{
edurl = pasarray[is][0:stringindex];
edurl,_ = url.QueryUnescape(edurl);
}
spedurl := strings.Split(edurl,"|")
if len(spedurl) > 5 && len(spedurl[4]) > 20 {
key:=spedurl[4]
parsedlink[key]=edurl;
}
}
}
}else{
fmt.Printf("can't open url; err=%s\n", err.String())
}
}
tf<-parsedlink;
return;
}