コード例 #1
0
ファイル: Aria2Proxy.cs プロジェクト: luisriverag/Sonarr
        public Aria2Status[] GetTorrents(Aria2Settings settings)
        {
            _logger.Debug("> aria2.tellActive");

            var client = BuildClient(settings);

            var actives = ExecuteRequest(() => client.GetActives(GetToken(settings)));

            _logger.Debug("< aria2.tellActive");

            _logger.Debug("> aria2.tellWaiting");

            var waitings = ExecuteRequest(() => client.GetWaitings(GetToken(settings), 1, 10 * 1024));

            _logger.Debug("< aria2.tellWaiting");

            _logger.Debug("> aria2.tellStopped");

            var stoppeds = ExecuteRequest(() => client.GetStoppeds(GetToken(settings), 1, 10 * 1024));

            _logger.Debug("< aria2.tellStopped");

            var ret = new List <Aria2Status>();

            ret.AddRange(actives);
            ret.AddRange(waitings);
            ret.AddRange(stoppeds);

            return(ret.ToArray());
        }
コード例 #2
0
        public List <Aria2Status> GetTorrents(Aria2Settings settings)
        {
            _logger.Trace("> aria2.tellActive");

            var client = BuildClient(settings);

            var active = ExecuteRequest(() => client.GetActive(GetToken(settings)));

            _logger.Trace("< aria2.tellActive");

            _logger.Trace("> aria2.tellWaiting");

            var waiting = ExecuteRequest(() => client.GetWaiting(GetToken(settings), 0, 10 * 1024));

            _logger.Trace("< aria2.tellWaiting");

            _logger.Trace("> aria2.tellStopped");

            var stopped = ExecuteRequest(() => client.GetStopped(GetToken(settings), 0, 10 * 1024));

            _logger.Trace("< aria2.tellStopped");

            var items = new List <Aria2Status>();

            items.AddRange(active);
            items.AddRange(waiting);
            items.AddRange(stopped);

            return(items);
        }
コード例 #3
0
        public bool RemoveCompletedTorrent(Aria2Settings settings, string gid)
        {
            var response = ExecuteRequest(settings, "aria2.removeDownloadResult", GetToken(settings), gid);

            var result = response.GetStringResponse();

            return(result == "OK");
        }
コード例 #4
0
        public bool RemoveTorrent(Aria2Settings settings, string gid)
        {
            var response = ExecuteRequest(settings, "aria2.forceRemove", GetToken(settings), gid);

            var gidres = response.GetStringResponse();

            return(gid == gidres);
        }
コード例 #5
0
        public string AddTorrent(Aria2Settings settings, byte[] torrent)
        {
            var response = ExecuteRequest(settings, "aria2.addTorrent", GetToken(settings), torrent);

            var gid = response.GetStringResponse();

            return(gid);
        }
コード例 #6
0
ファイル: Aria2Proxy.cs プロジェクト: bakerboy448/Prowlarr
        private IAria2 BuildClient(Aria2Settings settings)
        {
            var client = XmlRpcProxyGen.Create <IAria2>();

            client.Url = GetURL(settings);

            return(client);
        }
コード例 #7
0
        public Aria2Status GetFromGID(Aria2Settings settings, string gid)
        {
            var response = ExecuteRequest(settings, "aria2.tellStatus", GetToken(settings), gid);

            var element = response.XPathSelectElement("./methodResponse/params/param/value");

            return(new Aria2Status(element));
        }
コード例 #8
0
        public string GetVersion(Aria2Settings settings)
        {
            var response = ExecuteRequest(settings, "aria2.getVersion", GetToken(settings));

            var element = response.XPathSelectElement("./methodResponse/params/param/value");

            var version = new Aria2Version(element);

            return(version.Version);
        }
コード例 #9
0
        public Dictionary <string, string> GetGlobals(Aria2Settings settings)
        {
            var response = ExecuteRequest(settings, "aria2.getGlobalOption", GetToken(settings));

            var element = response.XPathSelectElement("./methodResponse/params/param/value");

            var result = new Aria2Dict(element);

            return(result.Dict);
        }
コード例 #10
0
        public string AddMagnet(Aria2Settings settings, string magnet)
        {
            var response = ExecuteRequest(settings, "aria2.addUri", GetToken(settings), new List <string> {
                magnet
            });

            var gid = response.GetStringResponse();

            return(gid);
        }
コード例 #11
0
ファイル: Aria2Proxy.cs プロジェクト: luisriverag/Sonarr
        public bool RemoveTorrent(Aria2Settings settings, string gid)
        {
            _logger.Debug("> aria2.forceRemove");

            var client = BuildClient(settings);
            var gidres = ExecuteRequest(() => client.Remove(GetToken(settings), gid));

            _logger.Debug("< aria2.forceRemove");

            return(gid == gidres);
        }
