using System; using System.Text.RegularExpressions; using System.Threading.Tasks; using Gallery.Util; using Gallery.Util.Interface; using Gallery.Util.Model; using Xamarin.Forms; namespace Gallery.Sources.Yandere { public class GallerySource : IGallerySource { public string Name => "Yande.re"; public string Route => "yandere"; public string FlyoutIconKey => "Yandere"; public string HomePage => "https://yande.re"; public async Task GetRecentItemsAsync(int page) { var url = $"https://yande.re/post?page={page}"; var (result, error) = await NetHelper.RequestObject(url, contentHandler: ContentHandler); if (result == null || !string.IsNullOrEmpty(error)) { Log.Error("yandere.content.load", $"failed to load content array, error: {error}"); return null; } var items = new GalleryItem[result.Length]; for (var i = 0; i < items.Length; i++) { var y = result[i]; var item = new GalleryItem(y.id) { Tags = y.tags?.Split(' '), CreatedTime = y.created_at.ToLocalTime(), UpdatedTime = y.updated_at.ToLocalTime(), UserId = y.creator_id.ToString(), UserName = y.author, Source = y.source, PreviewUrl = y.preview_url, RawUrl = y.file_url, Width = y.width, Height = y.height }; items[i] = item; } return items; } private string ContentHandler(string content) { var regex = new Regex(@"Post\.register\((\{.+\})\)\s*$", RegexOptions.Multiline); var matches = regex.Matches(content); var array = new string[matches.Count]; for (var i = 0; i < array.Length; i++) { array[i] = matches[i].Groups[1].Value; } return $"[{string.Join(',', array)}]"; } public void SetCookie() { throw new NotImplementedException(); } public void InitDynamicResources(string family, ResourceDictionary light, ResourceDictionary dark) { var icon = new FontImageSource { FontFamily = family, Glyph = "\uf302", Size = 18.0 }; light.Add(FlyoutIconKey, icon); dark.Add(FlyoutIconKey, icon); } } }