Пример #1
0
        // Static Members
        private static string[] getImageNumbs(int galleryId)
        {
            HttpWebRequest wreq = RequestHelper.CreateRequest(DownloadOptions.GalleryImageUrlsSubdomain, $"/galleries/{galleryId}.js");
            string         responseText;
            List <string>  urls = new List <string>();

            // request
            using (Stream str = wreq.GetResponse().GetResponseStream())
                using (StreamReader sr = new StreamReader(str))
                    responseText = sr.ReadToEnd();
            // cut
            responseText = responseText.Substring("var galleryinfo = ".Length);
            // parse
            JArray arr = JArray.Parse(responseText);

            return(JArray.Parse(responseText).Select(obj => obj["name"].ToString()).ToArray());
        }
Пример #2
0
 private void init(object _galleries)
 {
     InitializationStarted();
     lock (suggestions)
     {
         Gallery[] galleries = (Gallery[])_galleries;
         suggestions.Clear();
         foreach (string prop in getNamespaces(true, true))
         {
             suggestions[prop]  = new HashSet <string>();
             sortRankings[prop] = new Dictionary <string, int>();
         }
         HttpWebRequest wreq = RequestHelper.CreateRequest("", "/tags.json");
         HitomiTags     tagAutocompleteList = null;
         using (WebResponse wres = wreq.GetResponse())
             using (Stream str = wres.GetResponseStream())
                 using (StreamReader sre = new StreamReader(str))
                     using (JsonReader reader = new JsonTextReader(sre))
                     {
                         JsonSerializer serializer = new JsonSerializer();
                         tagAutocompleteList = serializer.Deserialize <HitomiTags>(reader);
                     }
         foreach (string ns in getNamespaces(true, false))
         {
             HitomiTagInfo[] tagInfos = (HitomiTagInfo[])(typeof(HitomiTags).GetProperty(ns).GetValue(tagAutocompleteList));
             foreach (HitomiTagInfo tagInfo in tagInfos)
             {
                 string text = tagInfo.Text.Trim().Replace(' ', '_');
                 suggestions[ns].Add(text);
                 sortRankings[ns].Add(text, tagInfo.Count);
             }
         }
         foreach (Gallery gallery in galleries)
         {
             suggestions["type"].Add(gallery.Type);
             suggestions["name"].Add(gallery.Name);
         }
         inited = true;
     }
     InitializaitonCompleted();
 }
Пример #3
0
 public Stream CreateThumbnailStream(int index)
 => RequestHelper.CreateRequest(getThumbnailUrls()[index]).GetResponse().GetResponseStream();
Пример #4
0
        public bool TryParse(int id, out Gallery parsedGallery)
        {
            HtmlDocument htmlDocument    = new HtmlDocument();
            Gallery      gallery         = new LibHitomi.Gallery(GalleryCrawlMethod.ParsedGalleryBlock);
            Regex        pattern         = new Regex("^/([a-zA-Z]+)/(.+)-all-1\\.html$", RegexOptions.Compiled | RegexOptions.IgnoreCase);
            Regex        languagePattern = new Regex("^/index-([a-zA-Z]+)-1\\.html$", RegexOptions.Compiled | RegexOptions.IgnoreCase);

            gallery.UnNull();
            gallery.id = id;

            htmlDocument.OptionDefaultStreamEncoding = System.Text.Encoding.UTF8;
            HttpWebRequest wreq = RequestHelper.CreateRequest(DownloadOptions.GalleryBlockSubdomain, $"/galleryblock/{id}.html");

            try
            {
                using (WebResponse wres = wreq.GetResponse())
                    using (Stream str = wres.GetResponseStream())
                        htmlDocument.Load(str);

                gallery.name = htmlDocument.DocumentNode.SelectSingleNode(".//h1").InnerText;
                List <string> artistsList = new List <string>(), parodiesList = new List <string>(), tagsList = new List <string>(), groupsList = new List <string>(), charactersList = new List <string>();
                foreach (HtmlNode linkNode in htmlDocument.DocumentNode.SelectNodes(".//a[ @href ]"))
                {
                    string href = linkNode.GetAttributeValue("href", "");
                    bool   isLanguageHref = languagePattern.IsMatch(href), isNormalHref = pattern.IsMatch(href);
                    if (isLanguageHref)
                    {
                        Match match = languagePattern.Match(href);
                        // 제목이 없는 좆같은 경우는 봤지만(씨발) 언어가 두개인 좆같은 경우는 보지 못했음. json 형식도 한개라는 가정하에 만들어졌기도 하고.
                        gallery.language = match.Groups[1].Value;
                    }
                    else if (isNormalHref)
                    {
                        Match  match    = pattern.Match(href);
                        string propName = namespaceMap[match.Groups[1].Value].ToLower();
                        string value    = Uri.UnescapeDataString(match.Groups[2].Value).ToLower();

                        if (propName == "artists")
                        {
                            artistsList.Add(value);
                        }
                        else if (propName == "parodies")
                        {
                            parodiesList.Add(value);
                        }
                        else if (propName == "tags")
                        {
                            tagsList.Add(value);
                        }
                        else if (propName == "groups")
                        {
                            groupsList.Add(value);
                        }
                        else if (propName == "characters")
                        {
                            charactersList.Add(value);
                        }
                        else if (propName == "type")
                        {
                            gallery.type = value;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
                gallery.artists    = artistsList.ToArray();
                gallery.parodies   = parodiesList.ToArray();
                gallery.tags       = tagsList.ToArray();
                gallery.groups     = groupsList.ToArray();
                gallery.characters = charactersList.ToArray();
                parsedGallery      = gallery;
                return(true);
            }
            catch (WebException ex)
            {
                // catch 404
                if ((ex.Response as HttpWebResponse).StatusCode == HttpStatusCode.NotFound)
                {
                    parsedGallery = null;
                    return(false);
                }
                else
                {
                    throw ex;
                }
            }
        }