public async Task <E621Post> SearchRandom(string tags) { var options = new E621SearchOptions { Limit = 1, Tags = $"{tags} order:random", TypedTags = true }; var posts = await _client.Search(options); return(posts.FirstOrDefault()); }
/// <summary> /// Fetch the next file. /// </summary> async void FetchFile() { if (WallpaperCache == null || WallpaperPtr >= WallpaperCache.Count) { try { WallpaperCache = await Client.Search(Search); WallpaperPtr = 0; } catch { return; } } if (WallpaperCache.Count == 0) { return; } var x = WallpaperCache[WallpaperPtr++]; bool fetchedCache = false; while (!(x.File.Ext == "png" || x.File.Ext == "jpg" || x.File.Ext == "gif") || x.File.Url == null) { try { if (WallpaperPtr >= WallpaperCache.Count) { if (fetchedCache) { return; } else { try { WallpaperCache = await Client.Search(Search); WallpaperPtr = 0; } catch { return; } fetchedCache = true; if (WallpaperCache.Count == 0) { return; } } } x = WallpaperCache[WallpaperPtr++]; } catch { return; } } if (!(x.File.Ext == "png" || x.File.Ext == "jpg" || x.File.Ext == "gif") || x.File.Url == null) { return; } using (MemoryStream src = new MemoryStream(await WebClient.GetByteArrayAsync(x.File.Url))) { if (PrevWallpaper != null) { PrevWallpaper.Dispose(); } PrevWallpaper = CurrWallpaper; NextWallpaper = Texture2D.FromStream(Helper.Graphics, src); StartTransition(); } }