Пример #1
0
        private static List <TorrentEntry> GetqBitTorrentDownloads()
        {
            List <TorrentEntry> ret = new List <TorrentEntry>();

            // get list of files being downloaded by qBitTorrentFinder
            string host = TVSettings.Instance.qBitTorrentHost;
            string port = TVSettings.Instance.qBitTorrentPort;

            if (string.IsNullOrEmpty(host) || string.IsNullOrEmpty(port))
            {
                return(ret);
            }

            string url = $"http://{host}:{port}/query/";

            try
            {
                JToken settings         = JsonHelper.ObtainToken(url + "preferences");
                JArray currentDownloads = JsonHelper.ObtainArray(url + "torrents?filter=all");

                foreach (JToken torrent in currentDownloads.Children())
                {
                    JArray stuff2 = JsonHelper.ObtainArray(url + "propertiesFiles/" + torrent["hash"]);

                    foreach (JToken file in stuff2.Children())
                    {
                        ret.Add(new TorrentEntry(torrent["name"].ToString(),
                                                 settings["save_path"] + file["name"].ToString(),
                                                 (int)(100 * file["progress"].ToObject <float>())));
                    }

                    if (!stuff2.Children().Any())
                    {
                        ret.Add(
                            new TorrentEntry(
                                torrent["name"].ToString()
                                , TVSettings.Instance.FilenameFriendly(settings["save_path"] + torrent["name"].ToString()) + TVSettings.Instance.VideoExtensionsArray[0]
                                , 0
                                )
                            );
                    }
                }
            }
            catch (WebException)
            {
                LOGGER.Warn($"Could not connect to {url}, Please check qBitTorrent Settings and ensure qBitTorrent is running with no password required for local connections");
            }

            return(ret);
        }