예제 #1
0
        public virtual IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            var releases = new List <ReleaseInfo>();

            if (!PreProcess(indexerResponse))
            {
                return(releases);
            }

            using (var xmlTextReader = XmlReader.Create(new StringReader(indexerResponse.Content), new XmlReaderSettings {
                DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true
            }))
            {
                var document = XDocument.Load(xmlTextReader);
                var items    = GetItems(document);

                foreach (var item in items)
                {
                    try
                    {
                        var reportInfo = ProcessItem(item);

                        releases.AddIfNotNull(reportInfo);
                    }
                    catch (Exception itemEx)
                    {
                        itemEx.Data.Add("Item", item.Title());
                        _logger.ErrorException("An error occurred while processing feed item from " + indexerResponse.Request.Url, itemEx);
                    }
                }
            }

            return(releases);
        }
예제 #2
0
        public virtual IList <ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            _indexerResponse = indexerResponse;

            var releases = new List <ReleaseInfo>();

            if (!PreProcess(indexerResponse))
            {
                return(releases);
            }

            var document = LoadXmlDocument(indexerResponse);
            var items    = GetItems(document);

            foreach (var item in items)
            {
                try
                {
                    var reportInfo = ProcessItem(item);

                    releases.AddIfNotNull(reportInfo);
                }
                catch (Exception itemEx)
                {
                    itemEx.Data.Add("Item", item.Title());
                    _logger.Error(itemEx, "An error occurred while processing feed item from {0}", indexerResponse.Request.Url);
                }
            }

            return(releases);
        }
예제 #3
0
        protected virtual XDocument LoadXmlDocument(IndexerResponse indexerResponse)
        {
            try
            {
                var content = indexerResponse.Content;
                content = ReplaceEntities.Replace(content, ReplaceEntity);

                using (var xmlTextReader = XmlReader.Create(new StringReader(content), new XmlReaderSettings {
                    DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true
                }))
                {
                    return(XDocument.Load(xmlTextReader));
                }
            }
            catch (XmlException ex)
            {
                var contentSample = indexerResponse.Content.Substring(0, Math.Min(indexerResponse.Content.Length, 512));
                _logger.Debug("Truncated response content (originally {0} characters): {1}", indexerResponse.Content.Length, contentSample);

                ex.Data.Add("ContentLength", indexerResponse.Content.Length);
                ex.Data.Add("ContentSample", contentSample);

                throw;
            }
        }
예제 #4
0
        public virtual IList<ReleaseInfo> ParseResponse(IndexerResponse indexerResponse)
        {
            _indexerResponse = indexerResponse;

            var releases = new List<ReleaseInfo>();

            if (!PreProcess(indexerResponse))
            {
                return releases;
            }

            var document = LoadXmlDocument(indexerResponse);
            var items = GetItems(document);

            foreach (var item in items)
            {
                try
                {
                    var reportInfo = ProcessItem(item);

                    releases.AddIfNotNull(reportInfo);
                }
                catch (Exception itemEx)
                {
                    itemEx.Data.Add("Item", item.Title());
                    _logger.ErrorException("An error occurred while processing feed item from " + indexerResponse.Request.Url, itemEx);
                }
            }

            return releases;
        }
예제 #5
0
        public IEnumerable <XElement> GetItems(IndexerResponse indexerResponse)
        {
            var document = LoadXmlDocument(indexerResponse);
            var items    = GetItems(document);

            return(items);
        }
예제 #6
0
        public IEnumerable<XElement> GetItems(IndexerResponse indexerResponse)
        {
            var document = LoadXmlDocument(indexerResponse);
            var items = GetItems(document);

            return items;
        }
예제 #7
0
        protected virtual IList <ReleaseInfo> FetchPage(IndexerRequest request, IParseIndexerResponse parser)
        {
            _logger.Debug("Downloading Feed " + request.Url);

            var response = new IndexerResponse(request, _httpClient.Execute(request.HttpRequest));

            return(parser.ParseResponse(response).ToList());
        }
