forked from pyed/rtelegram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.go
36 lines (31 loc) · 787 Bytes
/
add.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
package main
import (
"fmt"
"path/filepath"
"time"
)
// 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: %s"+err.Error(), false)
continue
}
if filename == "" {
filename = filepath.Base(url)
}
if TimeStamp != "" {
t := time.Now()
t.Format("Mon Jan _2 2006 15:04:05")
send(fmt.Sprintf("%s - Added: %s", t, filename), false) }
else {
send(fmt.Sprintf("Added: %s", filename), false) }
}
}