コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #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");
        }