.novel done, waifutransfer almost done
This commit is contained in:
		@@ -37,7 +37,7 @@ namespace NadekoBot.Modules.Searches
 | 
			
		||||
                    .WithImageUrl(novelData.ImageUrl)
 | 
			
		||||
                    .AddField(efb => efb.WithName(GetText("authors")).WithValue(String.Join("\n", novelData.Authors)).WithIsInline(true))
 | 
			
		||||
                    .AddField(efb => efb.WithName(GetText("status")).WithValue(novelData.Status).WithIsInline(true))
 | 
			
		||||
                    .AddField(efb => efb.WithName(GetText("genres")).WithValue(string.Join(",\n", novelData.Genres.Any() ? novelData.Genres : new[] { "none" })).WithIsInline(true))
 | 
			
		||||
                    .AddField(efb => efb.WithName(GetText("genres")).WithValue(string.Join(" ", novelData.Genres.Any() ? novelData.Genres : new[] { "none" })).WithIsInline(true))
 | 
			
		||||
                    .WithFooter(efb => efb.WithText(GetText("score") + " " + novelData.Score));
 | 
			
		||||
                await Context.Channel.EmbedAsync(embed).ConfigureAwait(false);
 | 
			
		||||
            }
 | 
			
		||||
 
 | 
			
		||||
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Modules.Searches.Common
 | 
			
		||||
{
 | 
			
		||||
    public class NovelData
 | 
			
		||||
    public class NovelResult
 | 
			
		||||
    {
 | 
			
		||||
        public string Description { get; set; }
 | 
			
		||||
        public string Title { get; set; }
 | 
			
		||||
 
 | 
			
		||||
@@ -5,6 +5,9 @@ using System;
 | 
			
		||||
using System.Net.Http;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using NadekoBot.Modules.Searches.Common;
 | 
			
		||||
using AngleSharp;
 | 
			
		||||
using AngleSharp.Dom.Html;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
 | 
			
		||||
namespace NadekoBot.Modules.Searches.Services
 | 
			
		||||
{
 | 
			
		||||
@@ -46,7 +49,7 @@ namespace NadekoBot.Modules.Searches.Services
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public async Task<NovelData> GetNovelData(string query)
 | 
			
		||||
        public async Task<NovelResult> GetNovelData(string query)
 | 
			
		||||
        {
 | 
			
		||||
            if (string.IsNullOrWhiteSpace(query))
 | 
			
		||||
                throw new ArgumentNullException(nameof(query));
 | 
			
		||||
@@ -57,18 +60,66 @@ namespace NadekoBot.Modules.Searches.Services
 | 
			
		||||
 | 
			
		||||
                var link = "http://www.novelupdates.com/series/" + Uri.EscapeDataString(query.Replace("/", " "));
 | 
			
		||||
                link = link.ToLowerInvariant();
 | 
			
		||||
                var (ok, data) = await _cache.TryGetAnimeDataAsync(link).ConfigureAwait(false);
 | 
			
		||||
                var (ok, data) = await _cache.TryGetNovelDataAsync(link).ConfigureAwait(false);
 | 
			
		||||
                if (!ok)
 | 
			
		||||
                {
 | 
			
		||||
                    data = await _http.GetStringAsync(link).ConfigureAwait(false);
 | 
			
		||||
                    await _cache.SetAnimeDataAsync(link, data).ConfigureAwait(false);
 | 
			
		||||
                    var config = Configuration.Default.WithDefaultLoader();
 | 
			
		||||
                    var document = await BrowsingContext.New(config).OpenAsync(link);
 | 
			
		||||
 | 
			
		||||
                    var imageElem = document.QuerySelector("div.seriesimg > img");
 | 
			
		||||
                    var imageUrl = ((IHtmlImageElement)imageElem).Source;
 | 
			
		||||
 | 
			
		||||
                    var descElem = document.QuerySelector("div#editdescription > p");
 | 
			
		||||
                    var desc = descElem.InnerHtml;
 | 
			
		||||
 | 
			
		||||
                    var genres = document.QuerySelector("div#seriesgenre").Children
 | 
			
		||||
                        .Select(x => x as IHtmlAnchorElement)
 | 
			
		||||
                        .Where(x => x != null)
 | 
			
		||||
                        .Select(x => $"[{x.InnerHtml}]({x.Href})")
 | 
			
		||||
                        .ToArray();
 | 
			
		||||
 | 
			
		||||
                    var authors = document
 | 
			
		||||
                        .QuerySelector("div#showauthors")
 | 
			
		||||
                        .Children
 | 
			
		||||
                        .Select(x => x as IHtmlAnchorElement)
 | 
			
		||||
                        .Where(x => x != null)
 | 
			
		||||
                        .Select(x => $"[{x.InnerHtml}]({x.Href})")
 | 
			
		||||
                        .ToArray();
 | 
			
		||||
 | 
			
		||||
                    var score = ((IHtmlSpanElement)document
 | 
			
		||||
                        .QuerySelector("h5.seriesother > span.uvotes"))
 | 
			
		||||
                        .InnerHtml;
 | 
			
		||||
 | 
			
		||||
                    var status = document
 | 
			
		||||
                        .QuerySelector("div#editstatus")
 | 
			
		||||
                        .InnerHtml;
 | 
			
		||||
                    var title = document
 | 
			
		||||
                        .QuerySelector("div.w-blog-content > div.seriestitlenu")
 | 
			
		||||
                        .InnerHtml;
 | 
			
		||||
 | 
			
		||||
                    var obj = new NovelResult()
 | 
			
		||||
                    {
 | 
			
		||||
                        Description = desc,
 | 
			
		||||
                        Authors = authors,
 | 
			
		||||
                        Genres = genres,
 | 
			
		||||
                        ImageUrl = imageUrl,
 | 
			
		||||
                        Link = link,
 | 
			
		||||
                        Score = score,
 | 
			
		||||
                        Status = status,
 | 
			
		||||
                        Title = title,
 | 
			
		||||
                    };
 | 
			
		||||
 | 
			
		||||
                    await _cache.SetNovelDataAsync(link,
 | 
			
		||||
                        JsonConvert.SerializeObject(obj)).ConfigureAwait(false);
 | 
			
		||||
 | 
			
		||||
                    return obj;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                return JsonConvert.DeserializeObject<MangaResult>(data);
 | 
			
		||||
                
 | 
			
		||||
                return JsonConvert.DeserializeObject<NovelResult>(data);
 | 
			
		||||
            }
 | 
			
		||||
            catch
 | 
			
		||||
            catch (Exception ex)
 | 
			
		||||
            {
 | 
			
		||||
                _log.Error(ex);
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user