コード例 #1
0
        public List <File> GetFiles(string torrentHash)
        {
            List <File> files = new List <File>();

            if (!torrentMapping.ContainsKey(torrentHash))
            {
                return(null);
            }
            Download dl = torrentMapping[torrentHash];

            Sohvaperuna.TorrentEngine.Torrent tor = toUtorrent(dl);
            File file = new File(this);

            file.Filename   = tor.Name;
            file.Filesize   = tor.Size;
            file.Downloaded = tor.Downloaded;
            file.Priority   = dl.Rank;

            files.Add(file);

            return(files);
        }
コード例 #2
0
        public bool UpdateData()
        {
            lock (lockUpdate)
            {
                prot.DownloadManager.Update();
                TorrentList __torrentsAll    = new TorrentList();
                TorrentList __torrentsActive = new TorrentList();
                Dictionary <string, global::AzureusEngine.AzCommunication.Download> _torrentMapping = new Dictionary <string, global::AzureusEngine.AzCommunication.Download>();
                Dictionary <string, int> categories = new Dictionary <string, int>();

                foreach (Download dl in prot.DownloadManager.Downloads)
                {
                    Sohvaperuna.TorrentEngine.Torrent tor = toUtorrent(dl);
                    if (!categories.ContainsKey(tor.Label))
                    {
                        categories.Add(tor.Label, 1);
                    }
                    else
                    {
                        categories[tor.Label] = categories[tor.Label] + 1;
                    }
                    __torrentsAll.Add(tor);
                    if (!torrentMapping.ContainsKey(tor.Hash))
                    {
                        torrentMapping.Add(tor.Hash, dl);
                        if (TorrentAdded != null)
                        {
                            TorrentAdded(tor);
                        }
                    }
                    if (tor.Status == 1)
                    {
                        __torrentsActive.Add(tor);
                    }
                }
                foreach (Sohvaperuna.TorrentEngine.Torrent tor in __torrentsAll)
                {
                    Sohvaperuna.TorrentEngine.Torrent _tor = _torrentsAll.TorrentByHash(tor.Hash);
                    if (tor != null)
                    {
                        _torrentsAll.Remove(tor);
                    }
                }


                _torrentsActive = __torrentsActive;
                _torrentsAll    = __torrentsAll;

                TorrentLabelList labels = new TorrentLabelList();
                //_labels.Clear();
                foreach (string s in categories.Keys)
                {
                    TorrentLabel lbl = new TorrentLabel();
                    lbl.Name  = s;
                    lbl.Count = categories[s];
                    labels.Add(lbl);
                }
                _labels = labels;

                /*
                 * string response = GetResponse("list=1");
                 * Regex re = new Regex("\\[\"(.*?)\",([0-9])+]");
                 * MatchCollection matches = re.Matches(response);
                 * _labels = new UTorrentLabelList();
                 * foreach (Match match in matches)
                 * {
                 *  UTorrentLabel label = new UTorrentLabel();
                 *  label.Name = match.Groups[1].Value.Replace(@"\\", @"\"); ;
                 *  label.Count = Convert.ToInt32( match.Groups[2].Value );
                 *  _labels.Add(label);
                 * }
                 *
                 * re = new Regex("\\[\"(.*?)\",([0-9-]+),\"(.*)\",([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),\"(.*)\",([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+),([0-9-]+)]");
                 * matches = re.Matches(response);
                 *
                 * UTorrentList oldTorrentsAll = _torrentsAll;
                 * UTorrentList newTorrentsAll = new UTorrentList();
                 * foreach (Match match in matches)
                 * {
                 *  UTorrent torrent = new UTorrent( this );
                 *  torrent.Hash = match.Groups[1].Value;
                 *  torrent.Status = Convert.ToInt32(match.Groups[2].Value);
                 *  torrent.Name = match.Groups[3].Value;
                 *  torrent.Size = Convert.ToInt64(match.Groups[4].Value);
                 *  torrent.Progress = Convert.ToInt32(match.Groups[5].Value) / 10.0;
                 *  torrent.Downloaded = Convert.ToInt64(match.Groups[6].Value);
                 *  torrent.Uploaded = Convert.ToInt64(match.Groups[7].Value);
                 *  torrent.Ratio = Convert.ToInt64(match.Groups[8].Value);
                 *  torrent.UploadSpeed = Convert.ToInt64(match.Groups[9].Value);
                 *  torrent.DownloadSpeed = Convert.ToInt64(match.Groups[10].Value);
                 *  torrent.ETA = Convert.ToInt32(match.Groups[11].Value);
                 *  torrent.Label = match.Groups[12].Value.Replace( @"\\", @"\" );
                 *  torrent.PeersConnected = Convert.ToInt32(match.Groups[13].Value);
                 *  torrent.PeersInSwarm = Convert.ToInt32(match.Groups[14].Value);
                 *  torrent.SeedsConnected = Convert.ToInt32(match.Groups[15].Value);
                 *  torrent.SeedsInSwarm = Convert.ToInt32(match.Groups[16].Value);
                 *  torrent.Availability = Convert.ToInt32(match.Groups[17].Value);
                 *  torrent.TorrentQueueOrder = Convert.ToInt32(match.Groups[18].Value);
                 *  torrent.Remaining = Convert.ToInt64(match.Groups[19].Value);
                 *
                 *  newTorrentsAll.Add(torrent);
                 * }
                 *
                 * UTorrentList newTorrentsActive = new UTorrentList();
                 *
                 * foreach (UTorrent torrent in newTorrentsAll)
                 * {
                 *  if (torrent.HasStatus((int)UTorrent.UTorrentStatus.Started))
                 *  {
                 *      newTorrentsActive.Add(torrent);
                 *  }
                 *
                 *  if (oldTorrentsAll != null)
                 *  {
                 *      UTorrent oldTorrent = oldTorrentsAll.TorrentByHash(torrent.Hash);
                 *      if (oldTorrent == null)
                 *      {
                 *          //this is new torrent! Send event!
                 *          if (TorrentAdded != null)
                 *          {
                 *              TorrentAdded(torrent);
                 *          }
                 *      }
                 *      else
                 *      {
                 *          oldTorrentsAll.Remove(oldTorrent);
                 *      }
                 *  }
                 * }
                 *
                 * if (oldTorrentsAll != null)
                 * {
                 *  foreach (UTorrent torrent in oldTorrentsAll)
                 *  {
                 *      //there are all removed torrents, send events!
                 *      if (TorrentRemoved != null)
                 *      {
                 *          TorrentRemoved(torrent);
                 *      }
                 *  }
                 * }
                 *
                 * //create no label label!
                 * UTorrentLabel nolabel = new UTorrentLabel();
                 * nolabel.Name = "";
                 *
                 * foreach (UTorrent torrent in newTorrentsAll)
                 * {
                 *  if (torrent.Label == "")
                 *  {
                 *      torrent.Label = nolabel.Name;
                 *      nolabel.Count = nolabel.Count + 1;
                 *  }
                 * }
                 *
                 * _labels.Insert(0, nolabel);
                 *
                 * if (_torrentsActive == null)
                 * {
                 *  _torrentsActive = new UTorrentList();
                 * }
                 * _torrentsActive.Clear();
                 * foreach (UTorrent torrent in newTorrentsActive)
                 * {
                 *  _torrentsActive.Add(torrent);
                 * }
                 * if (_torrentsAll == null)
                 * {
                 *  _torrentsAll = new UTorrentList();
                 * }
                 * _torrentsAll.Clear();
                 * foreach (UTorrent torrent in newTorrentsAll)
                 * {
                 *  _torrentsAll.Add(torrent);
                 * }*/
            }
            return(true);
        }
