-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathadd.go
More file actions
31 lines (26 loc) · 657 Bytes
/
add.go
File metadata and controls
31 lines (26 loc) · 657 Bytes
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
package main
import (
"fmt"
"path/filepath"
)
// add takes an URL to a .torrent file to add it to rtorrent
func add(tokens []string, filename string) {
if len(tokens) == 0 {
send("add: needs at least one URL", false)
return
}
// loop over the URL/s and add them
// WARNING: it doesn't report error if the same torrent already added.
for _, url := range tokens {
if err := rtorrent.Download(url); err != nil {
logger.Print("add:", err)
send("add: "+err.Error(), false)
continue
}
displayName := filename
if displayName == "" {
displayName = filepath.Base(url)
}
send(fmt.Sprintf("Added: %s", displayName), false)
}
}