コード例 #1
0
        private async void Search_Click(object sender, EventArgs e)
        {
            output.Text = "Searching...";
            DerpiObject.Rootobject   results  = Helper.deserializeJSON(await Helper.Derpibooru(rating(Input.Text, 1, GetSort())));
            List <DerpiObject.Image> searches = new List <DerpiObject.Image>();

            searches.AddRange(results.images.ToList());
            Random rand = new Random();


            label1.Text = $"Total Results: {results.total.ToString()}";
            if (results.total == 0)
            {
                output.Text = "No results! Either your tags are misspelled or no images match your search.";
            }
            else
            {
                DerpiObject.Image chosenImage = searches.ElementAt(rand.Next(searches.Count));
                var    displayImage           = String.Join(", ", chosenImage.tags);
                string cleanLink = $"https://derpicdn.net/img/view/{chosenImage.created_at.Date.ToString("yyyy/M/d")}/{chosenImage.id}.{chosenImage.format.ToLower()}";
                pictureBox1.Load($"{chosenImage.view_url}");
                richTextBox1.Text = cleanLink;
                output.Text       = displayImage;
            }
        }
コード例 #2
0
        private async void download_ClickAsync(object sender, EventArgs e)
        {
            string location = "no path";

            output.Text = "Beginning...";
            DerpiObject.Rootobject   response = Helper.deserializeJSON(await Helper.Derpibooru(rating(Input.Text, 1, GetSort())));
            List <DerpiObject.Image> searches = new List <DerpiObject.Image>();
            int num_pages = response.total / 50;

            if (response.total % 50 > 0)
            {
                num_pages++;
            }
            int u = 0;

            if (response.total == 0)
            {
                output.Text = "Nothing to download!";
            }
            else
            {
                folderBrowserDialog1.ShowDialog();
                location = folderBrowserDialog1.SelectedPath;

                if (location == "")
                {
                    output.Text = "No download location selected! Try again!";
                    return;
                }
                //this prepares the file for writing the data of each image, it appends to the file after every download,
                //so that closing the program will not lose any data.
                //check if the checkbox is checked, only write to doc if it is
                bool   writeInfoToTXT = infoCheckBox.Checked;
                string infoText       = $"DerpiGUI was made by @HoovierSparkle on Twitter! Thanks for using my work!\nQuery: {Input.Text}\nTotal Images: {response.total}\n" +
                                        $"Sorting:{GetSort()}\n\nFilename - ImageID - Artist(s) - Tags\n";
                string infoTextAddress = location + $@"\{filename.Text.Trim('*')}Info.txt";
                File.WriteAllText(infoTextAddress, infoText);

                using (StreamWriter infoWriter = File.AppendText(infoTextAddress))
                {
                    for (int pages = 1; pages <= (num_pages); pages++)
                    {
                        response = Helper.deserializeJSON(await Helper.Derpibooru(rating(Input.Text, pages, GetSort())));
                        searches = response.images;
                        foreach (DerpiObject.Image i in searches)
                        {
                            Uri    link          = new Uri($"{i.view_url}");
                            string filenameFixed = filename.Text.Replace("*", u.ToString());
                            try
                            {
                                await Helper.DownloadFile(link, i.format, filenameFixed, location);

                                pictureBox1.Load(location + @"\" + filenameFixed + "." + i.format);
                            }
                            catch
                            {//do nothing
                            }
                            u++;
                            //only write if the checkbox is checked
                            if (writeInfoToTXT)
                            {
                                // Get a distilled list of artist tags from the full tag listing.
                                string[] artistTags = i.tags.ToArray();
                                artistTags = Array.FindAll(artistTags, tag => tag.Contains("artist:"));
                                string artistString = "No Artist";
                                if (artistTags.Length != 0)
                                {
                                    artistString = String.Join(", ", artistTags);
                                }
                                infoWriter.WriteLine(filenameFixed + "." + i.format + " - " + i.id + " - " + artistString + " - " + String.Join(", ", i.tags) + "\n");
                            }
                            output.Text = $"{u} out of {response.total}";
                        }
                        searches.Clear();
                    }
                }
                output.Text = output.Text + " Finished!";
            }
        }