public async Task DownloadThread(int nHentaiId, WinForms.FolderBrowserDialog folder)
        {
            Doujin doujin  = new Doujin(nHentaiId);
            string newName = doujin.name.Replace("/", "").Replace("?", "").Replace("%", "").Replace("*", "").Replace(":", "").Replace("|", "").Replace(".", "").Replace("<", "").Replace(">", "").Replace('"'.ToString(), "");

            if (!Directory.Exists($@"{folder.SelectedPath}/{newName}"))
            {
                using (WebClient client = new WebClient())
                {
                    int i      = 1;
                    var notify = Notifications.Notifications.CreateNotificationWPBarNImg("Download", $"{doujin.name} is being downloaded", $"{i} of {doujin.pageCount}", 1, doujin.pageCount);
                    notify.LayoutTransform = new RotateTransform(180);
                    var window = DoujinUtility.MainWindow;
                    window.notificationPanellul.Children.Add(notify);

                    foreach (string ext in DoujinUtility.GetPage(doujin))
                    {
                        Console.WriteLine($"https://i.nhentai.net/galleries/{doujin.mediaId}/{i}{ext}, {folder.SelectedPath}/{newName}/{i}{ext}");
                        Directory.CreateDirectory($@"{folder.SelectedPath}/{newName}");
                        await Task.Run(() => client.DownloadFile(new Uri("https://i.nhentai.net/galleries/" + doujin.mediaId + "/" + i + ext), $@"{folder.SelectedPath}/{newName}/{i}{ext}"));

                        notify.UpdateNotificationWBarNImg($"{i} of {doujin.pageCount}", i);
                        i++;
                    }

                    // OR
                }
            }
            else
            {
                Console.WriteLine("DAS GIBTS DOCH SCHON!!!!11!!elf");
            }
        }
Пример #2
0
        private void Heart_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Image         obj     = (Image)sender;
            Grid          grid    = (Grid)obj.Parent;
            DoujinControl control = (DoujinControl)grid.Parent;
            int           nhId    = (int)control.img.Tag;

            if (DoujinUtility.CheckFavorised(new Doujin(nhId)))
            {
                DatabaseControler.favorites.FindBynHentaiID(nhId).favorite = false;
                //DatabaseControler.mainDataTable.FindBynHentaiID(nhId).favorite = false;
                control.heart.Source = new BitmapImage(new Uri("pack://application:,,,/UiElements/heart_nofav.png"));
                DatabaseControler.favorites.RemoveDoujinDataRow(DatabaseControler.favorites.FindBynHentaiID(nhId));

                DatabaseControler.favorites.WriteXml(DatabaseControler.favDataPath);
            }
            else
            {
                Doujin doujin = new Doujin(nhId);
                //DatabaseControler.mainDataTable.FindBynHentaiID(nhId).favorite = true;
                control.heart.Source = new BitmapImage(new Uri("pack://application:,,,/UiElements/heart_fav.png"));
                DoujinUtility.AddDoujinDataRow(doujin, DatabaseControler.favorites);
                DatabaseControler.favorites.WriteXml(DatabaseControler.favDataPath);
                //.Add();

                var notify = Notifications.Notifications.NotificationNoImg(doujin.name, "", "The doujin got favorised and you can acess it at your favourite page");

                DoujinUtility.MainWindow.notificationPanellul.Children.Add(notify);
            }
        }
        public DoujinControl(int nhentaiId)
        {
            InitializeComponent();
            prevSize     = this.Height;
            tagsPrevSize = doujinTags.Height;
            gridPrevSize = infoGrid.Height;
            Doujin doujin = new Doujin(nhentaiId);

            this.nHentaiId = nhentaiId;



            //foreach (Database.DoujinSet.DoujinDataRow row in Database.DatabaseControler.favorites)
            //{
            if (DatabaseControler.favorites.Any(item => item.nHentaiID == doujin.nhentaiId))
            {
                //doujin = new Doujin(row.nHentaiID);
                doujin.favorised = true;

                Console.WriteLine("fav matched");
                heart.Source = new BitmapImage(new Uri("pack://application:,,,/UiElements/heart_fav.png"));
            }
            //}


            var source = new BitmapImage(new Uri(doujin.coverUrl));

            img.Source = source;
            double ratio = source.Width / source.Height;

            img.ToolTip              = doujin.name;
            img.Tag                  = doujin.nhentaiId;
            img.Width                = 160;
            img.Height               = 230;
            img.Margin               = new Thickness(5, 3, 5, 3);
            img.MouseLeftButtonDown += Img_MouseLeftButtonDown;
            //img.MouseRightButtonDown += Img_MouseRightButtonDown;
            heart.MouseLeftButtonDown += Heart_MouseLeftButtonDown;
            Thickness margin = Margin;

            margin.Right    = 10;
            margin.Bottom   = 10;
            Margin          = margin;
            doujinName.Text = doujin.name;
            foreach (var tag in doujin.tags)
            {
                DoujinUtility.MainWindow.tagList.Add(tag);
                Console.WriteLine(tag);
            }
            Console.WriteLine(doujin.TagsConcat());
            doujinCreator.Text = doujin.ArtistsConcat();
            doujinTags.Text    = doujin.TagsConcat();
            var testRow = DatabaseControler.doujinCache.NewRow();

            testRow[0] = nhentaiId;
            testRow[1] = true;

            bool contains = DatabaseControler.doujinCache.AsEnumerable().Any(row => nhentaiId == row.Field <Int32>("hentaiID"));
        }
