Пример #1
0
func (self *PiDownloader) getAria2GlobalStat(args []string) (string, error) {
	globalStat, err := aria2rpc.GetGlobalStat()
	if err != nil {
		return "", err
	}
	speed := utils.FormatSizeString(globalStat["downloadSpeed"].(string))
	numActive := globalStat["numActive"].(string)
	numStopped := globalStat["numStopped"].(string)
	numWaiting := globalStat["numWaiting"].(string)
	return fmt.Sprintf("spd:%s ; act:%s ; wait:%s ; stop:%s", speed, numActive, numWaiting, numStopped), nil
}
Пример #2
0
func (self *PiDownloader) getCurrentDownloadInfo() (string, error) {
	globalStat, getStatErr := aria2rpc.GetGlobalStat()
	if getStatErr != nil {
		return "", getStatErr
	}
	// total active download task
	numActive, _ := strconv.Atoi(globalStat["numActive"].(string))
	if numActive == 0 {
		return "no active task", nil
	}

	// total speed
	speed := utils.FormatSizeString(globalStat["downloadSpeed"].(string))

	// the longest left time in active download task
	var longestTimeLeft int64 = -1
	keys := []string{"gid", "totalLength", "completedLength", "downloadSpeed"}
	tasks, getActErr := aria2rpc.GetActive(keys)
	if getActErr != nil {
		return "", getActErr
	}
	for _, task := range tasks {
		dSpd := task["downloadSpeed"]
		if dSpd != nil {
			total, _ := strconv.ParseInt(task["totalLength"].(string), 10, 64)
			completed, _ := strconv.ParseInt(task["completedLength"].(string), 10, 64)
			spd, _ := strconv.ParseInt(dSpd.(string), 10, 64)
			if spd > 0 {
				timeLeft := (total - completed) / spd
				if timeLeft > longestTimeLeft {
					longestTimeLeft = timeLeft
				}
			}
		}
	}

	var timeLeftFmt string
	if longestTimeLeft > 0 {
		timeLeftFmt = utils.FormatTime(longestTimeLeft)
	} else {
		timeLeftFmt = "N/A"
	}
	return fmt.Sprintf("spd: %s ; act: %d ; left: %s", speed, numActive, timeLeftFmt), nil
}