xldl

package module
v0.0.0-...-f0a3e49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 27, 2022 License: MIT Imports: 2 Imported by: 1

README

xldl

Xunlei download engine SDK

迅雷下载引擎SDK Go语言版

32位xldl.dll, 64位系统golang编译或调式时环境变量修改增加: GOARCH=386;CGO_ENABLED=1

使用方法:

// XLSdkTest project main.go
// api说明见:http://open.xunlei.com/wiki/api_doc.html#1
package main

import (
	"fmt"
	"os"

	"time"

	"gitee.com/snxamdf/xldl"

	"os/exec"
	"path/filepath"
)

var (
	exitLoop bool
)

func main() {

	file, _ := exec.LookPath(os.Args[0])
	path := filepath.Dir(file)

	println(path)

	if !xldl.InitXLEngine() {
		fmt.Println("初始引擎失败!")
		return
	}
	defer xldl.UnInitXLEngine()
	dloader := xldl.NewXLDownloader(path)

	task := dloader.AddTask("http://sw.bos.baidu.com/sw-search-sp/software/19de58890ffb8/QQ_8.6.18804.0_setup.exe", "QQ_8.6.18804.0_setup.exe")
	fmt.Println("任务启动:", task.Start())

	go func() {
		var exit string
		for {
			fmt.Scan(&exit)
			if exit == "q" {
				exitLoop = true
				break
			}
		}
	}()

	for !exitLoop {
		info, ret := task.Info()
		if ret {
			fmt.Printf("TotalSize=%d, Percent=%f, Speed=%d\n", info.TotalSize, info.Percent, info.Speed)
			switch info.Stat {
			case xldl.TSC_COMPLETE:
				fmt.Println("下载完成")
				task.Delete()
				return
			case xldl.TSC_ERROR:
				fmt.Println("下载错误。")
			}
		}
		time.Sleep(time.Millisecond * 500)
	}
	task.Stop()
	task.Delete()
	fmt.Println("删除:", task.DeleteTempFile())
}


Documentation

Overview

xldl project xldl.go api说明见:http://open.xunlei.com/wiki/api_doc.html#1

api说明见:http://open.xunlei.com/wiki/api_doc.html#1

Index

Constants

View Source
const (
	NOITEM = 0 + iota
	TSC_ERROR
	TSC_PAUSE
	TSC_DOWNLOAD
	TSC_COMPLETE
	TSC_STARTPENDING
	TSC_STOPPENDING
)
View Source
const (
	TASK_ERROR_UNKNOWN                = 0x00 // 未知错误
	TASK_ERROR_DISK_CREATE            = 0x01 // 创建文件失败
	TASK_ERROR_DISK_WRITE             = 0x02 // 写文件失败
	TASK_ERROR_DISK_READ              = 0x03 // 读文件失败
	TASK_ERROR_DISK_RENAME            = 0x04 // 重命名失败
	TASK_ERROR_DISK_PIECEHASH         = 0x05 // 文件片校验失败
	TASK_ERROR_DISK_FILEHASH          = 0x06 // 文件全文校验失败
	TASK_ERROR_DISK_DELETE            = 0x07 // 删除文件失败失败
	TASK_ERROR_DOWN_INVALID           = 0x10 // 无效的DOWN地址
	TASK_ERROR_PROXY_AUTH_TYPE_UNKOWN = 0x20 // 代理类型未知
	TASK_ERROR_PROXY_AUTH_TYPE_FAILED = 0x21 // 代理认证失败
	TASK_ERROR_HTTPMGR_NOT_IP         = 0x30 // http下载中无ip可用
	TASK_ERROR_TIMEOUT                = 0x40 // 任务超时
	TASK_ERROR_CANCEL                 = 0x41 // 任务取消
	TASK_ERROR_TP_CRASHED             = 0x42 // MINITP崩溃
	TASK_ERROR_ID_INVALID             = 0x43 // TaskId 非法
)
View Source
const (
	PROXY_TYPE_IE     = 0
	PROXY_TYPE_HTTP   = 1
	PROXY_TYPE_SOCK4  = 2
	PROXY_TYPE_SOCK5  = 3
	PROXY_TYPE_FTP    = 4
	PROXY_TYPE_UNKOWN = 255
)
View Source
const (
	PROXY_AUTH_NONE = 0 + iota
	PROXY_AUTH_AUTO
	PROXY_AUTH_BASE64
	PROXY_AUTH_NTLM
	PROXY_AUTH_DEGEST
	PROXY_AUTH_UNKOWN
)
View Source
const (
	MAX_PATH = 260
)

Variables

This section is empty.

Functions

func InitXLEngine

func InitXLEngine() bool

func UnInitXLEngine

func UnInitXLEngine() bool

func XL_CreateBTTaskByThunder

func XL_CreateBTTaskByThunder(pszPath string) uint32

func XL_CreateTask

func XL_CreateTask(param *DownTaskParam) uintptr

func XL_CreateTaskByThunder

func XL_CreateTaskByThunder(pszUrl, pszFileName, pszReferUrl, pszCharSet, pszCookie string) uint32

func XL_CreateTaskByURL

func XL_CreateTaskByURL(url, path, filename string, IsResume int32) uintptr

func XL_DelTempFile

func XL_DelTempFile(stParam *DownTaskParam) bool

