combine projects into one
This commit is contained in:
75
Gallery.Share/Sources/Danbooru/GallerySource.cs
Normal file
75
Gallery.Share/Sources/Danbooru/GallerySource.cs
Normal file
@ -0,0 +1,75 @@
|
||||
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.Danbooru
|
||||
{
|
||||
public class GallerySource : IGallerySource
|
||||
{
|
||||
public string Name => "Danbooru";
|
||||
public string Route => "danbooru";
|
||||
public string FlyoutIconKey => "Danbooru";
|
||||
public string HomePage => "https://danbooru.donmai.us";
|
||||
|
||||
public async Task<GalleryItem[]> GetRecentItemsAsync(int page)
|
||||
{
|
||||
var url = $"https://danbooru.donmai.us/posts?page={page}";
|
||||
var (result, error) = await NetHelper.RequestObject(url, @return: content => ResolveGalleryItems(content));
|
||||
|
||||
if (result == null || !string.IsNullOrEmpty(error))
|
||||
{
|
||||
Log.Error("danbooru.content.load", $"failed to load content array, error: {error}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private GalleryItem[] ResolveGalleryItems(string content)
|
||||
{
|
||||
var regex = new Regex(
|
||||
@"<article id=""post_\d+"".+?data-id=""(\d+)"".+?data-tags=""([^""]+?)"".+?" +
|
||||
@"data-width=""(\d+?)"" data-height=""(\d+?)"".+?data-source=""([^""]+?)"".+?" +
|
||||
@"data-uploader-id=""(\d+?)"".+?data-normalized-source=""([^""]+?)"".+?" +
|
||||
@"data-file-url=""([^""]+?)"".+?data-large-file-url=""([^""]+?)""", RegexOptions.Multiline);
|
||||
var matches = regex.Matches(content);
|
||||
var items = new GalleryItem[matches.Count];
|
||||
for (var i = 0; i < items.Length; i++)
|
||||
{
|
||||
var g = matches[i].Groups;
|
||||
items[i] = new GalleryItem(int.Parse(g[1].Value))
|
||||
{
|
||||
Tags = g[2].Value.Split(' '),
|
||||
Width = int.Parse(g[3].Value),
|
||||
Height = int.Parse(g[4].Value),
|
||||
UserId = g[6].Value,
|
||||
Source = g[7].Value,
|
||||
RawUrl = g[8].Value,
|
||||
PreviewUrl = g[9].Value
|
||||
};
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public void SetCookie()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void InitDynamicResources(string family, ResourceDictionary light, ResourceDictionary dark)
|
||||
{
|
||||
var icon = new FontImageSource
|
||||
{
|
||||
FontFamily = family,
|
||||
Glyph = "\uf5d2",
|
||||
Size = 18.0
|
||||
};
|
||||
light.Add(FlyoutIconKey, icon);
|
||||
dark.Add(FlyoutIconKey, icon);
|
||||
}
|
||||
}
|
||||
}
|
71
Gallery.Share/Sources/Gelbooru/GallerySource.cs
Normal file
71
Gallery.Share/Sources/Gelbooru/GallerySource.cs
Normal file
@ -0,0 +1,71 @@
|
||||
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.Gelbooru
|
||||
{
|
||||
public class GallerySource : IGallerySource
|
||||
{
|
||||
public string Name => "Gelbooru";
|
||||
public string Route => "gelbooru";
|
||||
public string FlyoutIconKey => "Gelbooru";
|
||||
public string HomePage => "https://gelbooru.com";
|
||||
|
||||
public async Task<GalleryItem[]> GetRecentItemsAsync(int page)
|
||||
{
|
||||
var offset = (page - 1) * 42;
|
||||
var url = $"https://gelbooru.com/index.php?page=post&s=list&tags=all&pid={offset}";
|
||||
var (result, error) = await NetHelper.RequestObject(url, @return: content => ResolveGalleryItems(content));
|
||||
|
||||
if (result == null || !string.IsNullOrEmpty(error))
|
||||
{
|
||||
Log.Error("gelbooru.content.load", $"failed to load content array, error: {error}");
|
||||
return null;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
private GalleryItem[] ResolveGalleryItems(string content)
|
||||
{
|
||||
var regex = new Regex(
|
||||
@"<article(.|\n)+?<a id=""p(\d+?)"" href=""([^""]+?)"">(.|\n)+?<img src=""([^""]+?)"" title=""([^""]+?)""",
|
||||
RegexOptions.Multiline);
|
||||
var matches = regex.Matches(content);
|
||||
var items = new GalleryItem[matches.Count];
|
||||
for (var i = 0; i < items.Length; i++)
|
||||
{
|
||||
var g = matches[i].Groups;
|
||||
items[i] = new GalleryItem(int.Parse(g[2].Value))
|
||||
{
|
||||
RawUrl = g[3].Value,
|
||||
PreviewUrl = g[5].Value,
|
||||
Tags = g[6].Value.Split(' '),
|
||||
IsRawPage = true
|
||||
};
|
||||
}
|
||||
return items;
|
||||
}
|
||||
|
||||
public void SetCookie()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void InitDynamicResources(string family, ResourceDictionary light, ResourceDictionary dark)
|
||||
{
|
||||
var icon = new FontImageSource
|
||||
{
|
||||
FontFamily = family,
|
||||
Glyph = "\uf5d2",
|
||||
Size = 18.0
|
||||
};
|
||||
light.Add(FlyoutIconKey, icon);
|
||||
dark.Add(FlyoutIconKey, icon);
|
||||
}
|
||||
}
|
||||
}
|
80
Gallery.Share/Sources/Yandere/GallerySource.cs
Normal file
80
Gallery.Share/Sources/Yandere/GallerySource.cs
Normal file
@ -0,0 +1,80 @@
|
||||
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<GalleryItem[]> GetRecentItemsAsync(int page)
|
||||
{
|
||||
var url = $"https://yande.re/post?page={page}";
|
||||
var (result, error) = await NetHelper.RequestObject<YandereItem[]>(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);
|
||||
}
|
||||
}
|
||||
}
|
29
Gallery.Share/Sources/Yandere/YandereItem.cs
Normal file
29
Gallery.Share/Sources/Yandere/YandereItem.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
|
||||
namespace Gallery.Sources.Yandere
|
||||
{
|
||||
public class YandereItem
|
||||
{
|
||||
#pragma warning disable IDE1006 // Naming Styles
|
||||
|
||||
public long id { get; set; }
|
||||
public string tags { get; set; }
|
||||
public long created_at { get; set; }
|
||||
public long updated_at { get; set; }
|
||||
public long creator_id { get; set; }
|
||||
public string author { get; set; }
|
||||
public string source { get; set; }
|
||||
public int score { get; set; }
|
||||
public int file_size { get; set; }
|
||||
public string file_ext { get; set; }
|
||||
public string file_url { get; set; }
|
||||
public string preview_url { get; set; }
|
||||
public int actual_preview_width { get; set; }
|
||||
public int actual_preview_height { get; set; }
|
||||
public string rating { get; set; }
|
||||
public int width { get; set; }
|
||||
public int height { get; set; }
|
||||
|
||||
#pragma warning restore IDE1006 // Naming Styles
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user