本文整理汇总了Golang中github.com/anacrolix/torrent.Client类的典型用法代码示例。如果您正苦于以下问题:Golang Client类的具体用法?Golang Client怎么用?Golang Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Client类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: loadTorrentMagnet
/**
Load a magnet and send to be watched and modified
*/
func loadTorrentMagnet(client torrent.Client, magnet string) torrent.Torrent {
torrentMagnet, err := client.AddMagnet(magnet)
util.CheckError(err)
return torrentMagnet
}
开发者ID:scottclin,项目名称:etontables,代码行数:10,代码来源:magnet.go
示例2: NewClient
// NewClient creates a new torrent client based on a magnet or a torrent file.
// If the torrent file is on http, we try downloading it.
func NewClient(torrentPath string, port int, seed bool) (client Client, err error) {
var t torrent.Torrent
var c *torrent.Client
client.Port = port
// Create client.
c, err = torrent.NewClient(&torrent.Config{
DataDir: os.TempDir(),
NoUpload: !seed,
Seed: seed,
})
if err != nil {
return client, ClientError{Type: "creating torrent client", Origin: err}
}
client.Client = c
// Add torrent.
// Add as magnet url.
if strings.HasPrefix(torrentPath, "magnet:") {
if t, err = c.AddMagnet(torrentPath); err != nil {
return client, ClientError{Type: "adding torrent", Origin: err}
}
} else {
// Otherwise add as a torrent file.
// If it's online, we try downloading the file.
if isHTTP.MatchString(torrentPath) {
if torrentPath, err = downloadFile(torrentPath); err != nil {
return client, ClientError{Type: "downloading torrent file", Origin: err}
}
}
// Check if the file exists.
if _, err = os.Stat(torrentPath); err != nil {
return client, ClientError{Type: "file not found", Origin: err}
}
if t, err = c.AddTorrentFromFile(torrentPath); err != nil {
return client, ClientError{Type: "adding torrent to the client", Origin: err}
}
}
client.Torrent = t
go func() {
<-t.GotInfo()
t.DownloadAll()
// Prioritize first 5% of the file.
client.getLargestFile().PrioritizeRegion(0, int64(t.NumPieces()/100*5))
}()
go client.addBlocklist()
return
}
开发者ID:thesyncim,项目名称:go-peerflix,代码行数:62,代码来源:client.go
示例3: addTestPeer
func addTestPeer(client *torrent.Client) {
for _, t := range client.Torrents() {
t.AddPeers([]torrent.Peer{{
IP: testPeerAddr.IP,
Port: testPeerAddr.Port,
}})
}
}
开发者ID:jakop345,项目名称:torrent,代码行数:8,代码来源:main.go
示例4: bytesCompleted
func bytesCompleted(tc *torrent.Client) (ret int64) {
for _, t := range tc.Torrents() {
if t.Info() != nil {
ret += t.BytesCompleted()
}
}
return
}
开发者ID:soul9,项目名称:torrent,代码行数:8,代码来源:main.go
示例5: NewClient
// NewClient creates a new torrent client based on a magnet or a torrent file.
// If the torrent file is on http, we try downloading it.
func NewClient(cfg ClientConfig) (client Client, err error) {
var t *torrent.Torrent
var c *torrent.Client
client.Config = cfg
// Create client.
c, err = torrent.NewClient(&torrent.Config{
DataDir: os.TempDir(),
NoUpload: !cfg.Seed,
Seed: cfg.Seed,
DisableTCP: !cfg.TCP,
ListenAddr: fmt.Sprintf(":%d", cfg.TorrentPort),
})
if err != nil {
return client, ClientError{Type: "creating torrent client", Origin: err}
}
client.Client = c
// Add torrent.
// Add as magnet url.
if strings.HasPrefix(cfg.TorrentPath, "magnet:") {
if t, err = c.AddMagnet(cfg.TorrentPath); err != nil {
return client, ClientError{Type: "adding torrent", Origin: err}
}
} else {
// Otherwise add as a torrent file.
// If it's online, we try downloading the file.
if isHTTP.MatchString(cfg.TorrentPath) {
if cfg.TorrentPath, err = downloadFile(cfg.TorrentPath); err != nil {
return client, ClientError{Type: "downloading torrent file", Origin: err}
}
}
if t, err = c.AddTorrentFromFile(cfg.TorrentPath); err != nil {
return client, ClientError{Type: "adding torrent to the client", Origin: err}
}
}
client.Torrent = t
client.Torrent.SetMaxEstablishedConns(cfg.MaxConnections)
go func() {
<-t.GotInfo()
t.DownloadAll()
// Prioritize first 5% of the file.
client.getLargestFile().PrioritizeRegion(0, int64(t.NumPieces()/100*5))
}()
go client.addBlocklist()
return
}
开发者ID:Sioro-Neoku,项目名称:go-peerflix,代码行数:60,代码来源:client.go
示例6: addTestPeer
func addTestPeer(client *torrent.Client) {
for _, t := range client.Torrents() {
if testPeerAddr != nil {
if err := t.AddPeers([]torrent.Peer{{
IP: testPeerAddr.IP,
Port: testPeerAddr.Port,
}}); err != nil {
log.Print(err)
}
}
}
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:12,代码来源:main.go
示例7: NewClient
// NewClient creates a new torrent client based on a magnet or a torrent file.
// If the torrent file is on http, we try downloading it.
func NewClient(torrentPath string) (client Client, err error) {
var t torrent.Torrent
var c *torrent.Client
// Create client.
c, err = torrent.NewClient(&torrent.Config{
DataDir: os.TempDir(),
NoUpload: !(*seed),
})
if err != nil {
return client, ClientError{Type: "creating torrent client", Origin: err}
}
client.Client = c
// Add torrent.
// Add as magnet url.
if strings.HasPrefix(torrentPath, "magnet:") {
if t, err = c.AddMagnet(torrentPath); err != nil {
return client, ClientError{Type: "adding torrent", Origin: err}
}
} else {
// Otherwise add as a torrent file.
// If it's online, we try downloading the file.
if isHTTP.MatchString(torrentPath) {
if torrentPath, err = downloadFile(torrentPath); err != nil {
return client, ClientError{Type: "downloading torrent file", Origin: err}
}
}
// Check if the file exists.
if _, err = os.Stat(torrentPath); err != nil {
return client, ClientError{Type: "file not found", Origin: err}
}
if t, err = c.AddTorrentFromFile(torrentPath); err != nil {
return client, ClientError{Type: "adding torrent to the client", Origin: err}
}
}
client.Torrent = t
go func() {
<-t.GotInfo()
t.DownloadAll()
}()
return
}
开发者ID:testbots,项目名称:go-peerflix,代码行数:54,代码来源:client.go
示例8: loadTorrentFile
/**
Load up the newly found file that has been sent though the channel
Sends for watching and mofication
*/
func loadTorrentFile(client torrent.Client, torrentFileString string) torrent.Torrent {
//Lets load up any file that comes though the channel
if _, err := os.Stat(torrentFileString); os.IsNotExist(err) {
fmt.Fprintf(os.Stderr, "The file handler was unable to stat the file: %s\n", torrentFileString)
}
torrentFile, err := client.AddTorrentFromFile(torrentFileString)
util.CheckError(err)
return torrentFile
}
开发者ID:scottclin,项目名称:etontables,代码行数:18,代码来源:filehandler.go
示例9: totalBytesEstimate
// Returns an estimate of the total bytes for all torrents.
func totalBytesEstimate(tc *torrent.Client) (ret int64) {
var noInfo, hadInfo int64
for _, t := range tc.Torrents() {
info := t.Info()
if info == nil {
noInfo++
continue
}
ret += info.TotalLength()
hadInfo++
}
if hadInfo != 0 {
// Treat each torrent without info as the average of those with,
// rounded up.
ret += (noInfo*ret + hadInfo - 1) / hadInfo
}
return
}
开发者ID:soul9,项目名称:torrent,代码行数:19,代码来源:main.go
示例10: actionOnTorrent
func actionOnTorrent(client torrent.Client, torrentName string, action string) bool {
allTorrents := client.Torrents()
for _, torrent := range allTorrents {
if torrent.Name() == torrentName {
switch action {
case util.Start:
torrent.DownloadAll()
return true
case util.Kill:
torrent.Drop()
return true
}
}
}
return false
}
开发者ID:scottclin,项目名称:etontables,代码行数:18,代码来源:control.go
示例11: addTorrents
func addTorrents(client *torrent.Client) {
for _, arg := range opts.Torrent {
t := func() *torrent.Torrent {
if strings.HasPrefix(arg, "magnet:") {
t, err := client.AddMagnet(arg)
if err != nil {
log.Fatalf("error adding magnet: %s", err)
}
return t
} else {
metaInfo, err := metainfo.LoadFromFile(arg)
if err != nil {
fmt.Fprintf(os.Stderr, "error loading torrent file %q: %s\n", arg, err)
os.Exit(1)
}
t, err := client.AddTorrent(metaInfo)
if err != nil {
log.Fatal(err)
}
return t
}
}()
torrentBar(t)
err := t.AddPeers(func() (ret []torrent.Peer) {
for _, ta := range opts.TestPeer {
ret = append(ret, torrent.Peer{
IP: ta.IP,
Port: ta.Port,
})
}
return
}())
if err != nil {
log.Fatal(err)
}
go func() {
<-t.GotInfo()
t.DownloadAll()
}()
}
}
开发者ID:CaptainIlu,项目名称:cloud-torrent,代码行数:41,代码来源:main.go
注:本文中的github.com/anacrolix/torrent.Client类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论