Example #1
0
        public List <DownloadClientItem> GetQueue(DeemixSettings settings)
        {
            var request  = BuildRequest(settings).Resource("/api/getQueue");
            var response = ProcessRequest <DeemixQueue>(request);

            var completed = response.Queue.Values.Where(x => x.Status == "completed");
            var queue     = response.Queue.Values.Where(x => x.Status == "inQueue").OrderBy(x => response.QueueOrder.IndexOf(x.Id));
            var current   = response.Current;

            var result = completed.Concat(new[] { current }).Concat(queue).Where(x => x != null).Select(ToDownloadClientItem).ToList();

            var currentItem = result.FirstOrDefault(x => x.Status == DownloadItemStatus.Downloading);

            if (currentItem != null && currentItem.RemainingTime.HasValue)
            {
                var remainingTime = currentItem.RemainingTime.Value;

                foreach (var item in result)
                {
                    if (item.Status == DownloadItemStatus.Queued)
                    {
                        remainingTime     += TimeSpan.FromSeconds(item.TotalSize / _bytesPerSecond);
                        item.RemainingTime = remainingTime;
                    }
                }
            }

            return(result);
        }
Example #2
0
        public DeemixConfig GetSettings(DeemixSettings settings)
        {
            var request  = BuildRequest(settings).Resource("/api/getSettings");
            var response = ProcessRequest <DeemixConfigResult>(request);

            return(response.Settings);
        }
Example #3
0
        public void Authenticate(DeemixSettings settings)
        {
            var requestBuilder = BuildRequest(settings);
            var baseUrl        = requestBuilder.BaseUrl.FullUri;

            Authenticate(baseUrl, settings.Arl);
        }
Example #4
0
 private HttpRequestBuilder BuildRequest(DeemixSettings settings)
 {
     return(new HttpRequestBuilder(settings.UseSsl, settings.Host, settings.Port, settings.UrlBase)
     {
         LogResponseContent = true
     });
 }
Example #5
0
        public string Download(string url, int bitrate, DeemixSettings settings)
        {
            Authenticate(settings);

            var request = BuildRequest(settings)
                          .Resource("/api/addToQueue")
                          .Post()
                          .AddFormParameter("url", url)
                          .AddFormParameter("bitrate", bitrate);

            var response = ProcessRequest <DeemixResult <DeemixAddResult> >(request);

            if (response.Result)
            {
                if (response.Data.Obj.Count != 1)
                {
                    throw new DownloadClientException("Expected Deemix to add 1 item, got {0}", response.Data.Obj.Count);
                }

                _logger.Trace("Downloading item {0}", response.Data.Obj[0].Uuid);
                return(response.Data.Obj[0].Uuid);
            }

            throw new DownloadClientException("Error adding item to Deemix: {0}", response.Errid);
        }
Example #6
0
        public void RemoveFromQueue(string downloadId, DeemixSettings settings)
        {
            var request = BuildRequest(settings)
                          .Resource("/api/removeFromQueue")
                          .Post()
                          .AddQueryParam("uuid", downloadId);

            ProcessRequest(request);
        }