private TimeSpan?GetRemainingTime(DeemixQueueItem x, long size) { if (x.Progress == 100) { _startTimeCache.Remove(x.Id); return(null); } if (x.Progress == 0) { return(null); } var started = _startTimeCache.Find(x.Id); if (started == null) { started = DateTime.UtcNow; _startTimeCache.Set(x.Id, started); return(null); } var elapsed = DateTime.UtcNow - started; var progress = Math.Min(x.Progress, 100) / 100.0; _bytesPerSecond = (progress * size) / elapsed.Value.TotalSeconds; return(TimeSpan.FromTicks((long)(elapsed.Value.Ticks * (1 - progress) / progress))); }
private DownloadClientItem ToDownloadClientItem(DeemixQueueItem x) { var title = $"{x.Artist} - {x.Title} [WEB] {Formats[x.Bitrate]}"; if (x.Explicit) { title += " [Explicit]"; } // assume 3 mins per track, bitrates in kbps var size = x.Size * 180L * Bitrates[x.Bitrate] * 128L; var item = new DownloadClientItem { DownloadId = x.Uuid, Title = title, TotalSize = size, RemainingSize = (long)((1 - (x.Progress / 100.0)) * size), RemainingTime = GetRemainingTime(x, size), Status = GetItemStatus(x), CanMoveFiles = true, CanBeRemoved = true }; if (x.ExtrasPath.IsNotNullOrWhiteSpace()) { item.OutputPath = new OsPath(x.ExtrasPath); } return(item); }
private static DownloadItemStatus GetItemStatus(DeemixQueueItem item) { if (item.Failed > 0) { return(DownloadItemStatus.Failed); } if (item.Status == "inQueue") { return(DownloadItemStatus.Queued); } if (item.Status == "completed") { return(DownloadItemStatus.Completed); } if (item.Progress is > 0 and < 100) { return(DownloadItemStatus.Downloading); } return(DownloadItemStatus.Queued); }