protected override void ProcessRecord() { var job = JObject.FromObject(this.InputObject, cSerialize); if (this.MyInvocation.BoundParameters.ContainsKey("NewPath")) { job["path"].Replace(this.NewPath); } if (this.MyInvocation.BoundParameters.ContainsKey("Monitored")) { job["monitored"].Replace(this.Monitored); } if (this.MyInvocation.BoundParameters.ContainsKey("UseSeasonFolder")) { job["seasonFolder"].Replace(this.UseSeasonFolder); } if (this.MyInvocation.BoundParameters.ContainsKey("QualityProfileId")) { job["qualityProfileId"].Replace(this.QualityProfileId); } string jsonBody = JsonConvert.SerializeObject(job, serializer); string full = string.Format("/series/{0}", this.InputObject.SeriesId); string outRes = base.TryPutSonarrResult(full, jsonBody); if (!string.IsNullOrEmpty(outRes)) { SeriesResult series = SonarrHttp.ConvertToSeriesResult(outRes); base.WriteObject(series); } }
protected override void ProcessRecord() { string start = this.DateToString(this.StartDate); string end = this.DateToString(this.EndDate); string full = string.Format(EP_WITH_DATE, start, end); string jsonRes = base.TryGetSonarrResult(full); if (!string.IsNullOrEmpty(jsonRes)) { List <CalendarEntry> entries = SonarrHttp.ConvertToSonarrResults <CalendarEntry>(jsonRes, out bool iso); if (this.ParameterSetName == "ByDayOfWeek") { base.WriteObject(entries.FindAll(x => x.DayOfWeek.HasValue && this.DayOfWeek.Contains(x.DayOfWeek.Value)), true); } else if (this.ParameterSetName == "BySeriesTitle") { var wcp = new WildcardPattern(this.SeriesTitle, WildcardOptions.IgnoreCase); base.WriteObject(entries.FindAll(x => wcp.IsMatch(x.Series)), true); } else { base.WriteObject(entries, true); } } }
protected override void ProcessRecord() { if (this.ParameterSetName == "ByRemotePathName") { string jsonRes = base.TryGetSonarrResult(EP); if (!string.IsNullOrEmpty(jsonRes)) { List <RemotePathMapping> mappings = SonarrHttp.ConvertToSonarrResults <RemotePathMapping>(jsonRes); if (this.MyInvocation.BoundParameters.ContainsKey("RemotePath")) { var wcp = new WildcardPattern(this.RemotePath); base.WriteObject(mappings.FindAll(x => wcp.IsMatch(x.RemotePath)), true); } else { base.WriteObject(mappings, true); } } } else if (this.MyInvocation.BoundParameters.ContainsKey("MappingId")) { for (int i = 0; i < this.MappingId.Length; i++) { string jsonRes = base.TryGetSonarrResult(string.Format(EP_WITH_ID, this.MappingId[i])); if (!string.IsNullOrEmpty(jsonRes)) { RemotePathMapping mapping = SonarrHttp.ConvertToSonarrResult <RemotePathMapping>(jsonRes); base.WriteObject(mapping); } } } }
protected override void ProcessRecord() { if (this.ParameterSetName != "ByClientId") { List <DownloadClient> clients = this.GetAllDownloadClients(); if (clients != null) { if (!this.MyInvocation.BoundParameters.ContainsKey("Protocol")) { base.WriteObject(clients, true); } else { base.WriteObject(this.FindByProtocol(clients), true); } } } else { for (int i = 0; i < this.Id.Length; i++) { string jsonRes = base.TryGetSonarrResult(string.Format(EP_ID, this.Id[i])); if (!string.IsNullOrEmpty(jsonRes)) { DownloadClient dlCli = SonarrHttp.ConvertToSonarrResult <DownloadClient>(jsonRes); base.WriteObject(dlCli); } } } }
protected override void ProcessRecord() { if (this.MyInvocation.BoundParameters.ContainsKey("Id")) { for (int i = 0; i < this.Id.Length; i++) { string ep = string.Format(EP_ID, this.Id[i]); string jsonRes = base.TryGetSonarrResult(ep); if (!string.IsNullOrEmpty(jsonRes)) { QueueItem oneRes = SonarrHttp.ConvertToSonarrResult <QueueItem>(jsonRes); base.WriteObject(oneRes); } } } else { string jsonRes = base.TryGetSonarrResult(EP); if (!string.IsNullOrEmpty(jsonRes)) { List <QueueItem> resses = SonarrHttp.ConvertToSonarrResults <QueueItem>(jsonRes, out bool iso); base.WriteObject(resses, true); } } }
protected override void ProcessRecord() { if (this.MyInvocation.BoundParameters.ContainsKey("JobId")) { for (int i = 0; i < this.JobId.Length; i++) { string ep = string.Format(EP_ID, this.JobId[i]); string jsonRes = base.TryGetSonarrResult(ep); if (!string.IsNullOrEmpty(jsonRes)) { CommandResult output = SonarrHttp.ConvertToSonarrResult <CommandResult>(jsonRes); base.WriteObject(output); } } } else { string jsonRes = base.TryGetSonarrResult(EP); if (!string.IsNullOrEmpty(jsonRes)) { List <CommandResult> jobs = SonarrHttp.ConvertToSonarrResults <CommandResult>(jsonRes, out bool iso); base.WriteObject(jobs, true); } } }
private List <DownloadClient> GetAllDownloadClients() { string jsonRes = base.TryGetSonarrResult(EP); return(!string.IsNullOrEmpty(jsonRes) ? SonarrHttp.ConvertToSonarrResults <DownloadClient>(jsonRes, out bool iso) : null); }
private List <Restriction> GetAllRestrictions() { string jsonRes = base.TryGetSonarrResult(EP); return(!string.IsNullOrEmpty(jsonRes) ? SonarrHttp.ConvertToSonarrResults <Restriction>(jsonRes) : null); }
// BETA - for New-QualityDefinition protected override void EndProcessing() { string qStr = base.TryGetSonarrResult("/qualitydefinition"); if (!string.IsNullOrEmpty(qStr)) { Context.Qualities = SonarrHttp.ConvertToSonarrResults <QualityDefinition>(qStr, out bool iso); } }
protected override void ProcessRecord() { string strRes = base.TryGetSonarrResult("/diskspace"); if (!string.IsNullOrWhiteSpace(strRes)) { List <SonarrDiskspaceResult> sdr = SonarrHttp.ConvertToSonarrResults <SonarrDiskspaceResult>(strRes, out bool iso); base.WriteObject(sdr, true); } }
protected override void ProcessRecord() { string strRes = base.TryGetSonarrResult("/system/status"); if (!string.IsNullOrWhiteSpace(strRes)) { SonarrStatusResult ssr = SonarrHttp.ConvertToSonarrResult <SonarrStatusResult>(strRes); base.WriteObject(ssr); } }
protected override void ProcessRecord() { string full = this.ParameterSetName != "ByEpisodeId" ? string.Format(EP_BY_SERIES, this.SeriesId) : string.Format(EP_BY_EP, this.EpisodeId); string jsonStr = base.TryGetSonarrResult(full); if (!string.IsNullOrEmpty(jsonStr)) { List <EpisodeResult> result = SonarrHttp.ConvertToSonarrResults <EpisodeResult>(jsonStr, out bool iso); foreach (EpisodeResult er in result) { if (er.AirDateUtc.HasValue) { er.AirDateUtc = er.AirDateUtc.Value.ToUniversalTime(); } } if (this.MyInvocation.BoundParameters.ContainsKey("AbsoluteEpisodeNumber")) { IEnumerable <EpisodeResult> results = result.Where(x => x.AbsoluteEpisodeNumber.HasValue && this.AbsoluteEpisodeNumber.Contains(x.AbsoluteEpisodeNumber.Value)); base.WriteObject(results, true); } else if (this.MyInvocation.BoundParameters.ContainsKey("EpisodeIdentifier")) { var list = new List <EpisodeResult>(result.Count); for (int i = 0; i < this.EpisodeIdentifier.Length; i++) { EpisodeIdentifier epid = this.EpisodeIdentifier[i]; for (int e = 0; e < result.Count; e++) { EpisodeResult er = result[e]; if (er.SeasonNumber == epid.Season) { if (!epid.Episode.HasValue || (epid.Episode.HasValue && er.EpisodeNumber == epid.Episode.Value)) { list.Add(er); } } } } list.Sort(new EpisodeComparer()); var ieq = new EpisodeEquality(); base.WriteObject(list.Distinct(ieq), true); } else { base.WriteObject(result, true); } } }
/// <summary> /// Takes in a generic dictionary of parameters and issues a command to Sonarr with the dictionary as its payload. /// </summary> /// <param name="parameterDict">The set of parameters to build the POST body with,</param> protected void ProcessRequest(IDictionary parameterDict) { string cmdName = parameterDict["name"] as string; string verbMsg = string.Format("Issuing command - {0} at {1}", cmdName, BASE_EP); string postBody = JsonConvert.SerializeObject(parameterDict, Formatting.Indented); string cmdOut = base.TryPostSonarrResult(BASE_EP, postBody); if (!string.IsNullOrEmpty(cmdOut)) { CommandOutput cmdOutput = SonarrHttp.ConvertToSonarrResult <CommandOutput>(cmdOut); base.WriteObject(cmdOutput); } }
protected override void ProcessRecord() { Restriction newRestrict = this.ParametersToRestriction(this.MyInvocation.BoundParameters); if (base.ShouldProcess(string.Format(SHOULD_MSG, newRestrict.Ignored.ToJson(), newRestrict.Required.ToJson()), "New")) { string jsonRes = base.TryPostSonarrResult(GetRestriction.EP, newRestrict.ToJson()); if (!string.IsNullOrEmpty(jsonRes)) { Restriction restRes = SonarrHttp.ConvertToSonarrResult <Restriction>(jsonRes); base.WriteObject(restRes); } } }
protected override void ProcessRecord() { string full = this.ParameterSetName == "BySeriesId" ? string.Format(EP_BY_SERIES, this.Series.SeriesId) : this.ParameterSetName == "ByEpisodeFileId" ? string.Format(EP_BY_EP, this.EpisodeFileId) : string.Format(EP_BY_EP, this.EpisodeFile.EpisodeFileId); string jsonStr = base.TryGetSonarrResult(full); if (!string.IsNullOrEmpty(jsonStr)) { List <EpisodeFile> result = SonarrHttp.ConvertToSonarrResults <EpisodeFile>(jsonStr, out bool iso); base.WriteObject(result, true); } }
protected override void ProcessRecord() { if (this.ParameterSetName == "ByProfileName") { List <QualityProfile> profs = null; string jsonStr = base.TryGetSonarrResult("/profile"); if (!string.IsNullOrEmpty(jsonStr)) { profs = SonarrHttp.ConvertToSonarrResults <QualityProfile>(jsonStr, out bool iso); } if (profs != null && profs.Count > 0) { if (this.Name != null && this.Name.Length > 0) { for (int n = 0; n < this.Name.Length; n++) { string name = this.Name[n]; var wcp = new WildcardPattern(name, WildcardOptions.IgnoreCase); for (int p = 0; p < profs.Count; p++) { QualityProfile qp = profs[p]; if (wcp.IsMatch(qp.Name)) { base.WriteObject(qp); } } } } else { base.WriteObject(profs, true); } } } else { string full = string.Format("/profile/{0}", this.Id); string oneProf = base.TryGetSonarrResult(full); if (!string.IsNullOrEmpty(oneProf)) { QualityProfile qp = SonarrHttp.ConvertToSonarrResult <QualityProfile>(oneProf); base.WriteObject(qp); } } }
protected override void ProcessRecord() { if (this.ParameterSetName == "ByTagLabel") { string allRes = base.TryGetSonarrResult(EP); List <Tag> tags = null; if (!string.IsNullOrEmpty(allRes)) { tags = SonarrHttp.ConvertToSonarrResults <Tag>(allRes, out bool iso); } if (tags.Count > 0) { if (this.MyInvocation.BoundParameters.ContainsKey("Label")) { for (int i = 0; i < this.Label.Length; i++) { var wcp = new WildcardPattern(this.Label[i], WildcardOptions.IgnoreCase); for (int t = 0; t < tags.Count; t++) { Tag oneTag = tags[t]; if (wcp.IsMatch(oneTag.Label)) { base.WriteObject(oneTag); } } } } else { base.WriteObject(tags, true); } } } else { for (int i = 0; i < this.Id.Length; i++) { string ep = string.Format(EP_ID, this.Id[i]); string jsonRes = base.TryGetSonarrResult(ep); if (!string.IsNullOrEmpty(jsonRes)) { base.WriteObject(SonarrHttp.ConvertToSonarrResult <Tag>(jsonRes)); } } } }
protected override void ProcessRecord() { if (this.ParameterSetName == "BySeriesName") { List <SeriesResult> list = null; string searchStr = this.ParseSearchString(this.Name); string full = string.Format(@"/series/lookup?{0}", searchStr); if (base.ShouldProcess(full, "Executing API call")) { string jsonStr = base.TryGetSonarrResult(full); if (!string.IsNullOrEmpty(jsonStr)) { var tok = JToken.Parse(jsonStr); list = SonarrHttp.ConvertToSeriesResults(jsonStr, false); if (this.Strict.ToBool()) { base.WriteObject(list.FindAll(x => x.Name.IndexOf(this.Name, StringComparison.CurrentCultureIgnoreCase) >= 0), true); } else { base.WriteObject(list, true); } } } } else { string searchStr = this.ParseSearchId(this.TVDBId); string full = string.Format(@"/series/lookup?{0}", searchStr); if (base.ShouldProcess(full, "Executing API call")) { string jsonStr = base.TryGetSonarrResult(full); if (!string.IsNullOrEmpty(jsonStr)) { var tok = JToken.Parse(jsonStr); List <SeriesResult> list = SonarrHttp.ConvertToSeriesResults(jsonStr, false); base.WriteObject(list, true); } } } }
protected override void ProcessRecord() { string jsonStr = base.TryGetSonarrResult("/system/backup"); if (!string.IsNullOrWhiteSpace(jsonStr)) { List <SonarrBackupResult> backups = SonarrHttp.ConvertToSonarrResults <SonarrBackupResult>(jsonStr, out bool iso); if (this.Type != null && this.Type.Length > 0) { base.WriteObject(backups.Where(x => this.Type.Contains(x.Type)), true); } else { base.WriteObject(backups, true); } } }
protected override void ProcessRecord() { var dict = new Dictionary <string, string>(1) { { "label", this.Label } }; string jsonBody = JsonConvert.SerializeObject(dict, Formatting.Indented); if (base.ShouldProcess(string.Format("Tag - {0}", this.Label), "New")) { string jsonRes = base.TryPostSonarrResult(EP, jsonBody); if (!string.IsNullOrEmpty(jsonRes)) { Tag res = SonarrHttp.ConvertToSonarrResult <Tag>(jsonRes); base.WriteObject(res); } } }
protected override void ProcessRecord() { if (!this.Path.EndsWith(@"\")) { this.Path = this.Path + @"\"; } string fullEp = string.Format(EP, this.Path); string jsonRes = base.TryGetSonarrResult(fullEp); if (!string.IsNullOrEmpty(jsonRes)) { FileSystem fs = SonarrHttp.ConvertToSonarrResult <FileSystem>(jsonRes); if (fs != null) { base.WriteObject(fs.Directories, true); } } }
protected override void ProcessRecord() { string jsonRes = base.TryGetSonarrResult(EP); if (!string.IsNullOrEmpty(jsonRes)) { List <LogFile> logFiles = SonarrHttp.ConvertToSonarrResults <LogFile>(jsonRes); logFiles.Sort(ClassFactory.GenerateLogFileComparer()); if (this.MyInvocation.BoundParameters.ContainsKey("LogFileId")) { base.WriteObject(logFiles.FindAll(x => this.LogFileId.Contains(x.LogFileId)), true); } else if (this.MyInvocation.BoundParameters.ContainsKey("Name")) { IEqualityComparer <string> ig = ClassFactory.NewIgnoreCase(); List <LogFile> list = logFiles.FindAll(x => this.Name.Contains(x.FileName, ig)); base.WriteObject(list, true); } else { base.WriteObject(logFiles, true); } } }
private Restriction GetRestrictionById(int id) { string jsonRes = base.TryGetSonarrResult(string.Format(EP_ID, id)); return(SonarrHttp.ConvertToSonarrResult <Restriction>(jsonRes)); }