func (a *Agent) OfflineClear(flag *OfflineClearFlag) (err error) {
	if flag == nil {
		flag = (&OfflineClearFlag{}).Done(false)
	}
	form := core.NewForm().
		WithInt("flag", flag.flag)
	result := &types.OfflineBasicResult{}
	err = a.callOfflineApi(apiOfflineClear, form, result)
	if err == nil && !result.State {
		err = types.MakeOfflineError(result.ErrorCode, result.ErrorMsg)
	}
	return
}
/*
Clear specific type of offline tasks.

The "flag" parameter indicates which type of tasks will be clear, you can pass nil to
clear the done tasks but keep the downloaded files.
package elevengo
import (
	"github.com/deadblue/elevengo/internal/core"
	"github.com/deadblue/elevengo/internal/types"
	"time"
)
const (
	apiOfflineSpace   = "https://115.com/"
	apiOfflineList    = "https://115.com/web/lixian/?ct=lixian&ac=task_lists"
	apiOfflineAddUrl  = "https://115.com/web/lixian/?ct=lixian&ac=add_task_url"
	apiOfflineAddUrls = "https://115.com/web/lixian/?ct=lixian&ac=add_task_urls"
	apiOfflineDelete  = "https://115.com/web/lixian/?ct=lixian&ac=task_del"
	apiOfflineClear   = "https://115.com/web/lixian/?ct=lixian&ac=task_clear"
)
type OfflineClearFlag struct {
	flag int
}
func (f *OfflineClearFlag) All(delete bool) *OfflineClearFlag {
	if delete {
		f.flag = 5
	} else {
		f.flag = 1
	}
	return f
}
func (f *OfflineClearFlag) Done(delete bool) *OfflineClearFlag {
	if delete {
		f.flag = 4
	} else {
		f.flag = 0
	}
	return f
}
func (f *OfflineClearFlag) Failed() *OfflineClearFlag {
	f.flag = 2
	return f
}
func (f *OfflineClearFlag) Running() *OfflineClearFlag {
	f.flag = 3
	return f
}
type OfflineTaskStatus int
func (s OfflineTaskStatus) IsRunning() bool {
	return s == 1
}
func (s OfflineTaskStatus) IsDone() bool {
	return s == 2
}
func (s OfflineTaskStatus) IsFailed() bool {
	return s == -1
}
type OfflineTask struct {
	InfoHash string
	Name string
	Url string
	Status OfflineTaskStatus
	Percent float64
	FileId string
}
func (a *Agent) updateOfflineToken() (err error) {
	qs := core.NewQueryString().
		WithString("ct", "offline").
		WithString("ac", "space").
		WithInt64("_", time.Now().Unix())
	result := &types.OfflineSpaceResult{}
	if err = a.hc.JsonApi(apiOfflineSpace, qs, nil, result); err != nil {
		return
	}
	if a.ot == nil {
		a.ot = &types.OfflineToken{}
	}
	a.ot.Sign = result.Sign
	a.ot.Time = result.Time
	return nil
}
func (a *Agent) callOfflineApi(url string, form core.Form, result interface{}) (err error) {
	if a.ot == nil {
		if err = a.updateOfflineToken(); err != nil {
			return
		}
	}
	if form == nil {
		form = core.NewForm()
	}
	form.WithInt("uid", a.ui.Id).
		WithString("sign", a.ot.Sign).
		WithInt64("time", a.ot.Time)
	err = a.hc.JsonApi(url, nil, form, result)
	return
}
func (a *Agent) OfflineList(cursor Cursor) (tasks []*OfflineTask, err error) {
	oc, ok := cursor.(*offlineCursor)
	if !ok {
		return nil, errOfflineCursorInvalid
	}
	form := core.NewForm().WithInt("page", oc.page)
	result := &types.OfflineListResult{}
	err = a.callOfflineApi(apiOfflineList, form, result)
	if err == nil && result.IsFailed() {
		err = types.MakeOfflineError(result.ErrorCode, result.ErrorMsg)
	}
	if err != nil {
		return
	}
	tasks = make([]*OfflineTask, len(result.Tasks))
	for index, data := range result.Tasks {
		tasks[index] = &OfflineTask{
			InfoHash: data.InfoHash,
			Name:     data.Name,
			Url:      data.Url,
			Status:   OfflineTaskStatus(data.Status),
			Percent:  data.Precent,
			FileId:   data.FileId,
		}
	}
	oc.used, oc.total = true, result.Count
	oc.page, oc.pageCount = result.Page, result.PageCount
	return
}
func (a *Agent) OfflineAdd(url ...string) (err error) {
	form, isSingle := core.NewForm(), len(url) == 1
	if isSingle {
		form.WithString("url", url[0])
		result := &types.OfflineAddUrlResult{}
		err = a.callOfflineApi(apiOfflineAddUrl, form, result)
	} else {
		form.WithStrings("url", url)
		result := &types.OfflineAddUrlsResult{}
		err = a.callOfflineApi(apiOfflineAddUrls, form, result)
	}
	return
}
func (a *Agent) OfflineDelete(deleteFile bool, hash ...string) (err error) {
	form := core.NewForm().WithStrings("hash", hash)
	if deleteFile {
		form.WithInt("flag", 1)
	}
	result := &types.OfflineBasicResult{}
	err = a.callOfflineApi(apiOfflineDelete, form, result)
	if err == nil && !result.State {
		err = types.MakeOfflineError(result.ErrorCode, result.ErrorMsg)
	}
	return
}