public string GetUrl([NotNull] string s, bool instanceSearchJsonUseCloudflare) { if (internalCache.TryGetValue(s, out string value)) { return(value); } string newValue = HttpHelper.GetUrl(s, instanceSearchJsonUseCloudflare); internalCache.TryAdd(s, newValue); return(newValue); }
// ReSharper disable once InconsistentNaming public bool DownloadRSS([NotNull] string url, bool useCloudflareProtection, string sourcePrefix) { string response = null; try { response = HttpHelper.GetUrl(url, useCloudflareProtection); XElement x = XElement.Load(new System.IO.StringReader(response)); if (x.Name.LocalName != "rss") { return(false); } if (!ReadChannel(x.Descendants("channel").First(), url, sourcePrefix)) { return(false); } } catch (WebException e) { Logger.LogWebException($"Could not download RSS page at: {url} got the following message:", e); return(false); } catch (XmlException e) { Logger.Warn($"Could not parse RSS page at:{url} Message was: {e.Message}"); Logger.Info(response); return(false); } catch (AggregateException ex) when(ex.InnerException is WebException wex) { Logger.LogWebException($"Could not download RSS page at: {url} got the following message: ", wex); return(false); } catch (AggregateException ex) when(ex.InnerException is System.Net.Http.HttpRequestException hex) { Logger.LogHttpRequestException($"Could not download RSS page at: {url} got the following message: ", hex); return(false); } catch (Exception e) { Logger.Error(e, $"Could not parse RSS page at:{url}"); return(false); } return(true); }
// ReSharper disable once InconsistentNaming public bool DownloadRSS([NotNull] string url, List <TVSettings.FilenameProcessorRE> rexps, bool useCloudflareProtection) { regxps = rexps; string response = null; try { response = HttpHelper.GetUrl(url, useCloudflareProtection); XElement x = XElement.Load(new System.IO.StringReader(response ?? "")); if (x.Name.LocalName != "rss") { return(false); } if (!ReadChannel(x.Descendants("channel").First())) { return(false); } } catch (WebException e) { Logger.LogWebException($"Could not download RSS page at: {url} got the following message:", e); return(false); } catch (XmlException e) { Logger.Warn($"Could not parse RSS page at:{url} Message was: {e.Message}"); Logger.Info(response); return(false); } catch (AggregateException ex) when(ex.InnerException is WebException wex) { Logger.LogWebException($"Could not download RSS page at: {url} got the following message: ", wex); return(false); } catch (Exception e) { Logger.Error(e, $"Could not parse RSS page at:{url}"); return(false); } finally { regxps = null; } return(true); }
private static void FindMissingEpisode([NotNull] ItemMissing action, ItemList toRemove, ItemList newItems) { ProcessedEpisode pe = action.Episode; string simpleShowName = Helpers.SimplifyName(pe.Show.ShowName); string simpleSeriesName = Helpers.SimplifyName(pe.TheSeries.Name); ItemList newItemsForThisMissingEpisode = new ItemList(); string imdbId = pe.TheSeries.GetImdbNumber(); if (string.IsNullOrWhiteSpace(imdbId)) { return; } string response = HttpHelper.GetUrl($"{TVSettings.Instance.SearchJSONURL}{imdbId}", TVSettings.Instance.SearchJSONUseCloudflare); if (string.IsNullOrWhiteSpace(response)) { LOGGER.Warn( $"Got no response from {TVSettings.Instance.SearchJSONURL}{imdbId} for {action.Episode.TheSeries.Name}"); return; } JObject jsonResponse = JObject.Parse(response); if (jsonResponse.ContainsKey(TVSettings.Instance.SearchJSONRootNode)) { foreach (JToken item in jsonResponse[TVSettings.Instance.SearchJSONRootNode]) { if (item is null || !(item is JObject episodeResponse)) { continue; } if (episodeResponse.ContainsKey(TVSettings.Instance.SearchJSONFilenameToken) && episodeResponse.ContainsKey(TVSettings.Instance.SearchJSONURLToken)) { string itemName = (string)item[TVSettings.Instance.SearchJSONFilenameToken]; string itemUrl = (string)item[TVSettings.Instance.SearchJSONURLToken]; long itemSizeBytes = CalculateItemSizeBytes(item); if (TVSettings.Instance.DetailedRSSJSONLogging) { LOGGER.Info("Processing JSON Item"); LOGGER.Info(episodeResponse.ToString); LOGGER.Info("Extracted"); LOGGER.Info($"Name: {itemName}"); LOGGER.Info($"URL: {itemUrl}"); LOGGER.Info($"Size: {itemSizeBytes}"); } if (!FileHelper.SimplifyAndCheckFilename(itemName, simpleShowName, true, false) && !FileHelper.SimplifyAndCheckFilename(itemName, simpleSeriesName, true, false)) { continue; } if (!FinderHelper.FindSeasEp(itemName, out int seas, out int ep, out int _, pe.Show)) { continue; } if (TVSettings.Instance.DetailedRSSJSONLogging) { LOGGER.Info($"Season: {seas}"); LOGGER.Info($"Episode: {ep}"); } if (seas != pe.AppropriateSeasonNumber) { continue; } if (ep != pe.AppropriateEpNum) { continue; } LOGGER.Info( $"Adding {itemUrl} from JSON page as it appears to be match for {pe.Show.ShowName} S{pe.AppropriateSeasonNumber}E{pe.AppropriateEpNum}"); newItemsForThisMissingEpisode.Add(new ActionTDownload(itemName, itemSizeBytes, itemUrl, action.TheFileNoExt, pe, action)); toRemove.Add(action); } else { LOGGER.Info( $"{TVSettings.Instance.SearchJSONFilenameToken} or {TVSettings.Instance.SearchJSONURLToken} not found in {TVSettings.Instance.SearchJSONURL}{imdbId} for {action.Episode.TheSeries.Name}"); } } } else { LOGGER.Info( $"{TVSettings.Instance.SearchJSONRootNode} not found in {TVSettings.Instance.SearchJSONURL}{imdbId} for {action.Episode.TheSeries.Name}"); } RemoveDuplicates(newItemsForThisMissingEpisode); newItems.AddNullableRange(newItemsForThisMissingEpisode); }