static public TorrentLabel Ask() { TorrentLabel selected = new TorrentLabel(); GUIDialogMenu dlgMenu = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlgMenu == null) { return(null); } dlgMenu.Reset(); dlgMenu.SetHeading("Under which label?"); foreach (TorrentLabel label in TorrentEngine.Instance().TorrentSession.Labels) { GUIListItem listItem = new GUIListItem(); listItem.Label = label.Name == "" ? "No label" : label.Name; listItem.AlbumInfoTag = label; dlgMenu.Add(listItem); } dlgMenu.DoModal(GUIWindowManager.ActiveWindow); if (dlgMenu.SelectedLabel == -1) { return(null); } selected.Name = dlgMenu.SelectedLabelText; return(selected); }
public void RSSDownload(RSSItem item) { GUIDialogYesNo dlg = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO); dlg.SetHeading("Download this torrent?"); dlg.SetLine(1, item.Title); dlg.DoModal(GUIWindowManager.ActiveWindow); if (!dlg.IsConfirmed) { return; } TorrentLabel label = DialogAskLabel.Ask(); if (label != null) { bool ok = TorrentEngine.Instance().StartDownloading(item.Link, label.Name, true, "", "0", "", ""); if (!ok) { GUIDialogNotify notify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); notify.Reset(); notify.SetHeading("Failed!"); notify.SetText("Unable to start download."); notify.DoModal(GUIWindowManager.ActiveWindow); } } }
public void FolderClickMenu(GUIListItem fldr, GUIListItem _selectedtorrent, TorrentLabel label) { GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlg == null) { return; } dlg.Reset(); dlg.SetHeading("Folder Options"); dlg.Add("Set as download location"); //dlg.Add("Add to favourite places"); dlg.DoModal(GUIWindowManager.ActiveWindow); switch (dlg.SelectedLabelText) { case "Set as download location": { MyTorrents.Instance().HideFolderBrowser(); if (MyTorrents.ListType == "SeriesInfo") { SeriesItem item = _selectedtorrent.AlbumInfoTag as SeriesItem; MyTorrents.Instance()._torrentWatchlist.GetSeriesList().Where(e => e.show.ID == item.show.ID).First().folder = fldr.Path + @"\" + fldr.Label; GUIPropertyManager.SetProperty("#MyTorrents.SeriesInfo.Folder", fldr.Path + @"\" + fldr.Label); } else { DefaultDir = TorrentEngine.Instance().TorrentSession.GetSettings("dir_active_download"); string response = TorrentEngine.Instance().TorrentSession.GetResponse(string.Format("?action=setsetting&s=dir_active_download&v={0}", fldr.Path + @"\" + fldr.Label)); string response2 = TorrentEngine.Instance().TorrentSession.GetResponse("?action=setsetting&s=dir_active_download_flag&v=1"); TorrentSearch.TorrentMatch match = _selectedtorrent.AlbumInfoTag as TorrentSearch.TorrentMatch; bool ok = TorrentEngine.Instance().StartDownloading(match.Url, label.Name, true, match.cookie, match.Id, _downloadoption, ""); if (!ok) { GUIDialogNotify notify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); notify.Reset(); notify.SetHeading("Failed!"); notify.SetText("Unable to start download."); notify.DoModal(GUIWindowManager.ActiveWindow); } string revert = TorrentEngine.Instance().TorrentSession.GetResponse(string.Format("?action=setsetting&s=dir_active_download&v={0}", DefaultDir)); } break; } } }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { var obj = new TorrentLabel() { Text = reader.ReadAsString(), Count = reader.ReadAsInt32().GetValueOrDefault() }; if (!reader.IsEndOfArray()) { throw new JsonReaderException(); } return(obj); }
public TorrentList TorrentsByLabel(TorrentLabel _selectedLabel) { TorrentList list = new TorrentList(); foreach (Sohvaperuna.TorrentEngine.Torrent torrent in _torrentsAll) { if (_selectedLabel.Name.CompareTo(torrent.Label) == 0) { //label match! list.Add(torrent); } } return(list); }
public bool UpdateData() { lock (lockUpdate) { string response = GetResponse("web.update_ui", DelugeAPI.UpdateParams); if (response == null || response.Length == 0) { return(false); } TorrentLabelList lbls = new TorrentLabelList(); UpdateResponse update = js.Deserialize <UpdateResponse>(response); foreach (object[] lbl in update.filters.label) { TorrentLabel label = new TorrentLabel(); label.Name = (string)lbl[0]; label.Count = (int)lbl[1]; lbls.Add(label); } _labels = lbls; TorrentList oldTorrentsAll = _torrentsAll; TorrentList newTorrentsAll = new TorrentList(); foreach (KeyValuePair <string, DelugeTorrent> pair in update.torrents) { DelugeTorrent tor = pair.Value; Torrent torrent = new Torrent(this); try { torrent.Hash = pair.Key; torrent.Status = 0;// get Status code torrent.Name = tor.name; torrent.Size = tor.total_size; torrent.Progress = tor.progress; torrent.Downloaded = tor.total_done; torrent.Uploaded = tor.total_uploaded; torrent.Ratio = (long)Math.Round(tor.ratio); torrent.UploadSpeed = (long)Math.Round(tor.upload_payload_rate); torrent.DownloadSpeed = (long)Math.Round(tor.download_payload_rate); torrent.ETA = (int)Math.Round(tor.eta); torrent.Label = tor.label; torrent.PeersConnected = tor.num_peers; torrent.PeersInSwarm = tor.total_peers; torrent.SeedsConnected = tor.num_seeds; torrent.SeedsInSwarm = tor.total_seeds; torrent.Availability = (int)Math.Round(tor.distributed_copies); torrent.TorrentQueueOrder = (int)Math.Round(tor.queue); torrent.Remaining = tor.total_size - tor.total_done; torrent.DownloadURL = ""; torrent.RSSFeedURL = ""; torrent.StatusMessage = tor.state; torrent.StreamID = ""; torrent.AddedOn = (int)Math.Round(tor.time_added); torrent.CompletedOn = 0; torrent.AppUpdateURL = ""; torrent.TorrentSavePath = tor.save_path; } catch { } newTorrentsAll.Add(torrent); } TorrentList newTorrentsActive = new TorrentList(); foreach (Torrent torrent in newTorrentsAll) { if (torrent.HasStatus((int)Torrent.UTorrentStatus.Started)) { newTorrentsActive.Add(torrent); } if (oldTorrentsAll != null) { Torrent oldTorrent = oldTorrentsAll.TorrentByHash(torrent.Hash); if (oldTorrent == null) { //this is new torrent! Send event! TimeSpan t = (DateTime.UtcNow - new DateTime(1970, 1, 1)); int now = (int)t.TotalSeconds; if (TorrentAdded != null && ((now - torrent.AddedOn) < Math.Max(60, Convert.ToInt32(_outtimer) * 2))) { TorrentAdded(torrent); } } else { if (torrent.Progress == 100 && oldTorrent.Progress < 100) { TorrentCompleted(torrent); } oldTorrentsAll.Remove(oldTorrent); } } } if (oldTorrentsAll != null && newTorrentsAll != null && oldTorrentsAll.Count != 0) { if (newTorrentsAll.Count / oldTorrentsAll.Count > 0.95) { foreach (Torrent torrent in oldTorrentsAll) { //there are all removed torrents, send events! if (TorrentRemoved != null) { TorrentRemoved(torrent); } } } } //create no label label! TorrentLabel nolabel = new TorrentLabel(); nolabel.Name = ""; foreach (Torrent torrent in newTorrentsAll) { if (torrent.Label == "") { torrent.Label = nolabel.Name; nolabel.Count = nolabel.Count + 1; } } if (!_labels.Exists(e => e.Name == "")) { _labels.Insert(0, nolabel); } if (_torrentsAll == null) { _torrentsAll = new TorrentList(); } _torrentsAll.Clear(); foreach (Torrent torrent in newTorrentsAll) { _torrentsAll.Add(torrent); } } return(true); }
public void SearchItemClicked(TorrentMatch match) { GUIDialogYesNo dlg = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO); dlg.SetHeading("Download this torrent?"); dlg.SetLine(1, match.Title); dlg.SetLine(2, UnitConvert.SizeToString(match.Size)); //dlg.SetLine(3, item.Label3); dlg.DoModal(GUIWindowManager.ActiveWindow); if (!dlg.IsConfirmed) { return; } label = DialogAskLabel.Ask(); if (label == null) { return; } Log.Instance().Print("label is " + label.Name); List <DownloadDir> predefined = TorrentEngine.Instance().TorrentSession.ListDirs(); if (predefined == null) { //MyTorrents.Instance().DisplayError("Unable to connect", "Connection error. Please open your Torrent client before retrying."); //return; } GUIDialogMenu chooser = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (chooser == null) { return; } chooser.Reset(); chooser.SetHeading("Download options"); chooser.Add("No change"); //foreach (DownloadDir dir in predefined) //{ // GUIListItem element = new GUIListItem(); // element.Label = dir.path; // element.Label2 = String.Format("{0} MB Free", Convert.ToString(dir.available)); // chooser.Add(element); //} chooser.Add("Browse Folders"); chooser.DoModal(GUIWindowManager.ActiveWindow); if (chooser.SelectedId == -1) { return; } int selecteddirId = chooser.SelectedId; string selectedText = chooser.SelectedLabelText; Log.Instance().Print("download option is " + selectedText); bool ok = false; // KAT hack string dowOption = ""; if (_searchEngine.GetType() == typeof(TorrentSearch_Combiner)) { Log.Instance().Print("Selected engine is Combiner"); TorrentSearch_Combiner _eng = (TorrentSearch_Combiner)_searchEngine; if (_searchEngine.Parameters.ContainsKey("Options")) { dowOption = _eng.Engines.Where(e => e.Name == match.tracker).First().Parameters["Options"].ToString().Replace("%id%", match.Id); } } else { if (_searchEngine.Parameters.ContainsKey("Options")) { dowOption = _searchEngine.Parameters["Options"].ToString().Replace("%id%", match.Id); } } switch (selectedText) { case "Browse Folders": //FolderBrowser ViewFolders = new FolderBrowser(TorrentEngine.Instance().TorrentSession, label, match, dowOption); Log.Instance().Print("Loading file browser"); MyTorrents.ListType = "FolderBrowser"; MyTorrents.Instance().ShowFolderBrowser(); break; case "No change": if (label != null) { Log.Instance().Print("Starting torrent file downloading"); ok = TorrentEngine.Instance().StartDownloading(match.Url, label.Name, true, match.cookie, match.Id, dowOption, ""); } break; default: if (label != null) { Log.Instance().Print("Starting torrent file downloading"); ok = TorrentEngine.Instance().StartDownloading(match.Url, label.Name, true, match.cookie, match.Id, dowOption, String.Format("&download_dir={0}", selecteddirId - 2)); } break; } /* * if (!ok) * { * GUIDialogNotify notify = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); * notify.Reset(); * notify.SetHeading("Failed!"); * notify.SetText("Unable to start download."); * notify.DoModal(GUIWindowManager.ActiveWindow); * * Log.Instance().Print("Downloading failed"); * } * */ }
public void ContextMenu(object info) { WatchItem watch = info as WatchItem; GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU); if (dlg == null) { return; } dlg.Reset(); dlg.SetHeading("Torrent watchlist"); dlg.Add("Add Series"); dlg.Add("Search Series"); dlg.Add("Add Movie"); dlg.Add("Add custom"); dlg.Add("Manual Search"); dlg.Add("Remove selected"); dlg.Add("Clear list"); dlg.Add("Force RSS update"); dlg.DoModal(GUIWindowManager.ActiveWindow); switch (dlg.SelectedLabelText) { case "Add Series": { AddSeries(); MyTorrents.Instance().ShowTorrentWatch(); break; } case "Search Series": { SearchSeries(); } break; case "Add Movie": break; case "Manual Search": MyTorrents.Instance()._torrentWatchlist.SearchTorrent(); break; case "Add custom": { VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_VIRTUAL_KEYBOARD); keyboard.Reset(); keyboard.Text = ""; keyboard.DoModal(GUIWindowManager.ActiveWindow); if (!keyboard.IsConfirmed) { return; } watch = new WatchItem(); watch.SearchTerm = keyboard.Text; TorrentLabel label = DialogAskLabel.Ask(); if (label != null) { watch.Label = label.Name; MyTorrents.Instance()._torrentWatchlist.AddWatch(watch); Log.Instance().Print(String.Format("Watch [{0}] added.", watch.SearchTerm)); } break; } case "Clear list": { MyTorrents.Instance()._torrentWatchlist.Clear(); break; } case "Remove selected": { MyTorrents.Instance()._torrentWatchlist.RemoveWatch(watch); // torrentList.RemoveItem(torrentList.SelectedListItemIndex); break; } case "Force RSS update": { RSSChannelManager.Instance().UpdateChannels(true); break; } } MyTorrents.Instance().ShowTorrentWatch(); }
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); }