コード例 #1
0
        public async Task RunExample()
        {
            PhilomenaClient client = new PhilomenaClient("https://derpibooru.org");
            IPhilomenaImage image  = await client.GetImageSearch("fluttershy").BeginSearch().FirstAsync();

            string filename = $"ExampleDownloads/DownloadImageToFile/{image.Id}.{image.Format}";

            await image.DownloadToFile(filename);
        }
コード例 #2
0
        public async Task RunExample()
        {
            PhilomenaClient       client = new PhilomenaClient("https://derpibooru.org");
            IPhilomenaImageSearch search = client.GetImageSearch("fluttershy", o => o
                                                                 .WithMaxImages(5)
                                                                 );

            Log.Information("Download query simple");

            // Using download all method
            await search
            .CreateParallelDownloader(maxDownloadThreads : 8, o => o
                                      .WithImageFileDownloader(image => $"ExampleDownloads/EnumerateSearchQuery/{image.Id}.{image.Format}")
                                      )
            .BeginDownload();

            Log.Information("Download query with delegates, skipping existing images");

            // Use a conditional downloader to skip images already downloaded
            // Note that filters in the search query itself are preferred since they will provide better performance. Don't use conditional downloaders for conditions like image score.
            await search
            .CreateParallelDownloader(maxDownloadThreads : 8, o => o
                                      .WithConditionalDownloader(SkipImagesAlreadyDownloaded, o => o
                                                                 .WithImageFileDownloader(GetFileForImage)
                                                                 )
                                      )
            .BeginDownload();

            Log.Information("Downloading images explicitly");

            // Explicitly looping over each image and saving
            await foreach (IPhilomenaImage image in search.BeginSearch())
            {
                string filename = $"ExampleDownloads/EnumerateSearchQuery/{image.Id}.{image.Format}";

                await image.DownloadToFile(filename);
            }

            Log.Information("Downloading with multiple threads and progress updates");

            // Downloading with multiple threads and progress updates
            // Also skips downloaded images like before
            SyncProgress <PhilomenaImageSearchDownloadProgressInfo> progress = new SyncProgress <PhilomenaImageSearchDownloadProgressInfo>(DownloadProgressUpdate);
            await client
            .GetImageSearch("fluttershy", o => o
                            .WithMaxImages(100)
                            )
            .CreateParallelDownloader(maxDownloadThreads: 8, o => o
                                      .WithConditionalDownloader(SkipImagesAlreadyDownloaded, o => o
                                                                 .WithImageFileDownloader(GetFileForImage)
                                                                 .WithImageMetadataFileDownloader(GetMetadataFileForImage)
                                                                 )
                                      )
            .BeginDownload(searchDownloadProgress: progress);
        }
コード例 #3
0
        public async Task RunExample()
        {
            PhilomenaClient client = new PhilomenaClient("https://derpibooru.org");

            // Download both SVG sources and rasters
            await client
            .GetImageSearch("original_format:svg", o => o
                            .WithMaxImages(5)
                            )
            .CreateParallelDownloader(maxDownloadThreads: 1, o => o
                                      .WithImageFileDownloader(image => $"ExampleDownloads/DownloadSvgImages/{image.Id}.{image.Format}")
                                      .WithImageSvgFileDownloader(image => $"ExampleDownloads/DownloadSvgImages/{image.Id}.svg") // Note: image.Format is always 'png' for SVG images
                                      )
            .BeginDownload();
        }
コード例 #4
0
        public async Task RunExample()
        {
            PhilomenaClient client = new PhilomenaClient("https://derpibooru.org");

            // Get an image
            IPhilomenaImage image = await client.GetImageSearch("fluttershy").BeginSearch().FirstAsync();

            Log.Information("Listing tags for image {ImageId}", image.Id);

            // Get the tags from the IDs
            foreach (int tagId in image.TagIds)
            {
                TagModel tag = await client.GetTagById(tagId);

                Log.Information("{TagId}: {TagName} (On {TagImages} images)", tagId, tag.Name, tag.Images);
            }
        }
コード例 #5
0
        public async Task RunExample()
        {
            PhilomenaClient client = new PhilomenaClient("https://derpibooru.org");

            using CancellationTokenSource cts = new CancellationTokenSource();

            SyncProgress <PhilomenaImageSearchDownloadProgressInfo> searchProgress = new SyncProgress <PhilomenaImageSearchDownloadProgressInfo>(ProgressReport);

            // Run the download on another thread
            Task downloadTask = Task.Run(async() =>
            {
                try
                {
                    await client
                    .GetImageSearch("fluttershy", o => o
                                    .WithMaxImages(100)
                                    )
                    .CreateParallelDownloader(maxDownloadThreads: 1, o => o
                                              .WithImageFileDownloader(image => Path.Join("ExampleDownloads", "PauseAndCancelImageDownload", $"{image.Id}.{image.Format}"))
                                              )
                    .BeginDownload(cts.Token);
                }
                catch (OperationCanceledException)
                {
                    Log.Information("Download cancelled");
                }
            });

            // Wait a bit before canceling
            Log.Information("Downloading some images");
            await Task.Delay(3000);

            // Cancel the download
            Log.Information("Cancelling the download");
            cts.Cancel();

            // Wait for the download thread to finish
            await downloadTask;

            Log.Information("Download ended");
        }
コード例 #6
0
ファイル: Program.cs プロジェクト: WinterGala/PhilomenaClient
        static void Main()
        {
            PhilomenaClient client = new PhilomenaClient(PhilomenaClient.DerpibooruUrl, null);

            //CommentResponse comment = client.GetCommentResponse(1000).Result;
            //ImageResponse image = client.GetImageResponse(1).Result;
            //TagResponse tag = client.GetTagResponse("artist-colon-atryl").Result;
            //PostResponse post = client.GetPostResponse(2730144).Result;
            //UserResponse user = client.GetProfileResponse(216494).Result;
            //FilterResponse filter = client.GetFilterResponse(56027).Result;
            //FiltersPage filters = client.GetSystemFiltersResponse().Result;
            //CommentsPage comments = client.GetCommentSearchResponses("image_id:1000000").Result;
            //GalleriesPage galleries = client.GetGallerySearchResponses("title:mean*").Result;
            //PostsPage posts = client.GetPostSearchResponses("subject:time wasting thread").Result;
            //ImagesPage images = client.GetImageSearchResponses("safe").Result;
            //TagsPage tags = client.GetTagSearchResponses("analyzed_name:wing").Result;
            //ForumsPage forums = client.GetForumResponses().Result;
            //ForumResponse forum = client.GetForumResponse("dis").Result;
            //TopicsPage topics = client.GetTopicResponses("dis").Result;
            //TopicResponse topic = client.GetTopicResponse("dis", "ask-the-mods-anything").Result;
            //PostsPage posts = client.GetPostResponses("dis", "ask-the-mods-anything").Result;
            //PostResponse post = client.GetPostResponse("dis", "ask-the-mods-anything", 2761095).Result;
            Console.ReadLine();
        }