Пример #4
0
        public AccountDoujinControl(int nhentaiId, string doujinrater, double rating, string comment)
        {
            InitializeComponent();
            prevSize     = this.Height;
            tagsPrevSize = doujinTags.Height;
            gridPrevSize = infoGrid.Height;
            Doujin doujin = new Doujin(nhentaiId);

            doujinRecomender.Text = doujinrater;
            doujinRatingText.Text = $"Rating: {rating}/5";
            doujinComment.Text    = comment;

            foreach (Database.DoujinSet.DoujinDataRow row in Database.DatabaseControler.favorites)
            {
                if (row.nHentaiID == doujin.nhentaiId)
                {
                    doujin           = new Doujin(row.nHentaiID);
                    doujin.favorised = true;

                    Console.WriteLine("fav matched");
                    heart.Source = new BitmapImage(new Uri("pack://application:,,,/UiElements/heart_fav.png"));
                }
            }


            var source = new BitmapImage(new Uri(doujin.coverUrl));

            img.Source = source;
            double ratio = source.Width / source.Height;

            img.ToolTip                = doujin.name;
            img.Tag                    = doujin.nhentaiId;
            img.Width                  = 160;
            img.Height                 = 230;
            img.Margin                 = new Thickness(5, 3, 5, 3);
            img.MouseLeftButtonDown   += Img_MouseLeftButtonDown;
            img.MouseRightButtonDown  += Img_MouseRightButtonDown;
            heart.MouseLeftButtonDown += Heart_MouseLeftButtonDown;
            Thickness margin = Margin;

            margin.Right       = 10;
            margin.Bottom      = 10;
            Margin             = margin;
            doujinName.Text    = doujin.name;
            doujinCreator.Text = doujin.ArtistsConcat();
            doujinTags.Text    = doujin.TagsConcat();
            var testRow = DatabaseControler.doujinCache.NewRow();

            testRow[0] = nhentaiId;
            testRow[1] = true;

            bool contains = DatabaseControler.doujinCache.AsEnumerable().Any(row => nhentaiId == row.Field <Int32>("hentaiID"));

            if (contains)
            {
                throw new Exception(nhentaiId.ToString());
            }
        }
        private void Img_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            var img = (Image)sender;

            using (var doujin = new Doujin((int)img.Tag))
            {
                var viewer = new DoujinViewer(doujin);
                viewer.Show();
            }
        }
Пример #6
0
 public DoujinViewer(Doujin doujin)
 {
     InitializeComponent();
     viewport.BeginInit();
     gDoujin = doujin;
     Load(doujin);
     viewport.EndInit();
     control.parent = this;
     //gDoujin.pageExt = DoujinUtility.GetPage(gDoujin);
 }
