private static void SetTitleYearLength(Isan isan, string text)
 {
     var match = TitleYearLengthRegex.Match(text);
     isan.Title = match.Groups[1].Value.Trim();
     isan.Year = Int32.Parse(match.Groups[2].Value.Trim());
     isan.LengthMin = Int32.Parse(match.Groups[3].Value.Trim());
 }
Beispiel #2
0
        public Isan ToIsan()
        {
            var isan = Isan.TryParse(Number);

            isan.Title     = Title;
            isan.Year      = Year;
            isan.LengthMin = LengthMin;
            return(isan);
        }
        private static string GetIsanText(Isan isan)
        {
            if (isan == null)
                return null;

            var lines = new List<string>();

            lines.Add(isan.IsSearchable ? "Valid:" : "Invalid:");
            lines.Add(isan.NumberFormatted);
            if (!string.IsNullOrWhiteSpace(isan.Title))
                lines.Add(string.Format("{0} ({1} - {2} min)", isan.Title, isan.Year, isan.LengthMin));
            else
                lines.Add("(no title/year/runtime found)");

            return string.Join(Environment.NewLine, lines);
        }
        private void Populate(Isan isan, [CanBeNull] CQ dom)
        {
            if (_token.IsCancelled || dom == null)
                return;

            var titles = dom[".title"];
            titles.ForEach(delegate(IDomObject o)
                {
                    var innerText = (o.InnerText ?? "").UnescapeHtml().Trim();
                    var fullText = o.Render().StripHtml().UnescapeHtml().Trim();
                    TryPopulate(isan, innerText);
                    TryPopulate(isan, fullText);
                });
        }
        private CQ GetDom(Isan isan)
        {
            if (_token.IsCancelled)
                return null;

            string status;

            status = string.Format("Querying isan.org for {0} {1}...", isan is VIsan ? "V-ISAN" : "ISAN", isan.NumberFormatted);
            _token.ReportProgress(100.0 * _numRequests / TotalRequests, status);

            var numberEscaped = Uri.EscapeUriString(isan.Number);
            var url = string.Format(IsanLookupUrl, numberEscaped);

            CQ dom = CQ.CreateFromUrl(url, new ServerConfig { UserAgent = UserAgent, Timeout = Timeout });

            status = string.Format("Got response from isan.org for {0} {1}...", isan is VIsan ? "V-ISAN" : "ISAN", isan.NumberFormatted);
            _token.ReportProgress(100.0 * (++_numRequests) / TotalRequests, status);

            return dom;
        }
 private static void TryPopulate(Isan isan, string text)
 {
     if (string.IsNullOrWhiteSpace(text))
         return;
     var title = text.StripLeadingIsan().Trim();
     if (Isan.IsIsan(text))
         Logger.DebugFormat("Full V-ISAN: {0}", text);
     if (IsTitleYearLength(title))
         SetTitleYearLength(isan, title);
 }