예제 #8
0
        protected virtual Boolean PreProcess(IndexerResponse indexerResponse)
        {
            if (indexerResponse.HttpResponse.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new IndexerException("Indexer API call resulted in an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode);
            }

            return(true);
        }
예제 #9
0
        protected override bool PreProcess(IndexerResponse indexerResponse)
        {
            var document = LoadXmlDocument(indexerResponse);
            var items    = GetItems(document).ToList();

            if (items.Count == 1 && GetTitle(items.First()).Equals("No items exist - Try again later"))
            {
                throw new IndexerException(indexerResponse, "No results were found");
            }

            return(base.PreProcess(indexerResponse));
        }
예제 #10
0
        protected override bool PreProcess(IndexerResponse indexerResponse)
        {
            var document = LoadXmlDocument(indexerResponse);
            var items = GetItems(document).ToList();

            if (items.Count == 1 && GetTitle(items.First()).Equals("No items exist - Try again later"))
            {
                throw new IndexerException(indexerResponse, "No results were found");
            }

            return base.PreProcess(indexerResponse);
        }
예제 #11
0
        protected virtual IList <ReleaseInfo> FetchPage(IndexerRequest request, IParseIndexerResponse parser)
        {
            var url = request.Url;

            _logger.Debug("Downloading Feed " + request.Url);
            var response = new IndexerResponse(request, _httpClient.Execute(request.HttpRequest));

            if (response.HttpResponse.Headers.ContentType != null && response.HttpResponse.Headers.ContentType.Contains("text/html") &&
                request.HttpRequest.Headers.Accept != null && !request.HttpRequest.Headers.Accept.Contains("text/html"))
            {
                throw new WebException("Indexer responded with html content. Site is likely blocked or unavailable.");
            }

            return(parser.ParseResponse(response).ToList());
        }
예제 #12
0
파일: RssParser.cs 프로젝트: silk186/Sonarr
        protected virtual bool PreProcess(IndexerResponse indexerResponse)
        {
            if (indexerResponse.HttpResponse.StatusCode != HttpStatusCode.OK)
            {
                throw new IndexerException(indexerResponse, "Indexer API call resulted in an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode);
            }

            if (indexerResponse.HttpResponse.Headers.ContentType != null && indexerResponse.HttpResponse.Headers.ContentType.Contains("text/html") &&
                indexerResponse.HttpRequest.Headers.Accept != null && !indexerResponse.HttpRequest.Headers.Accept.Contains("text/html"))
            {
                throw new IndexerException(indexerResponse, "Indexer responded with html content. Site is likely blocked or unavailable.");
            }

            return(true);
        }
예제 #13
0
        protected override bool PreProcess(IndexerResponse indexerResponse)
        {
            using (var xmlTextReader = XmlReader.Create(new StringReader(indexerResponse.Content), new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true }))
            {
                var document = XDocument.Load(xmlTextReader);
                var items = GetItems(document).ToList();

                if (items.Count == 1 && GetTitle(items.First()).Equals("No items exist - Try again later"))
                {
                    throw new IndexerException(indexerResponse, "No results were found");
                }
            }

            return base.PreProcess(indexerResponse);
        }
예제 #14
0
        protected override bool PreProcess(IndexerResponse indexerResponse)
        {
            using (var xmlTextReader = XmlReader.Create(new StringReader(indexerResponse.Content), new XmlReaderSettings {
                DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true
            }))
            {
                var document = XDocument.Load(xmlTextReader);
                var items    = GetItems(document).ToList();

                if (items.Count == 1 && GetTitle(items.First()).Equals("No items exist - Try again later"))
                {
                    throw new IndexerException(indexerResponse, "No results were found");
                }
            }

            return(base.PreProcess(indexerResponse));
        }
예제 #15
0
        protected virtual XDocument LoadXmlDocument(IndexerResponse indexerResponse)
        {
            try
            {
                using (var xmlTextReader = XmlReader.Create(new StringReader(indexerResponse.Content), new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true }))
                {
                    return XDocument.Load(xmlTextReader);
                }
            }
            catch (XmlException ex)
            {
                var contentSample = indexerResponse.Content.Substring(0, Math.Min(indexerResponse.Content.Length, 512));
                _logger.Debug("Truncated response content (originally {0} characters): {1}", indexerResponse.Content.Length, contentSample);

                ex.Data.Add("ContentLength", indexerResponse.Content.Length);
                ex.Data.Add("ContentSample", contentSample);

                throw;
            }
        }
예제 #16
0
 protected virtual bool PostProcess(IndexerResponse indexerResponse, List <XElement> elements, List <ReleaseInfo> releases)
 {
     return(true);
 }
예제 #17
0
파일: RssParser.cs 프로젝트: nnic/Sonarr
        protected virtual Boolean PreProcess(IndexerResponse indexerResponse)
        {
            if (indexerResponse.HttpResponse.StatusCode != System.Net.HttpStatusCode.OK)
            {
                throw new IndexerException(indexerResponse, "Indexer API call resulted in an unexpected StatusCode [{0}]", indexerResponse.HttpResponse.StatusCode);
            }

            if (indexerResponse.HttpResponse.Headers.ContentType != null && indexerResponse.HttpResponse.Headers.ContentType.Contains("text/html") &&
                indexerResponse.HttpRequest.Headers.Accept != null && !indexerResponse.HttpRequest.Headers.Accept.Contains("text/html"))
            {
                throw new IndexerException(indexerResponse, "Indexer responded with html content. Site is likely blocked or unavailable.");
            }

            return true;
        }