-
Notifications
You must be signed in to change notification settings - Fork 2
/
EngineBase.cs
59 lines (51 loc) · 1.77 KB
/
EngineBase.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Xml;
namespace BooruDownloader
{
public abstract class EngineBase
{
public XmlDocument document = new XmlDocument();
public XmlElement root;
public XmlElement post;
public string url;
public string rating;
protected string apiKey;
protected string login;
public enum type
{
DAN = 0,
GEL = 1,
};
[DllImport("kernel32.dll", SetLastError = true)]
public static extern bool AllocConsole();
public abstract void DownloadImage(string url, string tags, bool keepOrigName, string rating);
public abstract string DownloadPosts(string url, string tags, int page, bool keepOrigName, bool inclRating);
public abstract int GetPostCount(string domain, string tags);
public abstract type getType();
public virtual void SetApiKey(string apiKey)
{
this.apiKey = apiKey;
}
public virtual void SetLogin(string login)
{
this.login = login;
}
public virtual string ExtensionFromUrl(string url)
{
var extension = "";
var match = Regex.Match(url, @"(?<=\.)[^.]+$", RegexOptions.Compiled);
if (match.Success)
extension = match.Value;
return extension;
}
public virtual string FilenameFromUrl(string url)
{
var filename = "";
var match = Regex.Match(url, @"([^\/.]+)\.[^.]*$", RegexOptions.Compiled);
if (match.Success)
filename = match.Value;
return filename;
}
}
}