Пример #1
0
        /// <summary>
        /// This method pauses the download denoted by gid.
        /// This method behaves just like aria2.pause()
        /// except that this method pauses downloads without performing any actions which take time,
        /// such as contacting BitTorrent trackers to unregister the download first.
        /// </summary>
        /// <param name="gid"></param>
        /// <returns></returns>
        public static async Task <AriaPause> ForcePauseAsync(string gid)
        {
            List <object> ariaParams = new List <object>
            {
                "token:" + TOKEN,
                gid
            };
            AriaSendData ariaSend = new AriaSendData
            {
                Id      = Guid.NewGuid().ToString("N"),
                Jsonrpc = JSONRPC,
                Method  = "aria2.forcePause",
                Params  = ariaParams
            };

            return(await GetRpcResponseAsync <AriaPause>(ariaSend));
        }
Пример #2
0
        /// <summary>
        /// This method shuts down aria2.
        /// This method returns OK.
        /// </summary>
        /// <returns></returns>
        public static async Task <AriaShutdown> ShutdownAsync()
        {
            List <object> ariaParams = new List <object>
            {
                "token:" + TOKEN
            };
            AriaSendData ariaSend = new AriaSendData
            {
                Id      = Guid.NewGuid().ToString("N"),
                Jsonrpc = JSONRPC,
                Method  = "aria2.shutdown",
                Params  = ariaParams
            };
            var re = await GetRpcResponseAsync <AriaShutdown>(ariaSend);

            return(re);
        }
Пример #3
0
        /// <summary>
        /// This method returns the global options.
        /// The response is a struct.
        /// Its keys are the names of options.
        /// Values are strings.
        /// Note that this method does not return options which have no default value and have not been set on the command-line,
        /// in configuration files or RPC methods.
        /// Because global options are used as a template for the options of newly added downloads,
        /// the response contains keys returned by the aria2.getOption() method.
        /// </summary>
        /// <returns></returns>
        public static async Task <AriaGetOption> GetGlobalOptionAsync()
        {
            List <object> ariaParams = new List <object>
            {
                "token:" + TOKEN
            };

            AriaSendData ariaSend = new AriaSendData
            {
                Id      = Guid.NewGuid().ToString("N"),
                Jsonrpc = JSONRPC,
                Method  = "aria2.getGlobalOption",
                Params  = ariaParams
            };

            return(await GetRpcResponseAsync <AriaGetOption>(ariaSend));
        }
Пример #4
0
        /// <summary>
        /// This method returns a list of stopped downloads.
        /// offset is an integer and specifies the offset from the least recently stopped download.
        /// num is an integer and specifies the max.
        /// number of downloads to be returned.
        /// For the keys parameter, please refer to the aria2.tellStatus() method.
        /// <br/><br/>
        /// offset and num have the same semantics as described in the aria2.tellWaiting() method.
        /// <br/><br/>
        /// The response is an array of the same structs as returned by the aria2.tellStatus() method.
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public static async Task <AriaTellStatusList> TellStoppedAsync(int offset, int num)
        {
            List <object> ariaParams = new List <object>
            {
                "token:" + TOKEN,
                offset,
                num
            };
            AriaSendData ariaSend = new AriaSendData
            {
                Id      = Guid.NewGuid().ToString("N"),
                Jsonrpc = JSONRPC,
                Method  = "aria2.tellStopped",
                Params  = ariaParams
            };

            return(await GetRpcResponseAsync <AriaTellStatusList>(ariaSend));
        }
Пример #5
0
        /// <summary>
        /// 发送http请求,并将返回的json反序列化
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ariaSend"></param>
        /// <returns></returns>
        private async static Task <T> GetRpcResponseAsync <T>(AriaSendData ariaSend)
        {
            // 去掉null
            var jsonSetting = new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            };
            // 转换为json字符串
            string sendJson = JsonConvert.SerializeObject(ariaSend, Formatting.Indented, jsonSetting);
            // 向服务器请求数据
            string result = string.Empty;
            await Task.Run(() =>
            {
                result = Request(GetRpcUri(), sendJson);
            });

            if (result == null)
            {
                return(default);
Пример #6
0
        /// <summary>
        /// This method changes options of the download denoted by gid (string) dynamically.
        /// options is a struct.
        /// The options listed in Input File subsection are available, except for following options:
        /// <br/>
        /// dry-run metalink-base-uri parameterized-uri pause piece-length rpc-save-upload-metadata
        /// <br/>
        /// Except for the following options,
        /// changing the other options of active download makes it restart
        /// (restart itself is managed by aria2, and no user intervention is required):
        /// <br/>
        /// bt-max-peers bt-request-peer-speed-limit bt-remove-unselected-file force-save max-download-limit max-upload-limit
        /// <br/>
        /// This method returns OK for success.
        /// </summary>
        /// <param name="gid"></param>
        /// <param name="option"></param>
        /// <returns></returns>
        public static async Task <AriaChangeOption> ChangeOptionAsync(string gid, object option)
        {
            List <object> ariaParams = new List <object>
            {
                "token:" + TOKEN,
                gid,
                option
            };

            AriaSendData ariaSend = new AriaSendData
            {
                Id      = Guid.NewGuid().ToString("N"),
                Jsonrpc = JSONRPC,
                Method  = "aria2.changeOption",
                Params  = ariaParams
            };

            return(await GetRpcResponseAsync <AriaChangeOption>(ariaSend));
        }
Пример #7
0
        /// <summary>
        /// This method adds a new download.
        /// uris is an array of HTTP/FTP/SFTP/BitTorrent URIs (strings) pointing to the same resource.
        /// If you mix URIs pointing to different resources,
        /// then the download may fail or be corrupted without aria2 complaining.
        /// When adding BitTorrent Magnet URIs,
        /// uris must have only one element and it should be BitTorrent Magnet URI.
        /// options is a struct and its members are pairs of option name and value.
        /// See Options below for more details.
        /// If position is given, it must be an integer starting from 0.
        /// The new download will be inserted at position in the waiting queue.
        /// If position is omitted or position is larger than the current size of the queue,
        /// the new download is appended to the end of the queue.
        /// This method returns the GID of the newly registered download.
        /// </summary>
        /// <param name="uris"></param>
        /// <param name="dir"></param>
        /// <param name="outFile"></param>
        /// <returns></returns>
        public static async Task <AriaAddUri> AddUriAsync(List <string> uris, AriaSendOption option, int position = -1)
        {
            List <object> ariaParams = new List <object>
            {
                "token:" + TOKEN,
                uris,
                option
            };

            if (position > -1)
            {
                ariaParams.Add(position);
            }

            AriaSendData ariaSend = new AriaSendData
            {
                Id      = Guid.NewGuid().ToString("N"),
                Jsonrpc = JSONRPC,
                Method  = "aria2.addUri",
                Params  = ariaParams
            };

            return(await GetRpcResponseAsync <AriaAddUri>(ariaSend));
        }