Beispiel #1
0
func (s *BTService) downloadProgress() {
	rotateTicker := time.NewTicker(5 * time.Second)
	defer rotateTicker.Stop()

	showNext := 0
	for {
		select {
		case <-rotateTicker.C:
			if s.Session.IsPaused() && s.dialogProgressBG != nil {
				s.dialogProgressBG.Close()
				s.dialogProgressBG = nil
				continue
			}

			torrentsVector := s.Session.GetTorrents()
			torrentsVectorSize := int(torrentsVector.Size())
			totalProgress := 0
			activeTorrents := make([]*activeTorrent, 0)

			for i := 0; i < torrentsVectorSize; i++ {
				torrentHandle := torrentsVector.Get(i)
				if torrentHandle.IsValid() == false {
					continue
				}

				torrentStatus := torrentHandle.Status(uint(libtorrent.TorrentHandleQueryName))
				if torrentStatus.GetHasMetadata() == false || torrentStatus.GetPaused() || s.Session.IsPaused() {
					continue
				}

				torrentName := torrentStatus.GetName()
				progress := int(float64(torrentStatus.GetProgress()) * 100)

				if progress < 100 {
					activeTorrents = append(activeTorrents, &activeTorrent{
						torrentName: torrentName,
						progress:    progress,
					})
					totalProgress += progress
				} else {
					finished_time := torrentStatus.GetFinishedTime()
					if s.config.SeedTimeLimit > 0 {
						if finished_time >= s.config.SeedTimeLimit {
							s.log.Noticef("Seeding time limit reached, pausing %s", torrentName)
							torrentHandle.AutoManaged(false)
							torrentHandle.Pause(1)
							continue
						}
					}
					if s.config.SeedTimeRatioLimit > 0 {
						timeRatio := 0
						download_time := torrentStatus.GetActiveTime() - finished_time
						if download_time > 1 {
							timeRatio = finished_time * 100 / download_time
						}
						if timeRatio >= s.config.SeedTimeRatioLimit {
							s.log.Noticef("Seeding time ratio reached, pausing %s", torrentName)
							torrentHandle.AutoManaged(false)
							torrentHandle.Pause(1)
							continue
						}
					}
					if s.config.ShareRatioLimit > 0 {
						ratio := int64(0)
						allTimeDownload := torrentStatus.GetAllTimeDownload()
						if allTimeDownload > 0 {
							ratio = torrentStatus.GetAllTimeUpload() * 100 / allTimeDownload
						}
						if ratio >= int64(s.config.ShareRatioLimit) {
							s.log.Noticef("Share ratio reached, pausing %s", torrentName)
							torrentHandle.AutoManaged(false)
							torrentHandle.Pause(1)
						}
					}
				}
			}

			activeDownloads := len(activeTorrents)
			if activeDownloads > 0 {
				showProgress := totalProgress / activeDownloads
				showTorrent := "Total"
				if showNext >= activeDownloads {
					showNext = 0
				} else {
					showProgress = activeTorrents[showNext].progress
					showTorrent = activeTorrents[showNext].torrentName
					if len(showTorrent) > 32 {
						showTorrent = showTorrent[:32]
					}
					showNext += 1
				}
				if s.dialogProgressBG == nil {
					s.dialogProgressBG = xbmc.NewDialogProgressBG("Quasar", "")
				}
				s.dialogProgressBG.Update(showProgress, fmt.Sprintf("Quasar - %s", showTorrent))
			} else if s.dialogProgressBG != nil {
				s.dialogProgressBG.Close()
				s.dialogProgressBG = nil
			}
		}
	}
}
Beispiel #2
0
func (s *BTService) downloadProgress() {
	rotateTicker := time.NewTicker(5 * time.Second)
	defer rotateTicker.Stop()

	showNext := 0
	for {
		select {
		case <-rotateTicker.C:
			if s.Session.IsPaused() && s.dialogProgressBG != nil {
				s.dialogProgressBG.Close()
				s.dialogProgressBG = nil
				continue
			}

			torrentsVector := s.Session.GetTorrents()
			torrentsVectorSize := int(torrentsVector.Size())
			totalProgress := 0
			activeTorrents := make([]*activeTorrent, 0)

			for i := 0; i < torrentsVectorSize; i++ {
				torrentHandle := torrentsVector.Get(i)
				if torrentHandle.IsValid() == false {
					continue
				}

				torrentStatus := torrentHandle.Status(uint(libtorrent.TorrentHandleQueryName))
				if torrentStatus.GetHasMetadata() == false || torrentStatus.GetPaused() || s.Session.IsPaused() {
					continue
				}

				torrentName := torrentStatus.GetName()
				progress := int(float64(torrentStatus.GetProgress()) * 100)

				if progress < 100 {
					activeTorrents = append(activeTorrents, &activeTorrent{
						torrentName: torrentName,
						progress:    progress,
					})
					totalProgress += progress
				}
			}

			activeDownloads := len(activeTorrents)
			if activeDownloads > 0 {
				showProgress := totalProgress / activeDownloads
				showTorrent := "Total"
				if showNext >= activeDownloads {
					showNext = 0
				} else {
					showProgress = activeTorrents[showNext].progress
					showTorrent = activeTorrents[showNext].torrentName
					if len(showTorrent) > 32 {
						showTorrent = showTorrent[:32]
					}
					showNext += 1
				}
				if s.dialogProgressBG == nil {
					s.dialogProgressBG = xbmc.NewDialogProgressBG("Quasar", "")
				}
				s.dialogProgressBG.Update(showProgress, fmt.Sprintf("Quasar - %s", showTorrent))
			} else if s.dialogProgressBG != nil {
				s.dialogProgressBG.Close()
				s.dialogProgressBG = nil
			}
		}
	}
}