コード例 #1
0
        public async Task <IHentaiInfoModel> GetInfoAsync(string url)
        {
            var html = await CachedHttpClient.Method(t => t.GetStringAsync(url))
                       .ExpireAfter(TimeSpan.FromDays(1))
                       .GetValueAsync();

            var model = new EHentaiInfoModel
            {
                Title = TitleRegex.Match(html).Value,
                Id    = UrlRegex.Match(url).Groups["id"].Value,
                Cover = await GetCoverAsync(html)
            };

            foreach (var pair in await ExtractTagsAsync(html))
            {
                model.Tags.Add(pair);
            }

            return(model);
        }
コード例 #2
0
        public async Task <IHentaiInfoModel> GetInfoAsync(string url)
        {
            var html = await CachedHttpClient.Method(t => t.GetStringAsync(url))
                       .ExpireAfter(TimeSpan.FromDays(1))
                       .GetValueAsync();

            var htmlParser = BrowsingContext.New();
            var document   = await htmlParser.OpenAsync(req => req.Content(html));

            var model = new NHentaiInfoModel
            {
                Title = string.Join("", document.QuerySelector("h2.title").Children.Select(t => t.Text())),
                Id    = UrlRegex.Match(url).Groups["id"].Value,
                Cover = await GetCoverAsync(html)
            };

            foreach (var pair in await ExtractTagsAsync(html))
            {
                model.Tags.Add(pair);
            }

            return(model);
        }
コード例 #3
0
        public async Task <(bool, string)> GetTranslationAsync(string row, string tag = null)
        {
            string url, target;

            if (tag == null)
            {
                url    = $"{DatabaseUrl}rows.md";
                target = row;
            }
            else
            {
                url    = $"{DatabaseUrl}{row}.md";
                target = tag;
            }

            string markdown;

            try
            {
                markdown = await CachedHttpClient.Method(t => t.GetStringAsync(url))
                           .ExpireAfter(TimeSpan.FromDays(1))
                           .GetValueAsync();
            }
            catch (Exception e)
            {
                _logger.LogError(e, "Get translation failed");
                return(false, target.Replace("_", " "));
            }

            var regex = new Regex($@"\| {target.Replace("_", " ")} \| (?<translation>.+?) \|");
            var match = regex.Match(markdown);

            return(match.Success, match.Success
                ? MarkdownPicReplaceRegex.Replace(match.Groups["translation"].Value, "").Replace(@"\|", "|")
                : target.Replace("_", " "));
        }