Example #1
0
        private static void Poster()
        {
            string[] blockedImages    = File.ReadAllLines("./blockedimages.txt");
            string[] captions         = File.ReadAllLines("./captions.txt");
            string[] r34endpoints     = File.ReadAllLines("./r34endpoints.txt");
            string[] endpoints        = File.ReadAllLines("./endpoints.txt");
            string[] accountsToScrape = File.ReadAllLines("./accountstoscrape.txt");

            try
            {
                ITweet tweet;
                string caption  = captions[rng.Next(captions.Length)];
                string endpoint = endpoints[rng.Next(endpoints.Length)];

                int rngForR34 = rng.Next(4);

                if (rngForR34 == 3)
                {
                    string newEndpoint = r34endpoints[rng.Next(r34endpoints.Length)];

                    Console.WriteLine(newEndpoint);

                    string url = $"https://rule34.xxx/index.php?page=dapi&s=post&q=index&tags={newEndpoint}";

                    XmlDocument xmlDocument = new XmlDocument();
                    xmlDocument.LoadXml(client.DownloadString(url));

                    XmlNodeList nodes = xmlDocument.DocumentElement.SelectNodes("post");

                    XmlNode node = nodes[rng.Next(nodes.Count)];

                    string fileUrl = node.Attributes["file_url"].Value;

                    string[] URLSplit = fileUrl.Split('/').Last().Split('.');

                    string fileName      = URLSplit[0];
                    string fileExtension = URLSplit[1];
                    string fullFileName  = $"{fileName}.{fileExtension}";

                    client.DownloadFile(fileUrl, $"./hentai/r34items/{newEndpoint}/{fullFileName}");

                    byte[] bytesToUpload = File.ReadAllBytes($"./hentai/r34items/{newEndpoint}/{fullFileName}");

                    IMedia mediaToUpload;

                    if (fileExtension == "mp4")
                    {
                        mediaToUpload = Upload.UploadBinary(new UploadParameters
                        {
                            Binary    = bytesToUpload,
                            MediaType = MediaType.VideoMp4
                        });
                    }
                    else
                    {
                        mediaToUpload = Upload.UploadBinary(new UploadParameters
                        {
                            Binary    = bytesToUpload,
                            MediaType = MediaType.Media
                        });
                    }

                    List <IMedia> medias = new List <IMedia> {
                        mediaToUpload
                    };

                    tweet = Tweet.PublishTweet($"{caption}\n\n{hashtags}", new PublishTweetOptionalParameters
                    {
                        Medias = medias
                    });
                }
                else
                {
                    Console.WriteLine($"Selected endpoint: {endpoint}");

                    i++;

                    if (i == 10)
                    {
                        i = 0;
                        WriteStats();
                    }

                    if (endpoint == "scrape")
                    {
                    }
                    else
                    {
                        string           jsonString       = client.DownloadString(APIURL + endpoint);
                        ReturnInfomation returnInfomation = JsonConvert.DeserializeObject <ReturnInfomation>(jsonString);
                        string           URL = returnInfomation.URL;

                        string[] URLSplit = URL.Split('/').Last().Split('.');

                        string fileName      = URLSplit[0];
                        string fileExtension = URLSplit[1];
                        string fullFileName  = $"{fileName}.{fileExtension}";

                        if (!File.Exists($"./hentai/{endpoint}/{fullFileName}"))
                        {
                            client.DownloadFile(URL, $"./hentai/{endpoint}/{fullFileName}");
                        }

                        foreach (string blockedImage in blockedImages)
                        {
                            if (fullFileName == blockedImage)
                            {
                                Console.WriteLine($"Was going to tweet blocked image: {blockedImage}");
                                Poster();
                                return;
                            }
                        }

                        byte[] bytesToUpload = File.ReadAllBytes($"./hentai/{endpoint}/{fullFileName}");

                        IMedia mediaToUpload;

                        if (fileExtension == "mp4")
                        {
                            mediaToUpload = Upload.UploadBinary(new UploadParameters
                            {
                                Binary    = bytesToUpload,
                                MediaType = MediaType.VideoMp4
                            });
                        }
                        else
                        {
                            mediaToUpload = Upload.UploadBinary(new UploadParameters
                            {
                                Binary    = bytesToUpload,
                                MediaType = MediaType.Media
                            });
                        }

                        List <IMedia> medias = new List <IMedia> {
                            mediaToUpload
                        };

                        tweet = Tweet.PublishTweet($"{caption}\n\n{hashtags}", new PublishTweetOptionalParameters
                        {
                            Medias = medias
                        });
                    }
                }

                Console.WriteLine("Tweeted");

                Thread thread = new Thread(new ThreadStart(CalculateMetrics));
                thread.Start();
                FollowerInteraction();

                Console.WriteLine("Waiting 1 minute\n");
                Thread.Sleep(TimeSpan.FromMinutes(1));
                Poster();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Poster();
            }
        }
        private static void Poster()
        {
            string caption = captions[rng.Next(captions.Length)];

            Thread.Sleep(TimeSpan.FromTicks(2)); // This is to reset the Random system. Which runs off system time.
            string endpoint = endpoints[rng.Next(endpoints.Length)];

            Console.WriteLine($"Caption: {caption}\nEndpoint: {endpoint}");

            try                                                                                                   // Because shit happens.
            {
                string jsonString = client.DownloadString(APIURL + endpoint);                                     // Downloading JSON.
                client.Dispose();                                                                                 // Because memory leaks.
                ReturnInfomation returnInfomation = JsonConvert.DeserializeObject <ReturnInfomation>(jsonString); // Parsing JSON data into the ReturnInfomation class earlier.
                string           URL = returnInfomation.URL;                                                      // Getting the URL.

                string[] URLSplit = URL.Split('/').Last().Split('.');                                             // Splitting the URL into parts for below.

                // All these are as said.

                string fileName      = URLSplit[0];
                string fileExtension = URLSplit[1];
                string fullFileName  = $"{fileName}.{fileExtension}";
                byte[] bytesToUpload;

                if (blockedImages.Contains(fullFileName))
                {
                    return;
                }

                if (saveToDedicatedFolders) // If you are saving to dedicated folders. If not change saveToDedicatedFolders to false on line 29. DO NOT DELETE THIS.
                {
                    // This is all just saving the file and then getting the bytes.

                    if (!File.Exists($"{imageBaseDirectory}/{endpoint}/{fullFileName}"))
                    {
                        client.DownloadFile(URL, $"{imageBaseDirectory}/{endpoint}/{fullFileName}");
                        bytesToUpload = File.ReadAllBytes($"{imageBaseDirectory}/{endpoint}/{fullFileName}");
                    }
                    else
                    {
                        bytesToUpload = File.ReadAllBytes($"{imageBaseDirectory}/{endpoint}/{fullFileName}");
                    }
                }
                else
                {
                    if (!File.Exists($"{imageBaseDirectory}/{fullFileName}"))
                    {
                        client.DownloadFile(URL, $"{imageBaseDirectory}/{fullFileName}");
                        bytesToUpload = File.ReadAllBytes($"{imageBaseDirectory}/{fullFileName}");
                    }
                    else
                    {
                        bytesToUpload = File.ReadAllBytes($"{imageBaseDirectory}/{fullFileName}");
                    }
                }

                IMedia mediaToUpload;                                        // Creating the twitter media

                if (fileExtension == "mp4")                                  // Checking if the file is a .mp4
                {
                    mediaToUpload = Upload.UploadBinary(new UploadParameters // Uploading
                    {
                        Binary    = bytesToUpload,
                        MediaType = MediaType.VideoMp4
                    });
                }
                else
                {
                    mediaToUpload = Upload.UploadBinary(new UploadParameters // Uploading
                    {
                        Binary    = bytesToUpload,
                        MediaType = MediaType.Media
                    });
                }

                List <IMedia> medias = new List <IMedia> {
                    mediaToUpload
                };

                ITweet tweet = Tweet.PublishTweet($"{caption}\n\n{hashtags}", new PublishTweetOptionalParameters // Publishing... Finally!
                {
                    Medias = medias
                });
            }
            catch (Exception ex) // Shit probably happened.
            {
                Console.WriteLine(ex.ToString());
            }

            Console.WriteLine($"Tweeted. Waiting 5 minutes.");
            Thread.Sleep(TimeSpan.FromMinutes(5)); // Wait a minute to not spam twitters API and get rate limited.
            Poster();                              // To make this recursive without threadlocking.
        }