github.com/fzfile/BaiduPCS-Go@v0.0.0-20200606205115-4408961cf336/internal/pcscommand/cloud_dl.go (about) 1 package pcscommand 2 3 import ( 4 "fmt" 5 "github.com/fzfile/BaiduPCS-Go/baidupcs" 6 ) 7 8 // RunCloudDlAddTask 执行添加离线下载任务 9 func RunCloudDlAddTask(sourceURLs []string, savePath string) { 10 var ( 11 err error 12 pcs = GetBaiduPCS() 13 ) 14 err = matchPathByShellPatternOnce(&savePath) 15 if err != nil { 16 fmt.Println(err) 17 return 18 } 19 20 var taskid int64 21 for k := range sourceURLs { 22 taskid, err = pcs.CloudDlAddTask(sourceURLs[k], savePath+baidupcs.PathSeparator) 23 if err != nil { 24 fmt.Printf("[%d] %s, 地址: %s\n", k+1, err, sourceURLs[k]) 25 continue 26 } 27 28 fmt.Printf("[%d] 添加离线任务成功, 任务ID(task_id): %d, 源地址: %s, 保存路径: %s\n", k+1, taskid, sourceURLs[k], savePath) 29 } 30 } 31 32 // RunCloudDlQueryTask 精确查询离线下载任务 33 func RunCloudDlQueryTask(taskIDs []int64) { 34 cl, err := GetBaiduPCS().CloudDlQueryTask(taskIDs) 35 if err != nil { 36 fmt.Printf("%s\n", err) 37 return 38 } 39 40 fmt.Println(cl) 41 } 42 43 // RunCloudDlListTask 查询离线下载任务列表 44 func RunCloudDlListTask() { 45 cl, err := GetBaiduPCS().CloudDlListTask() 46 if err != nil { 47 fmt.Printf("%s\n", err) 48 return 49 } 50 51 fmt.Println(cl) 52 } 53 54 // RunCloudDlCancelTask 取消离线下载任务 55 func RunCloudDlCancelTask(taskIDs []int64) { 56 for _, id := range taskIDs { 57 err := GetBaiduPCS().CloudDlCancelTask(id) 58 if err != nil { 59 fmt.Printf("[%d] %s\n", id, err) 60 continue 61 } 62 63 fmt.Printf("[%d] 取消成功\n", id) 64 } 65 } 66 67 // RunCloudDlDeleteTask 删除离线下载任务 68 func RunCloudDlDeleteTask(taskIDs []int64) { 69 for _, id := range taskIDs { 70 err := GetBaiduPCS().CloudDlDeleteTask(id) 71 if err != nil { 72 fmt.Printf("[%d] %s\n", id, err) 73 continue 74 } 75 76 fmt.Printf("[%d] 删除成功\n", id) 77 } 78 } 79 80 // RunCloudDlClearTask 清空离线下载任务记录 81 func RunCloudDlClearTask() { 82 total, err := GetBaiduPCS().CloudDlClearTask() 83 if err != nil { 84 fmt.Printf("%s\n", err) 85 return 86 } 87 88 fmt.Printf("%s成功, 共清除 %d 条记录\n", baidupcs.OperationCloudDlClearTask, total) 89 return 90 }