func XL_DeleteTask

func XL_DeleteTask(hTask uintptr) bool

func XL_ForceStopTask

func XL_ForceStopTask(hTask uintptr) bool

func XL_GetFileSizeWithUrl

func XL_GetFileSizeWithUrl(lpURL string) (int64, bool)

func XL_Init

func XL_Init() bool

func XL_ParseThunderPrivateUrl

func XL_ParseThunderPrivateUrl(pszThunderUrl string) (string, bool)

func XL_SetFileIdAndSize

func XL_SetFileIdAndSize(hTask uintptr, szFileId FileId, nFileSize uint64) bool

func XL_SetProxy

func XL_SetProxy(stProxyInfo *DOWN_PROXY_INFO) bool

func XL_SetSpeedLimit

func XL_SetSpeedLimit(nKBps int32)

func XL_SetUploadSpeedLimit

func XL_SetUploadSpeedLimit(nTcpKBps, nOtherKBps uint32)

func XL_SetUserAgent

func XL_SetUserAgent(pszUserAgent string)

func XL_StartTask

func XL_StartTask(hTask uintptr) bool

func XL_StopTask

func XL_StopTask(hTask uintptr) bool

func XL_UnInit

func XL_UnInit() bool

Types

type DOWN_PROXY_AUTH_TYPE

type DOWN_PROXY_AUTH_TYPE int32

type DOWN_PROXY_INFO

type DOWN_PROXY_INFO struct {
	IEProxy int32
	Proxy   int32
	PType   DOWN_PROXY_TYPE
	AType   DOWN_PROXY_AUTH_TYPE
	Host    [2048]uint16
	Port    int32
	User    [50]uint16
	Pwd     [50]uint16
	Domain  [2048]uint16
}

type DOWN_PROXY_TYPE

type DOWN_PROXY_TYPE int32

type DOWN_TASK_STATUS

type DOWN_TASK_STATUS int32

type DownTaskInfo

type DownTaskInfo struct {
	Stat          DOWN_TASK_STATUS
	FailCode      TASK_ERROR_TYPE
	Filename      [MAX_PATH]uint16
	Reserved0     [MAX_PATH]uint16
	TotalSize     int64   // 该任务总大小(字节)
	TotalDownload int64   // 下载有效字节数(可能存在回退的情况)
	Percent       float32 // 下载进度

	SrcTotal int32 // 总资源数
	SrcUsing int32 // 可用资源数

	DonationP2P int64 // p2p贡献字节数

	DonationOrgin int64 // 原始资源共享字节数
	DonationP2S   int64 // 镜像资源共享字节数

	Speed    int32 // 即时速度(字节/秒)
	SpeedP2S int32 // 即时速度(字节/秒)
	SpeedP2P int32 // 即时速度(字节/秒)
	// contains filtered or unexported fields
}

他按4字节对齐的,然迅雷要求按1字节对齐,so下面两个有问题了,要换种方式了

func XL_QueryTaskInfoEx

func XL_QueryTaskInfoEx(hTask uintptr) (*DownTaskInfo, bool)

func (*DownTaskInfo) IsCreatingFile

func (c *DownTaskInfo) IsCreatingFile() bool

func (*DownTaskInfo) IsOriginUsable

func (c *DownTaskInfo) IsOriginUsable() bool

func (*DownTaskInfo) SetDefault

func (c *DownTaskInfo) SetDefault()

func (*DownTaskInfo) SetIsCreatingFile

func (c *DownTaskInfo) SetIsCreatingFile(val bool)

func (*DownTaskInfo) SetIsOriginUsable

func (c *DownTaskInfo) SetIsOriginUsable(val bool)

type DownTaskParam

type DownTaskParam struct {
	IsOnlyOriginal int32 // 是否只从原始地址下载

	DisableAutoRename int32 // 禁止智能命名
	IsResume          int32 // 是否用续传
	// contains filtered or unexported fields
}

func (*DownTaskParam) SetDefault

func (c *DownTaskParam) SetDefault()

type FileId

type FileId [40]byte

type TASK_ERROR_TYPE

type TASK_ERROR_TYPE int32

type XLDownloader

type XLDownloader struct {
	Tasks    map[string]*XLTask
	SavePath string
}

func NewXLDownloader

func NewXLDownloader(savePath string) *XLDownloader

func (*XLDownloader) AddTask

func (self *XLDownloader) AddTask(wstrUrl, wstrFileName string) *XLTask

func (*XLDownloader) Remove

func (self *XLDownloader) Remove(task *XLTask)

func (*XLDownloader) RemoveAll

func (self *XLDownloader) RemoveAll()

type XLTask

type XLTask struct {
	Url      string
	FileName string
	SavePath string
	// contains filtered or unexported fields
}

func (*XLTask) Delete

func (self *XLTask) Delete() bool

删除一个任务

func (*XLTask) DeleteTempFile

func (self *XLTask) DeleteTempFile() bool

func (*XLTask) Info

func (self *XLTask) Info() (*DownTaskInfo, bool)

func (*XLTask) Start

func (self *XLTask) Start() bool

启动一个任务

func (*XLTask) Stop

func (self *XLTask) Stop() bool

停止一个任务

Directories

Path Synopsis
XLSdkTest document
XLSdkTest document

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL