Hello
This commit is contained in:
25
Booru.Net.sln
Normal file
25
Booru.Net.sln
Normal file
@@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.27703.2026
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Booru.Net", "Booru.Net\Booru.Net.csproj", "{BC612FDE-FC2D-42D8-AD7F-988874B6A839}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{BC612FDE-FC2D-42D8-AD7F-988874B6A839}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BC612FDE-FC2D-42D8-AD7F-988874B6A839}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BC612FDE-FC2D-42D8-AD7F-988874B6A839}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BC612FDE-FC2D-42D8-AD7F-988874B6A839}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {0B4AF3C1-293A-4372-B24C-A3535F49FEC3}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
15
Booru.Net/Booru.Net.csproj
Normal file
15
Booru.Net/Booru.Net.csproj
Normal file
@@ -0,0 +1,15 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
|
||||
<Authors>exsersewo</Authors>
|
||||
<Company />
|
||||
<Description></Description>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
125
Booru.Net/Client.cs
Normal file
125
Booru.Net/Client.cs
Normal file
@@ -0,0 +1,125 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Booru.Net
|
||||
{
|
||||
public class Client
|
||||
{
|
||||
public async Task<IReadOnlyList<SafebooruImage>> GetSafebooruImagesAsync(IReadOnlyList<string> tags)
|
||||
{
|
||||
IList<string> newtags = tags.ToList();
|
||||
var tagstring = String.Join("%20", newtags);
|
||||
|
||||
var data = await WebRequest.ReturnStringAsync(new Uri("https://safebooru.org/index.php?page=dapi&s=post&q=index&json=1&tags=" + tagstring));
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
var posts = JsonConvert.DeserializeObject<List<SafebooruImage>>(data);
|
||||
return posts;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public async Task<IReadOnlyList<Rule34Image>> GetRule34ImagesAsync(IReadOnlyList<string> tags)
|
||||
{
|
||||
IList<string> newtags = tags.ToList();
|
||||
var tagstring = String.Join("%20", newtags);
|
||||
|
||||
var data = await WebRequest.ReturnStringAsync(new Uri("https://rule34.xxx/index.php?page=dapi&s=post&q=index&json=1&tags=" + tagstring));
|
||||
if (data != null)
|
||||
{
|
||||
var posts = JsonConvert.DeserializeObject<List<Rule34Image>>(data);
|
||||
return posts;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public async Task<IReadOnlyList<RealbooruImage>> GetRealBooruImagesAsync(IReadOnlyList<string> tags)
|
||||
{
|
||||
IList<string> newtags = tags.ToList();
|
||||
var tagstring = String.Join("%20", newtags);
|
||||
|
||||
var data = await WebRequest.ReturnStringAsync(new Uri("https://realbooru.com/index.php?page=dapi&s=post&q=index&json=1&tags=" + tagstring));
|
||||
if (data != null)
|
||||
{
|
||||
var posts = JsonConvert.DeserializeObject<List<RealbooruImage>>(data);
|
||||
return posts;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public async Task<IReadOnlyList<DanbooruImage>> GetDanbooruImagesAsync(IReadOnlyList<string> tags)
|
||||
{
|
||||
IList<string> newtags = tags.ToList();
|
||||
var tagstring = String.Join("%20", newtags);
|
||||
|
||||
var data = await WebRequest.ReturnStringAsync(new Uri("https://danbooru.donmai.us/posts.json?tags=" + tagstring));
|
||||
if (data != null)
|
||||
{
|
||||
var posts = JsonConvert.DeserializeObject<List<DanbooruImage>>(data);
|
||||
return posts;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
public async Task<IReadOnlyList<GelbooruImage>> GetGelbooruImagesAsync(IReadOnlyList<string> tags)
|
||||
{
|
||||
IList<string> newtags = tags.ToList();
|
||||
var tagstring = String.Join("%20", newtags);
|
||||
|
||||
var data = await WebRequest.ReturnStringAsync(new Uri("https://gelbooru.com/index.php?page=dapi&s=post&q=index&json=1&tags=" + tagstring));
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
var posts = JsonConvert.DeserializeObject<List<GelbooruImage>>(data);
|
||||
return posts;
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
public async Task<IReadOnlyList<KonaChanImage>> GetKonaChanImagesAsync(IReadOnlyList<string> tags)
|
||||
{
|
||||
IList<string> newtags = tags.ToList();
|
||||
var tagstring = String.Join("%20", newtags);
|
||||
|
||||
var data = await WebRequest.ReturnStringAsync(new Uri("https://konachan.com/post.json?tags=" + tagstring));
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
var posts = JsonConvert.DeserializeObject<List<KonaChanImage>>(data);
|
||||
return posts;
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
public async Task<IReadOnlyList<E621Image>> GetE621ImagesAsync(IReadOnlyList<string> tags)
|
||||
{
|
||||
IList<string> newtags = tags.ToList();
|
||||
var tagstring = String.Join("%20", newtags);
|
||||
|
||||
var data = await WebRequest.ReturnStringAsync(new Uri("https://e621.net/post/index.json?tags=" + tagstring));
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
var posts = JsonConvert.DeserializeObject<List<E621Image>>(data);
|
||||
return posts;
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
public async Task<IReadOnlyList<YandereImage>> GetYandereImagesAsync(IReadOnlyList<string> tags)
|
||||
{
|
||||
IList<string> newtags = tags.ToList();
|
||||
var tagstring = String.Join("%20", newtags);
|
||||
|
||||
var data = await WebRequest.ReturnStringAsync(new Uri("https://yande.re/post.json?tags=" + tagstring));
|
||||
|
||||
if (data != null)
|
||||
{
|
||||
var posts = JsonConvert.DeserializeObject<List<YandereImage>>(data);
|
||||
return posts;
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
39
Booru.Net/Models/Boards/BooruImage.cs
Normal file
39
Booru.Net/Models/Boards/BooruImage.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Booru.Net
|
||||
{
|
||||
public class BooruImage
|
||||
{
|
||||
[JsonProperty("id")]
|
||||
public int ID { get; set; }
|
||||
|
||||
[JsonProperty("score")]
|
||||
public int Score { get; set; }
|
||||
|
||||
[JsonProperty("rating")]
|
||||
private string Prating { get; set; }
|
||||
|
||||
[JsonProperty("file_url")]
|
||||
public string ImageUrl { get; set; }
|
||||
|
||||
public Rating Rating
|
||||
{
|
||||
get
|
||||
{
|
||||
if(Prating == "s")
|
||||
{
|
||||
return Rating.Safe;
|
||||
}
|
||||
if(Prating == "q")
|
||||
{
|
||||
return Rating.Questionable;
|
||||
}
|
||||
if(Prating == "e")
|
||||
{
|
||||
return Rating.Explicit;
|
||||
}
|
||||
return Rating.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Booru.Net/Models/Boards/DanBooruImage.cs
Normal file
15
Booru.Net/Models/Boards/DanBooruImage.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Booru.Net
|
||||
{
|
||||
public class DanbooruImage : BooruImage
|
||||
{
|
||||
[JsonProperty("tag_string")]
|
||||
private string TagString { get; set; }
|
||||
|
||||
public IReadOnlyList<string> Tags { get { return TagString.Split(' '); } }
|
||||
|
||||
public virtual string PostUrl { get { return "https://danbooru.donmai.us/posts/" + ID; } }
|
||||
}
|
||||
}
|
||||
7
Booru.Net/Models/Boards/E621Image.cs
Normal file
7
Booru.Net/Models/Boards/E621Image.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Booru.Net
|
||||
{
|
||||
public class E621Image : GelbooruImage
|
||||
{
|
||||
public override string PostUrl { get { return "https://e621.net/post/show/" + ID; } }
|
||||
}
|
||||
}
|
||||
18
Booru.Net/Models/Boards/GelbooruImage.cs
Normal file
18
Booru.Net/Models/Boards/GelbooruImage.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Booru.Net
|
||||
{
|
||||
public class GelbooruImage : BooruImage
|
||||
{
|
||||
[JsonProperty("directory")]
|
||||
public string Directory { get; set; }
|
||||
|
||||
[JsonProperty("tags")]
|
||||
private string Ptags { get; set; }
|
||||
|
||||
public IReadOnlyList<string> Tags { get { return Ptags.Split(' '); } }
|
||||
|
||||
public virtual string PostUrl { get { return "https://gelbooru.com/index.php?page=post&s=view&id=" + ID; } }
|
||||
}
|
||||
}
|
||||
7
Booru.Net/Models/Boards/KonaChanImage.cs
Normal file
7
Booru.Net/Models/Boards/KonaChanImage.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Booru.Net
|
||||
{
|
||||
public class KonaChanImage : GelbooruImage
|
||||
{
|
||||
public override string PostUrl { get { return "https://konachan.com/post/show/" + ID; } }
|
||||
}
|
||||
}
|
||||
10
Booru.Net/Models/Boards/RealBooruImage.cs
Normal file
10
Booru.Net/Models/Boards/RealBooruImage.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Booru.Net
|
||||
{
|
||||
public class RealbooruImage : SafebooruImage
|
||||
{
|
||||
public override string ImageUrl
|
||||
=> "https://realbooru.com/images/" + Directory + "/" + Image;
|
||||
public override string PostUrl
|
||||
=> "https://realbooru.com/index.php?page=post&s=view&id=" + ID;
|
||||
}
|
||||
}
|
||||
10
Booru.Net/Models/Boards/Rule34Image.cs
Normal file
10
Booru.Net/Models/Boards/Rule34Image.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Booru.Net
|
||||
{
|
||||
public class Rule34Image : SafebooruImage
|
||||
{
|
||||
public override string ImageUrl
|
||||
=> "https://rule34.xxx/images/" + Directory + "/" + Image;
|
||||
public override string PostUrl
|
||||
=> "https://rule34.xxx/index.php?page=post&s=view&id=" + ID;
|
||||
}
|
||||
}
|
||||
61
Booru.Net/Models/Boards/SafebooruImage.cs
Normal file
61
Booru.Net/Models/Boards/SafebooruImage.cs
Normal file
@@ -0,0 +1,61 @@
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Booru.Net
|
||||
{
|
||||
public class SafebooruImage
|
||||
{
|
||||
[JsonProperty("directory")]
|
||||
public string Directory { get; set; }
|
||||
|
||||
[JsonProperty("hash")]
|
||||
public string Hash { get; set; }
|
||||
|
||||
[JsonProperty("height")]
|
||||
public int Height { get; set; }
|
||||
|
||||
[JsonProperty("id")]
|
||||
public int ID { get; set; }
|
||||
|
||||
[JsonProperty("image")]
|
||||
public string Image { get; set; }
|
||||
|
||||
[JsonProperty("change")]
|
||||
public ulong Change { get; set; }
|
||||
|
||||
[JsonProperty("owner")]
|
||||
public string Owner { get; set; }
|
||||
|
||||
[JsonProperty("parent_id")]
|
||||
public int ParentID { get; set; }
|
||||
|
||||
[JsonProperty("rating")]
|
||||
public Rating Rating { get; set; }
|
||||
|
||||
[JsonProperty("sample")]
|
||||
public bool Sample { get; set; }
|
||||
|
||||
[JsonProperty("sample_height")]
|
||||
public int SampleHeight { get; set; }
|
||||
|
||||
[JsonProperty("sample_width")]
|
||||
public int SampleWidth { get; set; }
|
||||
|
||||
[JsonProperty("score")]
|
||||
public int Score { get; set; }
|
||||
|
||||
[JsonProperty("tags")]
|
||||
private string Ptags { get; set; }
|
||||
|
||||
[JsonProperty("width")]
|
||||
public int Width { get; set; }
|
||||
|
||||
public IReadOnlyList<string> Tags { get { return Ptags.Split(' '); } }
|
||||
|
||||
public virtual string ImageUrl
|
||||
=> "https://safebooru.org/images/" + Directory + "/" + Image;
|
||||
|
||||
public virtual string PostUrl
|
||||
=> "https://safebooru.org/index.php?page=post&s=view&id=" + ID;
|
||||
}
|
||||
}
|
||||
7
Booru.Net/Models/Boards/YandereImage.cs
Normal file
7
Booru.Net/Models/Boards/YandereImage.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Booru.Net
|
||||
{
|
||||
public class YandereImage : GelbooruImage
|
||||
{
|
||||
public override string PostUrl { get { return "https://yande.re/post/show/" + ID; } }
|
||||
}
|
||||
}
|
||||
17
Booru.Net/Models/BooruTypes.cs
Normal file
17
Booru.Net/Models/BooruTypes.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Skuld.Models.API.Booru
|
||||
{
|
||||
public enum BooruTypes
|
||||
{
|
||||
Danbooru,
|
||||
Gelbooru,
|
||||
Rule34,
|
||||
E621,
|
||||
Yandere,
|
||||
Safebooru,
|
||||
KonaChan
|
||||
}
|
||||
}
|
||||
10
Booru.Net/Models/Rating.cs
Normal file
10
Booru.Net/Models/Rating.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace Booru.Net
|
||||
{
|
||||
public enum Rating
|
||||
{
|
||||
None,
|
||||
Safe,
|
||||
Questionable,
|
||||
Explicit
|
||||
}
|
||||
}
|
||||
49
Booru.Net/WebRequest.cs
Normal file
49
Booru.Net/WebRequest.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using System.IO;
|
||||
|
||||
namespace Booru.Net
|
||||
{
|
||||
class WebRequest
|
||||
{
|
||||
public static HttpWebRequest CreateWebRequest(Uri uri)
|
||||
{
|
||||
var cli = (HttpWebRequest)System.Net.WebRequest.Create(uri);
|
||||
|
||||
cli.AllowAutoRedirect = true;
|
||||
cli.KeepAlive = false;
|
||||
cli.Timeout = 20000;
|
||||
cli.ProtocolVersion = HttpVersion.Version10;
|
||||
|
||||
return cli;
|
||||
}
|
||||
public static async Task<string> ReturnStringAsync(Uri url)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = CreateWebRequest(url);
|
||||
|
||||
var resp = (HttpWebResponse)(await client.GetResponseAsync());
|
||||
if (resp.StatusCode == HttpStatusCode.OK)
|
||||
{
|
||||
var reader = new StreamReader(resp.GetResponseStream());
|
||||
var responce = await reader.ReadToEndAsync();
|
||||
resp.Dispose();
|
||||
client.Abort();
|
||||
return responce;
|
||||
}
|
||||
else
|
||||
{
|
||||
resp.Dispose();
|
||||
client.Abort();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user