Exemplo n.º 1
0
 public string GetImageUrl(NhentaiGallery gallery, NhImageType imageType, int page = 1)
 {
     if (imageType == NhImageType.Cover)
     {
         return($"{thumbnailCdn}/galleries/{gallery.Media_Id}/cover.{gallery.Images.Cover.ImageFormat}");
     }
     else
     {
         return($"{imageCdn}/galleries/{gallery.Media_Id}/{page}.{gallery.Images.Pages[page - 1].ImageFormat}");
     }
 }
Exemplo n.º 2
0
        public async Task <NhentaiGallery> GetRandomGalleryAsync()
        {
            var gallery = new NhentaiGallery();

            var htmlString = "";

            try
            {
                htmlString = await _httpClient.GetStringAsync("https://nhentai.net/random");
            }
            catch (HttpRequestException) { }

            var beginIndex = htmlString.LastIndexOf("JSON.parse(\"");
            var pass1      = htmlString.Substring(beginIndex, htmlString.Length - beginIndex);
            var endIndex   = pass1.LastIndexOf("\");");
            var pass2      = pass1.Substring(0, endIndex);

            var escaped    = Regex.Unescape(pass2);
            var jsonString = escaped.Substring(12, escaped.Length - 12);

            gallery = JsonConvert.DeserializeObject <NhentaiGallery>(jsonString);

            return(gallery);
        }
Exemplo n.º 3
0
        public Embed GetGalleryEmbed(NhentaiGallery gallery, SocketUser user)
        {
            EmbedBuilder galleryEmbedBuilder;

            if (gallery != null && gallery.Id > 0)
            {
                var languagesStringBuilder  = new StringBuilder();
                var parodiesStringBuilder   = new StringBuilder();
                var charactersStringBuilder = new StringBuilder();
                var tagsStringBuilder       = new StringBuilder();
                var artistsStringBuilder    = new StringBuilder();
                var groupsStringBuilder     = new StringBuilder();

                foreach (var tag in gallery.Tags)
                {
                    if (tag.TagType == TagType.Language)
                    {
                        languagesStringBuilder.Append($"`{tag.Name}` ");
                    }
                    else if (tag.TagType == TagType.Parody)
                    {
                        parodiesStringBuilder.Append($"`{tag.Name}` ");
                    }
                    else if (tag.TagType == TagType.Character)
                    {
                        charactersStringBuilder.Append($"`{tag.Name}` ");
                    }
                    else if (tag.TagType == TagType.Tag)
                    {
                        tagsStringBuilder.Append($"`{tag.Name}` ");
                    }
                    else if (tag.TagType == TagType.Artist)
                    {
                        artistsStringBuilder.Append($"`{tag.Name}` ");
                    }
                    else if (tag.TagType == TagType.Group)
                    {
                        groupsStringBuilder.Append($"`{tag.Name}` ");
                    }
                }

                var fields = new List <EmbedFieldBuilder>();

                if (languagesStringBuilder.Length > 0)
                {
                    fields.Add(new EmbedFieldBuilder()
                    {
                        Name  = "Languages",
                        Value = languagesStringBuilder.ToString()
                    });
                }
                if (parodiesStringBuilder.Length > 0)
                {
                    fields.Add(new EmbedFieldBuilder()
                    {
                        Name  = "Parodies",
                        Value = parodiesStringBuilder.ToString()
                    });
                }
                if (charactersStringBuilder.Length > 0)
                {
                    fields.Add(new EmbedFieldBuilder()
                    {
                        Name  = "Characters",
                        Value = charactersStringBuilder.ToString()
                    });
                }
                if (tagsStringBuilder.Length > 0)
                {
                    fields.Add(new EmbedFieldBuilder()
                    {
                        Name  = "Tags",
                        Value = tagsStringBuilder.ToString()
                    });
                }
                if (artistsStringBuilder.Length > 0)
                {
                    fields.Add(new EmbedFieldBuilder()
                    {
                        Name  = "Artists",
                        Value = artistsStringBuilder.ToString()
                    });
                }
                if (groupsStringBuilder.Length > 0)
                {
                    fields.Add(new EmbedFieldBuilder()
                    {
                        Name  = "Groups",
                        Value = groupsStringBuilder.ToString()
                    });
                }

                galleryEmbedBuilder = new EmbedBuilder()
                {
                    Author = new EmbedAuthorBuilder()
                    {
                        IconUrl = user.GetAvatarUrl(),
                        Name    = $"Requested by {user.Username}"
                    },
                    Title    = $"[{gallery.Id}] {gallery.Title.Pretty}",
                    Url      = $"http://nhentai.net/g/{gallery.Id}",
                    Fields   = fields,
                    ImageUrl = GetImageUrl(gallery, NhImageType.Cover),
                    Footer   = new EmbedFooterBuilder()
                    {
                        Text = $"{gallery.Num_Pages} pages"
                    }
                };
            }
            else
            {
                galleryEmbedBuilder = new EmbedBuilder()
                {
                    Author = new EmbedAuthorBuilder()
                    {
                        IconUrl = user.GetAvatarUrl(),
                        Name    = $"Requested by {user.Username}"
                    },

                    Description = "Gallery doesn't exist.",
                };
            }

            return(galleryEmbedBuilder.Build());
        }