コード例 #3
0
        private Sohvaperuna.TorrentEngine.Torrent toUtorrent(Download download)
        {
            Sohvaperuna.TorrentEngine.Torrent tor = new Sohvaperuna.TorrentEngine.Torrent(this);
            tor.Availability  = (int)download.Stats.Availabilty;
            tor.Downloaded    = (long)download.Stats.Downloaded * (1024 * 1024);
            tor.DownloadSpeed = (long)download.Stats.DownloadAverage;
            if (download.Stats.ETA == "")
            {
                tor.ETA = 0;
            }
            else
            {
                if (download.State == DownloadState.ST_DOWNLOADING)
                {
                    string[] split   = download.Stats.ETA.Split(new char[] { ' ' });
                    int      days    = 0;
                    int      hours   = 0;
                    int      minutes = 0;
                    int      seconds = 0;
                    foreach (string s in split)
                    {
                        if (s.Contains("d"))
                        {
                            days = Convert.ToInt32(s.Replace("d", ""));
                        }
                        if (s.Contains("m"))
                        {
                            minutes = Convert.ToInt32(s.Replace("m", ""));
                        }
                        if (s.Contains("h"))
                        {
                            hours = Convert.ToInt32(s.Replace("h", ""));
                        }
                        if (s.Contains("s"))
                        {
                            seconds = Convert.ToInt32(s.Replace("s", ""));
                        }
                    }
                    TimeSpan ts = new TimeSpan(days, hours, minutes, seconds, 0);
                    //DateTime time = DateTime.Parse(download.Stats.ETA.Replace(" ",""));
                    tor.ETA = ts.Days * 24 * 3600 + 3600 * ts.Hours + ts.Minutes * 60 + ts.Seconds;
                }
                else
                {
                    tor.ETA = 0;
                }
            }

            /*Started = 1,
            *  Checking = 2,
            *  StartAfterCheck = 4,
            *  Checked = 8,
            *  Error = 16,
            *  Paused = 32,
            *  Queued = 64,
            *  Loaded = 128*/
            if (download.State == DownloadState.ST_DOWNLOADING || download.State == DownloadState.ST_SEEDING)
            {
                tor.Status = 1;
            }
            if (download.State == DownloadState.ST_PREPARING)
            {
                tor.Status = 2;
            }
            if (download.State == DownloadState.ST_QUEUED)
            {
                tor.Status = 64;
            }
            if (download.State == DownloadState.ST_READY)
            {
                tor.Status = 8;
            }
            if (download.State == DownloadState.ST_STOPPED || DownloadState.ST_STOPPING == download.State)
            {
                tor.Status = 32;
            }
            if (download.State == DownloadState.ST_ERROR)
            {
                tor.Status = 16;
            }
            tor.Hash           = download.Torrent.Hash;
            tor.Label          = download.Category;
            tor.Name           = download.Torrent.Name;
            tor.PeersConnected = download.Scrape_Result.Seeders + download.Scrape_Result.Leechers;
            //tor.PeersInSwarm //TODO: do something
            tor.Progress       = download.Stats.Completed;
            tor.Ratio          = (long)download.Stats.Share_Ratio * 100;
            tor.Remaining      = download.Remaining;
            tor.SeedsConnected = download.Scrape_Result.Seeders;
            tor.SeedsInSwarm   = 0; //TODO: do something
            tor.Size           = (long)download.Torrent.Size * (1024 * 1024);
            tor.Uploaded       = (long)download.Stats.Uploaded * (1024 * 1024);
            tor.UploadSpeed    = (long)download.Stats.UploadAverage;


            return(tor);
        }