public void AddTorrentFromUrl(string torrentUrl, string label, RTorrentPriority priority, string directory, RTorrentSettings settings) { _logger.Debug("Executing remote method: load.normal"); var client = BuildClient(settings); var response = ExecuteRequest(() => client.LoadStart("", torrentUrl, GetCommands(label, priority, directory))); if (response != 0) { throw new DownloadClientException("Could not add torrent: {0}.", torrentUrl); } }
public void SetTorrentPriority(string hash, RTorrentPriority priority, RTorrentSettings settings) { _logger.Debug("Executing remote method: d.priority.set"); var client = BuildClient(settings); var response = client.SetPriority(hash, (long)priority); if (response != 0) { throw new DownloadClientException("Could not set priority on torrent: {0}.", hash); } }
private string[] GetCommands(string label, RTorrentPriority priority, string directory) { var result = new List <string>(); if (label.IsNotNullOrWhiteSpace()) { result.Add("d.custom1.set=" + label); } if (priority != RTorrentPriority.Normal) { result.Add("d.priority.set=" + (int)priority); } if (directory.IsNotNullOrWhiteSpace()) { result.Add("d.directory.set=" + directory); } return(result.ToArray()); }
public void AddTorrentFromUrl(string torrentUrl, string label, RTorrentPriority priority, string directory, bool doNotStart, RTorrentConfig settings) { _logger.Debug("Adding Torrent From URL"); var client = BuildClient(settings); var response = -1; if (doNotStart) { _logger.Debug("Executing remote method load.normal"); response = client.Load("", torrentUrl, GetCommands(label, priority, directory)); } else { _logger.Debug("Executing remote method load.start"); response = client.LoadStart("", torrentUrl, GetCommands(label, priority, directory)); } if (response != 0) { throw new Exception("Could not add torrent:" + torrentUrl); } }
public void AddTorrentFromUrl(string torrentUrl, string label, RTorrentPriority priority, string directory, RTorrentSettings settings) { var args = new List <object> { "", torrentUrl }; args.AddRange(GetCommands(label, priority, directory)); XDocument response; if (settings.AddStopped) { response = ExecuteRequest(settings, "load.normal", args.ToArray()); } else { response = ExecuteRequest(settings, "load.start", args.ToArray()); } if (response.GetIntResponse() != 0) { throw new DownloadClientException("Could not add torrent: {0}.", torrentUrl); } }
public void SetDeferredMagnetProperties(string hash, string category, string directory, RTorrentPriority priority, RTorrentSettings settings) { var commands = new List <string>(); if (category.IsNotNullOrWhiteSpace()) { commands.Add("d.set_custom1=" + category); } if (directory.IsNotNullOrWhiteSpace()) { commands.Add("d.set_directory=" + directory); } if (priority != RTorrentPriority.Normal) { commands.Add("d.set_priority=" + (long)priority); } // Ensure it gets started if the user doesn't have schedule=...,start_tied= commands.Add("d.open="); commands.Add("d.start="); if (commands.Any()) { var key = "event.download.inserted_new"; var cmd_key = "sonarr_deferred_" + hash; commands.Add(string.Format("print=\"Applying deferred properties to {0}\"", hash)); // Remove event handler once triggered. commands.Add(string.Format("\"system.method.set_key={0},{1}\"", key, cmd_key)); var setKeyValue = string.Format("branch=\"equal=d.get_hash=,cat={0}\",{{{1}}}", hash, string.Join(",", commands)); _logger.Debug("Executing remote method: method.set_key = {0},{1},{2}", key, cmd_key, setKeyValue); var client = BuildClient(settings); var response = client.SetKey(key, cmd_key, setKeyValue); if (response != 0) { throw new DownloadClientException("Could set properties for torrent: {0}.", hash); } } }
public void AddTorrentFromFile(string fileName, byte[] fileContent, string label, RTorrentPriority priority, string directory, RTorrentSettings settings) { var client = BuildClient(settings); var response = ExecuteRequest(() => { if (settings.AddStopped) { _logger.Debug("Executing remote method: load.raw"); return(client.LoadRaw("", fileContent, GetCommands(label, priority, directory))); } else { _logger.Debug("Executing remote method: load.raw_start"); return(client.LoadRawStart("", fileContent, GetCommands(label, priority, directory))); } }); if (response != 0) { throw new DownloadClientException("Could not add torrent: {0}.", fileName); } }
public void AddTorrentFromFile(string fileName, byte[] fileContent, string label, RTorrentPriority priority, string directory, bool doNotStart, RTorrentConfig settings) { _logger.Debug("Loading Torrent from File"); var client = BuildClient(settings); var response = -1; if (doNotStart) { _logger.Debug("Executing remote method load.raw"); response = client.LoadRaw("", fileContent, GetCommands(label, priority, directory)); } else { _logger.Debug("Executing remote method load.raw_start"); response = client.LoadRawStart("", fileContent, GetCommands(label, priority, directory)); } if (response != 0) { throw new Exception("Could not add torrent:" + fileName); } }
public void SetTorrentPriority(string hash, RTorrentPriority priority, RTorrentSettings settings) { _logger.Debug("Executing remote method: d.priority.set"); var client = BuildClient(settings); var response = client.SetPriority(hash, (long) priority); if (response != 0) { throw new DownloadClientException("Could not set priority on torrent: {0}.", hash); } }
public void SetDeferredMagnetProperties(string hash, string category, string directory, RTorrentPriority priority, RTorrentSettings settings) { var commands = new List<string>(); if (category.IsNotNullOrWhiteSpace()) { commands.Add("d.custom1.set=" + category); } if (directory.IsNotNullOrWhiteSpace()) { commands.Add("d.directory.set=" + directory); } if (priority != RTorrentPriority.Normal) { commands.Add("d.priority.set=" + (long)priority); } // Ensure it gets started if the user doesn't have schedule=...,start_tied= commands.Add("d.open="); commands.Add("d.start="); if (commands.Any()) { var key = "event.download.inserted_new"; var cmd_key = "sonarr_deferred_" + hash; commands.Add(string.Format("print=\"Applying deferred properties to {0}\"", hash)); // Remove event handler once triggered. commands.Add(string.Format("\"method.set_key={0},{1}\"", key, cmd_key)); var setKeyValue = string.Format("branch=\"equal=d.hash=,cat={0}\",{{{1}}}", hash, string.Join(",", commands)); _logger.Debug("Executing remote method: method.set_key = {0},{1},{2}", key, cmd_key, setKeyValue); var client = BuildClient(settings); // Commands need a target, in this case the target is an empty string // See: https://github.com/rakshasa/rtorrent/issues/227 var response = client.SetKey("", key, cmd_key, setKeyValue); if (response != 0) { throw new DownloadClientException("Could set properties for torrent: {0}.", hash); } } }
public void AddTorrentFromFile(string fileName, byte[] fileContent, string label, RTorrentPriority priority, string directory, RTorrentSettings settings) { var args = new List <object> { "", fileContent }; args.AddRange(GetCommands(label, priority, directory)); XDocument response; if (settings.AddStopped) { response = ExecuteRequest(settings, "load.raw", args.ToArray()); } else { response = ExecuteRequest(settings, "load.raw_start", args.ToArray()); } if (response.GetIntResponse() != 0) { throw new DownloadClientException("Could not add torrent: {0}.", fileName); } }