add .torrent link support
This commit is contained in:
@@ -180,8 +180,16 @@ func handle(vpntor, outdir, content string) error {
|
||||
}
|
||||
|
||||
func findMagnets(s string) []string {
|
||||
magnetRegexp := regexp.MustCompile(`magnet:.xt[^ $"]*`)
|
||||
return magnetRegexp.FindAllString(s, -1)
|
||||
patterns := []string{
|
||||
`magnet:.xt[^ $"]*`,
|
||||
`https:..[^"]*\.torrent`,
|
||||
}
|
||||
matches := []string{}
|
||||
for _, pattern := range patterns {
|
||||
magnetRegexp := regexp.MustCompile(pattern)
|
||||
matches = append(matches, magnetRegexp.FindAllString(s, -1)...)
|
||||
}
|
||||
return matches
|
||||
}
|
||||
|
||||
func submit(vpntor, outdir, magnet string) (*http.Response, error) {
|
||||
|
||||
@@ -239,6 +239,10 @@ func TestFindMagnets(t *testing.T) {
|
||||
s: `here is some magnet:-xt1 and magnet:-xt2 another one <a href="magnet:-xt3">link</a>`,
|
||||
l: 3,
|
||||
},
|
||||
{
|
||||
s: `here is a link https://my.domain/a.b/c.torrent, and another <a href="https://my.domain/a/b/c.torrent"></a>`,
|
||||
l: 2,
|
||||
},
|
||||
}
|
||||
|
||||
for i, c := range cases {
|
||||
|
||||
Reference in New Issue
Block a user