Finished NSFW conversion? untested
This commit is contained in:
parent
40214c0deb
commit
a8fe9d6c42
@ -8,6 +8,8 @@ using System.Threading.Tasks;
|
|||||||
using NadekoBot.Services;
|
using NadekoBot.Services;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Xml.Linq;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.NSFW
|
namespace NadekoBot.Modules.NSFW
|
||||||
{
|
{
|
||||||
@ -171,62 +173,70 @@ namespace NadekoBot.Modules.NSFW
|
|||||||
|
|
||||||
public static async Task<string> GetGelbooruImageLink(string tag)
|
public static async Task<string> GetGelbooruImageLink(string tag)
|
||||||
{
|
{
|
||||||
var headers = new Dictionary<string, string>() {
|
using (var http = new HttpClient())
|
||||||
{"User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1"},
|
{
|
||||||
{"Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" },
|
http.DefaultRequestHeaders.Clear();
|
||||||
};
|
http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1");
|
||||||
var url =
|
http.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
||||||
$"http://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=100&tags={tag.Replace(" ", "_")}";
|
|
||||||
var webpage = await GetResponseStringAsync(url, headers).ConfigureAwait(false);
|
var webpage = await http.GetStringAsync("http://gelbooru.com/index.php?page=dapi&s=post&q=index&limit=100&tags="+ tag.Replace(" ", "_")).ConfigureAwait(false);
|
||||||
var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
|
var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
|
||||||
if (matches.Count == 0)
|
if (matches.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
var rng = new Random();
|
var rng = new Random();
|
||||||
var match = matches[rng.Next(0, matches.Count)];
|
var match = matches[rng.Next(0, matches.Count)];
|
||||||
return matches[rng.Next(0, matches.Count)].Groups["url"].Value;
|
return matches[rng.Next(0, matches.Count)].Groups["url"].Value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task<string> GetSafebooruImageLink(string tag)
|
public static async Task<string> GetSafebooruImageLink(string tag)
|
||||||
{
|
{
|
||||||
var rng = new Random();
|
var rng = new Random();
|
||||||
var url =
|
var url =
|
||||||
$"http://safebooru.org/index.php?page=dapi&s=post&q=index&limit=100&tags={tag.Replace(" ", "_")}";
|
$"http://safebooru.org/index.php?page=dapi&s=post&q=index&limit=100&tags={tag.Replace(" ", "_")}";
|
||||||
var webpage = await GetResponseStringAsync(url).ConfigureAwait(false);
|
using (var http = new HttpClient())
|
||||||
|
{
|
||||||
|
var webpage = await http.GetStringAsync(url).ConfigureAwait(false);
|
||||||
var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
|
var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
|
||||||
if (matches.Count == 0)
|
if (matches.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
var match = matches[rng.Next(0, matches.Count)];
|
var match = matches[rng.Next(0, matches.Count)];
|
||||||
return matches[rng.Next(0, matches.Count)].Groups["url"].Value;
|
return matches[rng.Next(0, matches.Count)].Groups["url"].Value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static async Task<string> GetRule34ImageLink(string tag)
|
public static async Task<string> GetRule34ImageLink(string tag)
|
||||||
{
|
{
|
||||||
var rng = new Random();
|
var rng = new Random();
|
||||||
var url =
|
var url =
|
||||||
$"http://rule34.xxx/index.php?page=dapi&s=post&q=index&limit=100&tags={tag.Replace(" ", "_")}";
|
$"http://rule34.xxx/index.php?page=dapi&s=post&q=index&limit=100&tags={tag.Replace(" ", "_")}";
|
||||||
var webpage = await GetResponseStringAsync(url).ConfigureAwait(false);
|
using (var http = new HttpClient())
|
||||||
|
{
|
||||||
|
var webpage = await http.GetStringAsync(url).ConfigureAwait(false);
|
||||||
var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
|
var matches = Regex.Matches(webpage, "file_url=\"(?<url>.*?)\"");
|
||||||
if (matches.Count == 0)
|
if (matches.Count == 0)
|
||||||
return null;
|
return null;
|
||||||
var match = matches[rng.Next(0, matches.Count)];
|
var match = matches[rng.Next(0, matches.Count)];
|
||||||
return "http:" + matches[rng.Next(0, matches.Count)].Groups["url"].Value;
|
return "http:" + matches[rng.Next(0, matches.Count)].Groups["url"].Value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
internal static async Task<string> GetE621ImageLink(string tags)
|
internal static async Task<string> GetE621ImageLink(string tags)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var headers = new Dictionary<string, string>() {
|
using (var http = new HttpClient())
|
||||||
{"User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1"},
|
{
|
||||||
{"Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" },
|
http.DefaultRequestHeaders.Clear();
|
||||||
};
|
http.DefaultRequestHeaders.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1");
|
||||||
var data = await GetResponseStreamAsync(
|
http.DefaultRequestHeaders.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
|
||||||
"http://e621.net/post/index.xml?tags=" + Uri.EscapeUriString(tags) + "%20order:random&limit=1",
|
var data = await http.GetStringAsync("http://e621.net/post/index.xml?tags=" + Uri.EscapeUriString(tags) + "%20order:random&limit=1");
|
||||||
headers);
|
|
||||||
var doc = XDocument.Load(data);
|
var doc = XDocument.Load(data);
|
||||||
return doc.Descendants("file_url").FirstOrDefault().Value;
|
return doc.Descendants("file_url").FirstOrDefault().Value;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Error in e621 search: \n" + ex);
|
Console.WriteLine("Error in e621 search: \n" + ex);
|
||||||
|
Loading…
Reference in New Issue
Block a user