Exemplo n.º 1
0
        private void SetAge(IdolImage img, string ageString, Action <string, string> errorHandler)
        {
            img.Age = GetNumber(ageString, errorHandler);

            if (img.Age == 0 && ageString?.Length > 0)
            {
                img.SpecialAge = ageString;
            }
        }
Exemplo n.º 2
0
        private void SetWeight(IdolImage img, string weightString, Action <string, string> errorHandler)
        {
            img.Weight = GetNumber(weightString, errorHandler);

            if (img.Weight == 0 && weightString?.Length > 0)
            {
                img.SpecialWeight = weightString;
            }
        }
Exemplo n.º 3
0
        private void SetHeight(IdolImage img, string heightString, Action <string, string> errorHandler)
        {
            img.Height = GetNumber(heightString, errorHandler);

            if (img.Height == 0 && heightString?.Length > 0)
            {
                img.SpecialHeight = heightString;
            }
        }
Exemplo n.º 4
0
        private void SetSunSign(IdolImage img, string sunSign, Action <string, string> errorHandler)
        {
            var v = GetSunSign(sunSign, errorHandler);

            if (v != SunSign.Unknown)
            {
                img.SunSign = v;
            }
            else if (!string.IsNullOrEmpty(sunSign))
            {
                img.SpecialSunSign = sunSign;
            }
        }
Exemplo n.º 5
0
        public JsonIdolImage(IdolImage model)
        {
            Headline = model.Headline;
            Name     = model.Idol?.Name;
            Kana     = model.Idol?.Kana;
            Hash     = model.Hash;
            Rarity   = model.Rarity.ToString();
            IdolType = model.Type.ToString();

            BloodType  = model.BloodType.ToString();
            Height     = model.SpecialHeight ?? $"{model.Height}cm";
            Weight     = model.SpecialWeight ?? $"{model.Weight}kg";
            Bust       = model.SpecialBust ?? $"{model.Bust}";
            Waist      = model.SpecialWaist ?? $"{model.Waist}";
            Hip        = model.SpecialHip ?? $"{model.Hip}";
            Age        = model.SpecialAge ?? $"{model.Age}歳";
            Birthday   = model.SpecialBirthday ?? $"{model.BirthDay}月{model.BirthMonth}日";
            SunSign    = model.SpecialSunSign ?? model.SunSign.GetDisplayName();
            Birthplace = model.Birthplace;
            Hobby      = model.Hobby;
            Handedness = model.Handedness.ToString();
        }
Exemplo n.º 6
0
        private void SetThreeSize(IdolImage image, string value, Action <string, string> errorHandler)
        {
            var m = Regex.Match(value ?? string.Empty, @"^\s*(?<b>[0-9]{1,3})\s*/\s*(?<w>[0-9]{1,3})\s*/\s*(?<h>[0-9]{1,3})\s*$");

            if (m.Success)
            {
                byte b, w, h;

                if (byte.TryParse(m.Groups["b"].Value, out b) &&
                    byte.TryParse(m.Groups["w"].Value, out w) &&
                    byte.TryParse(m.Groups["h"].Value, out h))
                {
                    image.Bust  = b;
                    image.Waist = w;
                    image.Hip   = h;
                    return;
                }
            }

            if (!string.IsNullOrEmpty(value))
            {
                var vs = value.Split('/');

                if (vs.Length == 3)
                {
                    image.SpecialBust  = vs[0].Trim();
                    image.SpecialWaist = vs[1].Trim();
                    image.SpecialHip   = vs[2].Trim();
                }
                else
                {
                    image.SpecialBust  = value;
                    image.SpecialWaist = null;
                    image.SpecialHip   = null;
                }

                errorHandler?.Invoke(nameof(image.Bust), value);
            }
        }
Exemplo n.º 7
0
        private void SetBirthday(IdolImage image, string value, Action <string, string> errorHandler)
        {
            var m = Regex.Match(value ?? string.Empty, @"^\s*(?<m>[0-9]{1,2})\s*月\s*(?<d>[0-9]{1,2})\s*日\s*$");

            if (m.Success)
            {
                byte b, w;

                if (byte.TryParse(m.Groups["m"].Value, out b) &&
                    byte.TryParse(m.Groups["d"].Value, out w))
                {
                    image.BirthDay   = b;
                    image.BirthMonth = w;
                    return;
                }
            }

            if (!string.IsNullOrEmpty(value))
            {
                image.SpecialBirthday = value;
                errorHandler?.Invoke(nameof(image.BirthMonth), value);
            }
        }
Exemplo n.º 8
0
        public async Task <List <IdolImage> > GetIdolImagesAsync(string urlFormat = null, Action <string, string> errorHandler = null)
        {
            var doc = new HtmlDocument();

            using (var wc = new WebClient())
            {
                var data = await wc.DownloadDataTaskAsync(string.Format(urlFormat ?? Settings.Default.IdolImageUrlFormat, +Id));

                using (var ms = new MemoryStream(data))
                    using (var sr = new StreamReader(ms, Encoding.UTF8))
                    {
                        doc.Load(sr);
                    }
            }

            var imgs = new List <IdolImage>();

            foreach (var a in doc.DocumentNode.Descendants("a"))
            {
                if (a.GetAttributeValue("class", "") != "swap-card")
                {
                    continue;
                }

                var div = a.ParentNode.ParentNode;

                var inftable = div.Descendants("table").Where(_ => _.GetAttributeValue("class", "") == "bcinf").FirstOrDefault(_ => _.Descendants("th").Any(h => h.InnerText.Contains("レア度")));

                var tr1 = inftable.Descendants("tr").ElementAt(1).Descendants("td").ToArray();
                var tr3 = inftable.Descendants("tr").ElementAt(3).Descendants("td").ToArray();

                var img = new IdolImage()
                {
                    Idol     = this,
                    IdolId   = Id,
                    Headline = div.Descendants("h2").FirstOrDefault(_ => _.GetAttributeValue("class", "") == "headline")?.InnerText?.Trim(),
                    Hash     = a.GetAttributeValue("href", "").Split('=').Last(),
                };

                var hlm = Regex.Match(img.Headline, @"\s+\(\d+年\d+月\d+日公開\)$");
                if (hlm.Success)
                {
                    img.Headline = img.Headline.Substring(img.Headline.Length - hlm.Length);
                }

                img.Rarity    = GetRarity(tr1[0].InnerText, img.Headline, errorHandler);
                img.Type      = GetType(tr1[1].InnerText, errorHandler);
                img.BloodType = GetBloodType(tr1[2].InnerText, errorHandler);

                SetHeight(img, tr1[3].InnerText?.Trim(), errorHandler);
                SetWeight(img, tr1[4].InnerText?.Trim(), errorHandler);
                SetThreeSize(img, tr1[5].InnerText?.Trim(), errorHandler);

                SetAge(img, tr3[0].InnerText?.Trim(), errorHandler);
                SetBirthday(img, tr3[1].InnerText?.Trim(), errorHandler);
                SetSunSign(img, tr3[2].InnerText?.Trim(), errorHandler);

                img.Birthplace = tr3[3].InnerText.Trim();
                img.Hobby      = tr3[4].InnerText.Trim();
                img.Handedness = GetHandedness(tr3[5].InnerText, errorHandler);

                imgs.Add(img);
            }

            return(imgs);
        }