Exemplo n.º 1
0
        public async Task <bool> QueryPosts()
        {
            if (Site is null || Tags is null)
            {
                return(false);
            }
            Site += "/posts.json";

            for (int i = 0; i < pages; i++)
            {
                var page = queryDictionary["page"];
                queryDictionary["page"] = int.Parse(page.ToString()) + 1;

                var queryPage = new UriBuilder
                {
                    Host  = Site,
                    Query = queryDictionary.ToGetParameters(),
                };


                var url      = queryPage.ToString();
                var response = await client.GetAsync(url.Remove(url.LastIndexOf('/'), 1));

                var rawResponseJSON = await response.Content.ReadAsStringAsync();

                var responseJSON = JsonConvert.DeserializeObject <BooruResponse>(rawResponseJSON);

                foreach (var post in responseJSON.Posts)
                {
                    var hash      = post.File.Md5;
                    var lookupTag = Tags.Split(' ').Where(tag => tag != "").ToArray();
                    Array.Sort(lookupTag);
                    if (PostDownloadHelper.ContainsHash(lookupTag[0], hash))
                    {
                        log.Info($"File with hash {hash} already exists; skipping.");
                    }
                    else
                    {
                        if (post.File.Url is null)
                        {
                            continue;
                        }
                        PostDownloadHelper.MD5Hashes[lookupTag[0]].Add(hash);
                        PostDownloadHelper.DownloadQueue.Enqueue(new Download {
                            FolderName = Tags, URL = post.File.Url.ToString()
                        });
                    }
                }
            }
            return(true);
        }
Exemplo n.º 2
0
        public static async Task Main()
        {
            Console.CancelKeyPress += OnControlC;
            InitLogger();
            //Get Configuration from file.
            Console.Title = "MFCD - Furry Image Downloader Tool";
            await Task.Delay(600);

            var config = await RetrieveConfigAsync();

            await Task.Delay(1500);

            GenerateDirectories(config);
            await Task.Delay(1500);

            await new TopLevelQueryManager().QueryPostsFromJSON(config);

            await PostDownloadHelper.DrainQueue();

            await Task.Delay(2000);
        }