Пример #7
0
        public static string GetExtension(int doujinMediaID, Boolean cover, Doujin doujin)
        {
            string page = null;

            string[]        fileTypes = { ".jpg", ".png", ".gif" };
            HttpWebResponse response  = null;

            switch (cover)
            {
            case false:
                page = "5t";
                break;

            case true:
                page = "cover";
                break;
            }

            foreach (string type in fileTypes)
            {
                Console.WriteLine("testing ---> " + type);
                var request = WebRequest.Create("https://t.nhentai.net/galleries/" + doujinMediaID + "/" + page + type);
                try
                {
                    response = (HttpWebResponse)request.GetResponse();
                }
                catch
                {
                    Console.WriteLine("error ---> " + type);
                    continue;
                }

                switch (response.StatusCode)
                {
                case HttpStatusCode.OK:
                    Console.WriteLine("found ---> " + type);
                    doujin.thumbnailExt = type;
                    return(type);

                case HttpStatusCode.InternalServerError:
                    return(fileTypes[0]);

                case HttpStatusCode.NotFound:
                    return(fileTypes[0]);

                case HttpStatusCode.Forbidden:
                    return(fileTypes[0]);

                case HttpStatusCode.RequestTimeout:
                    return(fileTypes[0]);
                }
            }
            return(null);
        }
        private void Heart_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            Image         obj     = (Image)sender;
            Grid          grid    = (Grid)obj.Parent;
            DoujinControl control = (DoujinControl)grid.Parent;
            int           nhId    = (int)control.img.Tag;

            if (DoujinUtility.CheckFavorised(new Doujin(nhId)))
            {
                DatabaseControler.favorites.FindBynHentaiID(nhId).favorite = false;
                //DatabaseControler.mainDataTable.FindBynHentaiID(nhId).favorite = false;
                control.heart.Source = new BitmapImage(new Uri("pack://application:,,,/UiElements/heart_nofav.png"));
                DatabaseControler.favorites.RemoveDoujinDataRow(DatabaseControler.favorites.FindBynHentaiID(nhId));

                DatabaseControler.favorites.WriteXml(DatabaseControler.favDataPath);
            }
            else
            {
                Doujin doujin = new Doujin(nhId);
                //DatabaseControler.mainDataTable.FindBynHentaiID(nhId).favorite = true;
                control.heart.Source = new BitmapImage(new Uri("pack://application:,,,/UiElements/heart_fav.png"));
                DoujinUtility.AddDoujinDataRow(doujin, DatabaseControler.favorites);
                DatabaseControler.favorites.WriteXml(DatabaseControler.favDataPath);
                //.Add();

                var notify = Notifications.Notifications.NotificationNoImg(doujin.name, "", "The doujin got favorised and you can acess it at your favourite page");

                DoujinUtility.MainWindow.notificationPanellul.Children.Add(notify);
                try
                {
                    if (DoujinUtility.MainWindow.accountElement.loggedIn)
                    {
                        DoujinUtility.MainWindow.accountElement.apiHelper.PostFavorite(nhId);
                    }
                    else
                    {
                        DoujinUtility.MainWindow.accountElement.apiHelper.user = Newtonsoft.Json.JsonConvert.DeserializeObject <Doujin_Interface.Connection.Models.AuthenticatedUser>(Doujin_Interface.Properties.Settings.Default.User);
                        DoujinUtility.MainWindow.accountElement.apiHelper.PostFavorite(nhId);
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Пример #9
0
        public static List <string> GetPage(Doujin doujin)
        {
            var request = WebRequest.Create("https://nhentai.net/api/gallery/" + doujin.nhentaiId);

            Console.WriteLine(doujin.nhentaiId);
            string text;
            var    response = (HttpWebResponse)request.GetResponse();

            using (var sr = new StreamReader(response.GetResponseStream()))
            {
                text = sr.ReadToEnd();
            }
            XNode       node = JsonConvert.DeserializeXNode(text, "Root");
            XmlDocument doc  = new XmlDocument();

            doc.LoadXml(node.ToString());
            doc.Save("test.xml");
            List <string> extensions = new List <string>();
            XElement      table      = XElement.Parse(node.ToString());

            foreach (XElement element in table.Elements())
            {
                if (element.Name == "images")
                {
                    foreach (var pages in element.Elements())
                    {
                        if (pages.Name == "pages")
                        {
                            foreach (var t in pages.Elements())
                            {
                                if (t.Value == "j")
                                {
                                    extensions.Add(".jpg");
                                }
                                else if (t.Value == "p")
                                {
                                    extensions.Add(".png");
                                }
                            }
                        }
                    }
                }
            }
            Console.WriteLine("REEEEEEEEEEEEEEEEEEEEEEEEE " + extensions.Count);
            return(extensions);
        }
Пример #10
0
 public static bool DoujinIsPartOfDataTable(Doujin doujin, DoujinDataDataTable dt)
 {
     try
     {
         if (dt.Contains(dt.FindBynHentaiID(doujin.nhentaiId)))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
Пример #11
0
 public static bool CheckFavorised(Doujin doujin)
 {
     try
     {
         if (Database.DatabaseControler.favorites.Contains(Database.DatabaseControler.favorites.FindBynHentaiID(doujin.nhentaiId)))
         {
             return(true);
         }
         else
         {
             return(false);
         }
     }
     catch
     {
         return(false);
     }
 }
Пример #12
0
        //viewport
        public void Load(Doujin doujin)
        {
            for (int i = 1; i < doujin.pageCount; i++)
            {
                //WebClient webClient = new WebClient();
                //webClient.DownloadFile(new Uri("https://i.nhentai.net/galleries/" + gDoujin.mediaId + "/" + i +gDoujin.pageExt.ElementAt(i-1)), i + gDoujin.pageExt.ElementAt(i-1));
                if (doujin.thumbnailExt == null)
                {
                    Console.WriteLine(i);
                    Image img = new Image();


                    img.Source = new BitmapImage(new Uri("https://t.nhentai.net/galleries/" + doujin.mediaId + "/" + i + "t" + DoujinUtility.GetExtension(doujin.mediaId, false, doujin)));

                    img.Width  = 162;
                    img.Height = 231;
                    img.Margin = new Thickness(5, 3, 5, 3);

                    viewport.Children.Add(img);
                    images.Add(img);
                }
                else
                {
                    Console.WriteLine(i);
                    Image img = new Image();
                    viewport.Children.Add(img);


                    img.Source = new BitmapImage(new Uri("https://t.nhentai.net/galleries/" + doujin.mediaId + "/" + i + "t" + doujin.pageExt.ElementAt(i - 1)));

                    img.Width  = 250;
                    img.Height = 347;
                    img.Margin = new Thickness(5, 3, 5, 3);
                    img.MouseLeftButtonDown += Img_MouseLeftButtonDown;
                    images.Add(img);
                    Console.WriteLine(img.Source);
                }
                Console.WriteLine("pages=" + doujin.pageCount + ", entires=" + images.Count);
                pageNumberText.Text = $"Pages: {gDoujin.pageCount}";
            }
        }
Пример #13
0
        public static void AddDoujinDataRow(Doujin d, DoujinDataDataTable dt)
        {
            DoujinDataRow rowDoujinDataRow = ((DoujinDataRow)(dt.NewRow()));

            object[] columnValuesArray = new object[] {
                dt.Rows.Count,
                d.nhentaiId,
                d.mediaId,
                d.name,
                d.fullName,
                d.Artist(),
                d.Character(),
                d.Parody(),
                d.Group(),
                d.TagsConcat(),
                d.language,
                d.favorised,
                d.pageCount,
                d.coverUrl,
                d.coverExt
            };
            rowDoujinDataRow.ItemArray = columnValuesArray;
            dt.Rows.Add(rowDoujinDataRow);
        }
        public DetailsWindow(Doujin doujin)
        {
            InitializeComponent();
            titel.Content = doujin.name;
            cover.Source  = new BitmapImage(new Uri(doujin.coverUrl));

            TreeViewItem ids = new TreeViewItem();

            ids.Header     = "IDs";
            ids.Foreground = Brushes.White;
            Tags.Items.Add(ids);

            TreeViewItem id = new TreeViewItem();

            id.Header     = "local DB ID: " + doujin.id;
            id.Foreground = Brushes.White;
            ids.Items.Add(id);

            TreeViewItem nId = new TreeViewItem();

            nId.Header     = "nHentai ID: " + doujin.nhentaiId;
            nId.Foreground = Brushes.White;
            ids.Items.Add(nId);

            TreeViewItem mediaId = new TreeViewItem();

            mediaId.Header     = "Media ID: " + doujin.mediaId;
            mediaId.Foreground = Brushes.White;
            ids.Items.Add(mediaId);

            TreeViewItem names = new TreeViewItem();

            names.Header     = "Names";
            names.Foreground = Brushes.White;
            Tags.Items.Add(names);

            TreeViewItem prettyName = new TreeViewItem();

            prettyName.Header     = "Pretty Name: " + doujin.name;
            prettyName.Foreground = Brushes.White;
            names.Items.Add(prettyName);

            TreeViewItem fullName = new TreeViewItem();

            fullName.Header     = "Full Name: " + doujin.fullName;
            fullName.Foreground = Brushes.White;
            names.Items.Add(fullName);

            if (doujin.Artist() == null)
            {
                TreeViewItem artists = new TreeViewItem();
                artists.Header     = "Artists";
                artists.Foreground = Brushes.White;
                Tags.Items.Add(artists);

                foreach (string art in doujin.artists)
                {
                    TreeViewItem artist = new TreeViewItem();
                    artist.Header     = art;
                    artist.Foreground = Brushes.White;
                    artists.Items.Add(artist);
                }
            }
            else
            {
                TreeViewItem artist = new TreeViewItem();
                artist.Header     = "Artist: " + doujin.Artist();
                artist.Foreground = Brushes.White;
                Tags.Items.Add(artist);
            }

            if (doujin.Character() == null)
            {
                TreeViewItem top = new TreeViewItem();
                top.Header     = "Characters";
                top.Foreground = Brushes.White;
                Tags.Items.Add(top);

                foreach (string selec in doujin.character)
                {
                    TreeViewItem child = new TreeViewItem();
                    child.Header     = selec;
                    child.Foreground = Brushes.White;
                    top.Items.Add(child);
                }
            }
            else
            {
                TreeViewItem item = new TreeViewItem();
                item.Header     = "Character: " + doujin.Character();
                item.Foreground = Brushes.White;
                Tags.Items.Add(item);
            }

            if (doujin.Parody() == null)
            {
                TreeViewItem top = new TreeViewItem();
                top.Header     = "Parodys";
                top.Foreground = Brushes.White;
                Tags.Items.Add(top);

                foreach (string selec in doujin.parodys)
                {
                    TreeViewItem child = new TreeViewItem();
                    child.Header     = selec;
                    child.Foreground = Brushes.White;
                    top.Items.Add(child);
                }
            }
            else
            {
                TreeViewItem item = new TreeViewItem();
                item.Header     = "Parody: " + doujin.Parody();
                item.Foreground = Brushes.White;
                Tags.Items.Add(item);
            }

            if (doujin.Group() == null)
            {
                TreeViewItem top = new TreeViewItem();
                top.Header     = "Groups";
                top.Foreground = Brushes.White;
                Tags.Items.Add(top);

                foreach (string selec in doujin.group)
                {
                    TreeViewItem child = new TreeViewItem();
                    child.Header     = selec;
                    child.Foreground = Brushes.White;
                    top.Items.Add(child);
                }
            }
            else
            {
                TreeViewItem item = new TreeViewItem();
                item.Header     = "Group: " + doujin.Group();
                item.Foreground = Brushes.White;
                Tags.Items.Add(item);
            }

            TreeViewItem tag = new TreeViewItem();

            tag.Header     = "Tags:";
            tag.Foreground = Brushes.White;
            Tags.Items.Add(tag);
            foreach (string selec in doujin.tags)
            {
                TreeViewItem child = new TreeViewItem();
                child.Header     = selec;
                child.Foreground = Brushes.White;
                tag.Items.Add(child);
            }

            TreeViewItem lang = new TreeViewItem();

            lang.Header     = $"Language: {doujin.language}";
            lang.Foreground = Brushes.White;
            Tags.Items.Add(lang);
        }
Пример #15
0
 public static void FavoriteSave(Doujin doujin)
 {
     doujin.favorised = true;
     Console.WriteLine("Doujin: " + doujin.fullName + " (" + doujin.id + ") " + "got favorised");
 }
Пример #16
0
 public static void SaveDoujin(Doujin doujin)
 {
     System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(@"");
 }
        public DoujinControl(Doujin doujin)
        {
            InitializeComponent();
            prevSize       = this.Height;
            tagsPrevSize   = doujinTags.Height;
            gridPrevSize   = infoGrid.Height;
            this.nHentaiId = doujin.nhentaiId;



            if (DatabaseControler.favorites.Any(item => item.nHentaiID == doujin.nhentaiId))
            {
                //doujin = new Doujin(row.nHentaiID);
                doujin.favorised = true;

                Console.WriteLine("fav matched");
                heart.Source = new BitmapImage(new Uri("pack://application:,,,/UiElements/heart_fav.png"));
            }

            var cm    = new ContextMenu();
            var mitem = new MenuItem {
                Header = "Recommend to"
            };

            cm.Items.Add(mitem);

            if (DoujinUtility.loggedIn)
            {
                foreach (var friend in DoujinUtility.MainWindow.accountElement.apiHelper.GetFriends().Result.Friends)
                {
                    mitem.Items.Add(new MenuItem {
                        Header = friend
                    });
                }
            }
            else
            {
                mitem.Items.Add(new MenuItem {
                    Header = "You have to be logged in to use this feature"
                });
            }
            this.cm = cm;



            var source = new BitmapImage(new Uri(doujin.coverUrl));

            img.Source = source;
            double ratio = source.Width / source.Height;

            img.ToolTip                = doujin.name;
            img.Tag                    = (int)doujin.nhentaiId;
            img.Width                  = 160;
            img.Height                 = 230;
            img.Margin                 = new Thickness(5, 3, 5, 3);
            img.MouseLeftButtonDown   += Img_MouseLeftButtonDown;
            img.MouseRightButtonDown  += Img_MouseRightButtonDown;
            heart.MouseLeftButtonDown += Heart_MouseLeftButtonDown;
            Thickness margin = Margin;

            margin.Right       = 10;
            margin.Bottom      = 10;
            Margin             = margin;
            doujinName.Text    = doujin.name;
            doujinCreator.Text = doujin.ArtistsConcat();
            foreach (var tag in doujin.tags)
            {
                DoujinUtility.MainWindow.tagList.Add(tag);
                Console.WriteLine(tag);
            }
            Console.WriteLine(doujin.tags);
            doujinTags.Text = string.Join(", ", doujin.tags);
            Tag             = doujin.nhentaiId.ToString();


            bool contains = DatabaseControler.doujinCache.AsEnumerable().Any(row => doujin.nhentaiId == row.Field <Int32>("hentaiID"));

            if (contains)
            {
                img.Opacity = 0.3;
            }
        }
Пример #18
0
        //Outdated
        public static Result OutdatedSearch(string search, string tagsIn, string artistIn, string characterIn, string parodyIn, Boolean popOrder, string lang, int page)
        {
            string        query     = "";
            string        url       = "https://nhentai.net/api/galleries/search?query=";
            List <Doujin> doujinshi = new List <Doujin>();
            List <System.Windows.Controls.Image> images = new List <Image>();
            Result result = new Result();

            if (search != "")
            {
                query += search + "+";
            }
            if (tagsIn != "")
            {
                if (tagsIn.Contains(","))
                {
                    foreach (string str in tagsIn.Split(','))
                    {
                        query += ("tag%3A\"" + str + "\"+");
                    }
                }
                else
                {
                    query += ("tag%3A\"" + tagsIn + "\"+");
                }
            }
            if (artistIn != "")
            {
                if (artistIn.Contains(","))
                {
                    foreach (string str in artistIn.Split(','))
                    {
                        query += ("artist%3A\"" + str + "\"+");
                    }
                }
                else
                {
                    query += ("artist%3A\"" + artistIn + "\"+");
                }
            }
            if (characterIn != "")
            {
                if (characterIn.Contains(","))
                {
                    foreach (string str in characterIn.Split(','))
                    {
                        query += ("character%3A\"" + str + "\"+");
                    }
                }
                else
                {
                    query += ("character%3A\"" + characterIn + "\"+");
                }
            }
            if (parodyIn != "")
            {
                if (parodyIn.Contains(","))
                {
                    foreach (string str in characterIn.Split(','))
                    {
                        query += ("parody%3A\"" + str + "\"+");
                    }
                }
                else
                {
                    query += ("parody%3A\"" + parodyIn + "\"+");
                }
            }
            query += lang;
            if (popOrder)
            {
                query += "&order=popular";
            }
            query += "&page=" + page;
            Console.WriteLine(url + query);
            var request = WebRequest.Create("https://nhentai.net/api/galleries/search?query=" + query);

            request.ContentType = "application/xml; charset=utf-8";
            string text;
            var    response = (HttpWebResponse)request.GetResponse();

            using (var sr = new StreamReader(response.GetResponseStream()))
            {
                text = sr.ReadToEnd();
            }
            XNode       node = JsonConvert.DeserializeXNode(text, "Root");
            XmlDocument doc  = new XmlDocument();

            doc.LoadXml(node.ToString());
            //doc.Save(artistIn + ".xml");
            int id = 0;

            XElement table = XElement.Parse(node.ToString());

            foreach (XElement element in table.Elements())
            {
                if (element.Name == "result")
                {
                    Doujin doujin = new Doujin();
                    doujinshi.Add(doujin);
                    string extension = "";
                    foreach (var title in element.Elements())
                    {
                        if (title.Name == "id")
                        {
                            id = int.Parse(title.Value);
                            doujin.nhentaiId = id;
                            Console.WriteLine($"current id is {id}");
                        }
                        if (title.Name == "media_id")
                        {
                            doujin.mediaId = int.Parse(title.Value);
                            //Image img = new Image();
                            //images.Add(img);
                            //Console.WriteLine("extension is " + extension);
                            //doujin.coverExt = extension;
                            doujin.coverUrl = "https://t.nhentai.net/galleries/" + title.Value + "/1t";
                        }
                        if (title.Name == "images")
                        {
                            foreach (var pages in title.Elements())
                            {
                                if (pages.Name == "thumbnail")
                                {
                                    foreach (var t in pages.Elements())
                                    {
                                        if (t.Value == "j")
                                        {
                                            Console.WriteLine(".jpg");
                                            extension           = ".jpg";
                                            doujin.coverExt     = ".jpg";
                                            doujin.thumbnailExt = ".jpg";
                                        }
                                        else if (t.Value == "p")
                                        {
                                            Console.WriteLine(".png");
                                            extension           = ".png";
                                            doujin.coverExt     = ".png";
                                            doujin.thumbnailExt = ".png";
                                        }
                                    }
                                    doujin.coverUrl = "https://t.nhentai.net/galleries/" + doujin.mediaId + "/1t" + extension;
                                }
                            }
                        }
                        if (title.Name == "tags")
                        {
                            foreach (var tag in title.Elements())
                            {
                                if (tag.Name == "url")
                                {
                                    string[] split = tag.Value.Split('/');

                                    if (split[1] == "tag")
                                    {
                                        doujin.tags.Add(split[2]);
                                    }
                                    else if (split[1] == "group")
                                    {
                                        doujin.group.Add(split[2]);
                                    }
                                    else if (split[1] == "artist")
                                    {
                                        doujin.artists.Add(split[2]);
                                    }
                                    else if (split[1] == "character")
                                    {
                                        doujin.character.Add(split[2]);
                                    }
                                    else if (split[1] == "language" && split[2] == "translated")
                                    {
                                        doujin.translated = true;
                                    }
                                    else if (split[1] == "language")
                                    {
                                        doujin.language = split[2];
                                    }
                                    else if (split[1] == "parody")
                                    {
                                        doujin.parodys.Add(split[2]);
                                    }
                                }
                            }
                        }


                        if (title.Name == "title")
                        {
                            foreach (var pretty in title.Elements())
                            {
                                if (pretty.Name == "pretty")
                                {
                                    Console.WriteLine(pretty.Value);
                                    doujin.name = pretty.Value;
                                }
                                if (pretty.Name == "english")
                                {
                                    doujin.fullName = pretty.Value;
                                }
                            }
                        }
                        if (title.Name == "num_pages")
                        {
                            doujin.pageCount = int.Parse(title.Value);
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                else
                {
                    continue;
                }
            }

            result.images    = images;
            result.doujinshi = doujinshi;
            query            = "";
            return(result);
        }
Пример #19
0
        public static Result Search(string search, string tagsIn, string artistIn, string characterIn, string parodyIn, Boolean popOrder, string lang, int page)
        {
            string        query     = "";
            string        url       = "https://nhentai.net/api/galleries/search?query=";
            List <Doujin> doujinshi = new List <Doujin>();
            List <System.Windows.Controls.Image> images = new List <Image>();
            Result result = new Result();

            if (search != "")
            {
                query += search + "+";
            }
            if (tagsIn != "")
            {
                if (tagsIn.Contains(","))
                {
                    foreach (string str in tagsIn.Split(','))
                    {
                        query += ("tag%3A\"" + str + "\"+");
                    }
                }
                else
                {
                    query += ("tag%3A\"" + tagsIn + "\"+");
                }
            }
            if (artistIn != "")
            {
                if (artistIn.Contains(","))
                {
                    foreach (string str in artistIn.Split(','))
                    {
                        query += ("artist%3A\"" + str + "\"+");
                    }
                }
                else
                {
                    query += ("artist%3A\"" + artistIn + "\"+");
                }
            }
            if (characterIn != "")
            {
                if (characterIn.Contains(","))
                {
                    foreach (string str in characterIn.Split(','))
                    {
                        query += ("character%3A\"" + str + "\"+");
                    }
                }
                else
                {
                    query += ("character%3A\"" + characterIn + "\"+");
                }
            }
            if (parodyIn != "")
            {
                if (parodyIn.Contains(","))
                {
                    foreach (string str in characterIn.Split(','))
                    {
                        query += ("parody%3A\"" + str + "\"+");
                    }
                }
                else
                {
                    query += ("parody%3A\"" + parodyIn + "\"+");
                }
            }
            query += lang;
            if (popOrder)
            {
                query += "&order=popular";
            }
            query += "&page=" + page;
            Console.WriteLine(url + query);
            var request = WebRequest.Create("https://nhentai.net/api/galleries/search?query=" + query);

            request.ContentType = "application/xml; charset=utf-8";
            string text;
            var    response = (HttpWebResponse)request.GetResponse();

            using (var sr = new StreamReader(response.GetResponseStream()))
            {
                text = sr.ReadToEnd();
            }
            var searchResult = JsonConvert.DeserializeObject <DoujinSearchResult>(text);

            foreach (var item in searchResult.Result)
            {
                var doujin = new Doujin
                {
                    fullName  = item.Title.English,
                    name      = item.Title.Pretty,
                    id        = item.Id,
                    mediaId   = int.Parse(item.Media_id),
                    pageCount = item.Num_pages,
                };
                foreach (var doujinImages in item.Images)
                {
                    switch (doujinImages.Cover.T)
                    {
                    case "j":
                        doujin.coverExt = ".jpg";
                        break;

                    case "p":
                        doujin.coverExt = ".png";
                        break;

                    case "g":
                        doujin.coverExt = ".gif";
                        break;
                    }
                    switch (doujinImages.Thumbnail.T)
                    {
                    case "j":
                        doujin.thumbnailExt = ".jpg";
                        break;

                    case "p":
                        doujin.thumbnailExt = ".png";
                        break;

                    case "g":
                        doujin.thumbnailExt = ".gif";
                        break;
                    }
                    foreach (var pages in doujinImages.Pages)
                    {
                        switch (pages.T)
                        {
                        case "j":
                            doujin.pageExt.Add(".jpg");
                            break;

                        case "p":
                            doujin.pageExt.Add(".png");
                            break;

                        case "g":
                            doujin.pageExt.Add(".gif");
                            break;
                        }
                    }
                }
                foreach (var tags in item.Tags)
                {
                    switch (tags.Type)
                    {
                    case "artist":
                        doujin.artists.Add(tags.Name);
                        break;

                    case "group":
                        doujin.group.Add(tags.Name);
                        break;

                    case "language":
                        doujin.language = tags.Name;
                        break;

                    case "parody":
                        doujin.parodys.Add(tags.Name);
                        break;

                    case "character":
                        doujin.character.Add(tags.Name);
                        break;

                    case "tag":
                        doujin.tags.Add(tags.Name);
                        break;
                    }
                }
                doujin.coverUrl = "https://t.nhentai.net/galleries/" + doujin.mediaId + "/1t" + doujin.coverExt;
                doujinshi.Add(doujin);
            }

            result.images    = images;
            result.doujinshi = doujinshi;
            query            = "";
            return(result);
        }
Пример #20
0
        public Doujin(int nhIDin)
        {
Retry:
            //this.id = Database.DatabaseControler.mainDataTable.FindBynHentaiID(nhIDin).ID;
            var request = WebRequest.Create("https://nhentai.net/api/gallery/" + nhIDin);

            Console.WriteLine($"https://nhentai.net/api/gallery/{nhIDin}");
            string          text;
            HttpWebResponse response = null;

            try { response = (HttpWebResponse)request.GetResponse(); }
            catch
            {
                System.Threading.Thread.Sleep(100);
                goto Retry;
            };

            using (var sr = new StreamReader(response.GetResponseStream()))
            {
                text = sr.ReadToEnd();
            }
            XNode       node = JsonConvert.DeserializeXNode(text, "Root");
            XmlDocument doc  = new XmlDocument();

            doc.LoadXml(node.ToString());
            //doc.Save(artistIn + ".xml");
            int id = 0;

            XElement table = XElement.Parse(node.ToString());

            foreach (XElement title in table.Elements())
            {
                Doujin doujin    = this;
                string extension = "";
                if (title.Name == "id")
                {
                    id             = int.Parse(title.Value);
                    this.nhentaiId = id;
                }
                if (title.Name == "media_id")
                {
                    doujin.mediaId = int.Parse(title.Value);

                    doujin.coverUrl = "https://t.nhentai.net/galleries/" + title.Value + "/1t";
                }
                if (title.Name == "images")
                {
                    foreach (var pages in title.Elements())
                    {
                        if (pages.Name == "pages")
                        {
                            foreach (var t in pages.Elements())
                            {
                                if (t.Value == "j")
                                {
                                    doujin.pageExt.Add(".jpg");
                                }
                                else if (t.Value == "p")
                                {
                                    doujin.pageExt.Add(".png");
                                }
                            }
                        }
                    }


                    foreach (var pages in title.Elements())
                    {
                        if (pages.Name == "thumbnail")
                        {
                            foreach (var t in pages.Elements())
                            {
                                if (t.Value == "j")
                                {
                                    Console.WriteLine(".jpg");
                                    extension           = ".jpg";
                                    doujin.coverExt     = ".jpg";
                                    doujin.thumbnailExt = ".jpg";
                                }
                                else if (t.Value == "p")
                                {
                                    Console.WriteLine(".png");
                                    extension           = ".png";
                                    doujin.coverExt     = ".png";
                                    doujin.thumbnailExt = ".png";
                                }
                            }
                            doujin.coverUrl = "https://t.nhentai.net/galleries/" + doujin.mediaId + "/1t" + extension;
                        }
                    }
                }
                if (title.Name == "tags")
                {
                    foreach (var tag in title.Elements())
                    {
                        if (tag.Name == "url")
                        {
                            string[] split = tag.Value.Split('/');

                            if (split[1] == "tag")
                            {
                                doujin.tags.Add(split[2]);
                            }
                            else if (split[1] == "group")
                            {
                                doujin.group.Add(split[2]);
                            }
                            else if (split[1] == "artist")
                            {
                                doujin.artists.Add(split[2]);
                            }
                            else if (split[1] == "character")
                            {
                                doujin.character.Add(split[2]);
                            }
                            else if (split[1] == "language" && split[2] == "translated")
                            {
                                doujin.translated = true;
                            }
                            else if (split[1] == "language")
                            {
                                doujin.language = split[2];
                            }
                            else if (split[1] == "parody")
                            {
                                doujin.parodys.Add(split[2]);
                            }
                        }
                    }
                }


                if (title.Name == "title")
                {
                    foreach (var pretty in title.Elements())
                    {
                        if (pretty.Name == "pretty")
                        {
                            Console.WriteLine(pretty.Value);
                            doujin.name = pretty.Value;
                        }
                        if (pretty.Name == "english")
                        {
                            doujin.fullName = pretty.Value;
                        }
                    }
                }
                if (title.Name == "num_pages")
                {
                    doujin.pageCount = int.Parse(title.Value);
                }
                else
                {
                    continue;
                }
            }
        }