private List<Torrent> GetTorrents(bool forceUpdate)
{
HttpWebRequest getTorrent = (HttpWebRequest)(HttpWebRequest.Create(host + "?list=1&token=" + token));
getTorrent.Credentials = credentials;
getTorrent.Headers.Add("Cookie", cookie);
HttpWebResponse response = (HttpWebResponse)getTorrent.GetResponse();
StreamReader sr = new StreamReader(response.GetResponseStream());
string torrentsResponse = sr.ReadToEnd();
response.Close();
JsonObject res = (JsonObject)JsonConvert.Import(torrentsResponse);
JsonArray torrents = (JsonArray)res["torrents"];
List<Torrent> returnTorrents = new List<Torrent>();
if (forceUpdate)
torrentCollection = new List<Torrent>();
foreach (JsonArray torrent in torrents)
{
string hash = (string)torrent[0];
string name = (string)torrent[2];
string label = (string)torrent[11];
int percentage = (int)torrent[4];
returnTorrents.Add(new Torrent { Hash = hash, Name = name, Label = label, PercentageDone = percentage });
if(forceUpdate)
torrentCollection.Add(new Torrent { Hash = hash, Name = name, Label = label, PercentageDone = percentage });
}
return returnTorrents;
}