コード例 #12
0
ファイル: Aria2Proxy.cs プロジェクト: bakerboy448/Prowlarr
        public string AddUri(Aria2Settings settings, string magnet)
        {
            _logger.Debug("> aria2.addUri");

            var client = BuildClient(settings);
            var gid    = ExecuteRequest(() => client.AddUri(GetToken(settings), new[] { magnet }));

            _logger.Debug("< aria2.addUri");

            return(gid);
        }
コード例 #13
0
        public bool RemoveCompletedTorrent(Aria2Settings settings, string gid)
        {
            _logger.Trace("> aria2.removeDownloadResult");

            var client = BuildClient(settings);
            var result = ExecuteRequest(() => client.RemoveResult(GetToken(settings), gid));

            _logger.Trace("< aria2.removeDownloadResult");

            return(result == "OK");
        }
コード例 #14
0
ファイル: Aria2Proxy.cs プロジェクト: bakerboy448/Prowlarr
        public string GetVersion(Aria2Settings settings)
        {
            _logger.Debug("> aria2.getVersion");

            var client  = BuildClient(settings);
            var version = ExecuteRequest(() => client.GetVersion(GetToken(settings)));

            _logger.Debug("< aria2.getVersion");

            return(version.Version);
        }
コード例 #15
0
ファイル: Aria2Proxy.cs プロジェクト: bakerboy448/Prowlarr
        public Aria2Status GetFromGID(Aria2Settings settings, string gid)
        {
            _logger.Debug("> aria2.tellStatus");

            var client = BuildClient(settings);
            var found  = ExecuteRequest(() => client.GetFromGid(GetToken(settings), gid));

            _logger.Debug("< aria2.tellStatus");

            return(found);
        }
コード例 #16
0
ファイル: Aria2Proxy.cs プロジェクト: bakerboy448/Prowlarr
        public string AddTorrent(Aria2Settings settings, byte[] torrent)
        {
            _logger.Debug("> aria2.addTorrent");

            var client = BuildClient(settings);
            var gid    = ExecuteRequest(() => client.AddTorrent(GetToken(settings), torrent));

            _logger.Debug("< aria2.addTorrent");

            return(gid);
        }
コード例 #17
0
        public List <Aria2Status> GetTorrents(Aria2Settings settings)
        {
            var active = GetTorrentsMethod(settings, "aria2.tellActive");

            var waiting = GetTorrentsMethod(settings, "aria2.tellWaiting", 0, 10 * 1024);

            var stopped = GetTorrentsMethod(settings, "aria2.tellStopped", 0, 10 * 1024);

            var items = new List <Aria2Status>();

            items.AddRange(active);
            items.AddRange(waiting);
            items.AddRange(stopped);

            return(items);
        }
コード例 #18
0
ファイル: Aria2Proxy.cs プロジェクト: luisriverag/Sonarr
        public Dictionary <string, string> GetGlobals(Aria2Settings settings)
        {
            _logger.Debug("> aria2.getGlobalOption");

            var client  = BuildClient(settings);
            var options = ExecuteRequest(() => client.GetGlobalOption(GetToken(settings)));

            _logger.Debug("< aria2.getGlobalOption");

            var ret = new Dictionary <string, string>();

            foreach (DictionaryEntry option in options)
            {
                ret.Add(option.Key.ToString(), option.Value?.ToString());
            }

            return(ret);
        }
コード例 #19
0
        private List <Aria2Status> GetTorrentsMethod(Aria2Settings settings, string method, params object[] args)
        {
            var allArgs = new List <object> {
                GetToken(settings)
            };

            if (args.Any())
            {
                allArgs.AddRange(args);
            }

            var response = ExecuteRequest(settings, method, allArgs.ToArray());

            var element = response.XPathSelectElement("./methodResponse/params/param/value/array/data");

            var torrents = element?.Elements()
                           .Select(x => new Aria2Status(x))
                           .ToList()
                           ?? new List <Aria2Status>();

            return(torrents);
        }
コード例 #20
0
        private XDocument ExecuteRequest(Aria2Settings settings, string methodName, params object[] args)
        {
            var requestBuilder = new XmlRpcRequestBuilder(settings.UseSsl, settings.Host, settings.Port, settings.RpcPath)
            {
                LogResponseContent = true,
            };

            var request = requestBuilder.Call(methodName, args).Build();

            var response = _httpClient.Execute(request);

            var doc = XDocument.Parse(response.Content);

            var faultElement = doc.XPathSelectElement("./methodResponse/fault");

            if (faultElement != null)
            {
                var fault = new Aria2Fault(faultElement);

                throw new DownloadClientException($"Aria2 returned error code {fault.FaultCode}: {fault.FaultString}");
            }

            return(doc);
        }
コード例 #21
0
ファイル: Aria2Proxy.cs プロジェクト: bakerboy448/Prowlarr
 private string GetURL(Aria2Settings settings)
 {
     return($"http{(settings.UseSsl ? "s" : "")}://{settings.Host}:{settings.Port}{settings.RpcPath}");
 }
コード例 #22
0
ファイル: Aria2Proxy.cs プロジェクト: bakerboy448/Prowlarr
 private string GetToken(Aria2Settings settings)
 {
     return($"token:{settings?.SecretToken}");
 }