-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtorrent.go
More file actions
35 lines (30 loc) · 795 Bytes
/
torrent.go
File metadata and controls
35 lines (30 loc) · 795 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
32
33
34
35
package main
import (
"io"
"github.com/jackpal/bencode-go"
)
type FileInfo struct {
Name string "name"
Length int64 "length"
Pieces string "pieces"
PieceLength int "piece length"
}
type TorrentInfo struct {
Announce string "announce"
AnnounceList [][]string "announce-list"
Info FileInfo "info"
HttpSeeds []string "httpseeds"
}
func generateTorrent(writer io.Writer, url string) error {
info := FileInfo{
Name: "file.mp3",
Length: 1024,
Pieces: "01234567890123456789",
PieceLength: 1024,
}
announceList := [][]string{[]string{url}}
seeds := []string{url}
torrent := TorrentInfo{Info: info, Announce: url, HttpSeeds: seeds, AnnounceList: announceList}
err := bencode.Marshal(writer, torrent)
return err
}