Skip to content

Commit

Permalink
Add api key and login options, also fix #6
Browse files Browse the repository at this point in the history
  • Loading branch information
fgRuslan committed Mar 11, 2023
1 parent 3f93291 commit ebd21d5
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 20 deletions.
17 changes: 6 additions & 11 deletions DanEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,18 @@ public override async void DownloadImage(string url, string tags, bool keepOrigi
{
// wc.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; " +
// "Windows NT 5.2; .NET CLR 1.0.3705;)");
wc.Headers.Add("user-agent", ".NET Framework Test Client");
try
{
if (keepOriginalNames)
wc.DownloadFileAsync(new System.Uri(url), "./out/" + rating + FilenameFromUrl(url));
wc.DownloadFileTaskAsync(new System.Uri(url), "./out/" + rating + FilenameFromUrl(url)).Wait();
else
await wc.DownloadFileTaskAsync(new System.Uri(url), "./out/" + fullpath + extension);
wc.DownloadFileTaskAsync(new System.Uri(url), "./out/" + fullpath + extension).Wait();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), ex.GetType().ToString());
wc.DownloadFileAsync(new System.Uri(url), "./out/" + rating + FilenameFromUrl(url));
//wc.DownloadFileAsync(new System.Uri(url), "./out/" + rating + FilenameFromUrl(url));
}
}
}
Expand All @@ -75,10 +76,7 @@ public override string DownloadPosts(string domain, string tags, int page, bool
ServicePointManager.DefaultConnectionLimit = 9999;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

string apiKey = "";
string login = "";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(domain + "/posts.xml?page=dapi&s=post&q=index&limit=1&tags=" + tags + "&page=" + page + "&api_key=" + apiKey + "&login=" + login);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(domain + "/posts.xml?page=dapi&s=post&q=index&limit=1&tags=" + tags + "&page=" + page + "&api_key=" + this.apiKey + "&login=" + this.login);
request.UserAgent = ".NET Framework Test Client";
request.Accept = "text/xml";
//request.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:88.0) Gecko/20100101 Firefox/88.0";
Expand Down Expand Up @@ -125,10 +123,7 @@ public override int GetPostCount(string domain, string tags)
ServicePointManager.DefaultConnectionLimit = 9999;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

string apiKey = "";
string login = "";

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(domain + "/posts.xml?page=dapi&s=post&q=index&tags=" + tags + "&api_key=" + apiKey + "&login=" + login);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(domain + "/posts.xml?page=dapi&s=post&q=index&tags=" + tags + "&api_key=" + this.apiKey + "&login=" + this.login);
request.UserAgent = ".NET Framework Test Client";
request.Accept = "text/xml";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Expand Down
12 changes: 12 additions & 0 deletions EngineBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ public abstract class EngineBase
public string url;
public string rating;

protected string apiKey;
protected string login;

public enum type
{
DAN = 0,
Expand All @@ -27,5 +30,14 @@ public enum type
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;
}
}
}
54 changes: 49 additions & 5 deletions Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ private async void downloadButton_Click(object sender, EventArgs e)
else
engine = new GelEngine();
}

engine.SetApiKey(apiKeyTextBox.Text);
engine.SetLogin(loginTextBox.Text);

int postCount = engine.GetPostCount(domainBox.Text, tagsBox.Text);
alreadyDownloaded = 0;
Console.WriteLine(postCount);
if (postCount == 0)
{
Expand All @@ -91,7 +96,7 @@ private async void downloadButton_Click(object sender, EventArgs e)
{
limitBoxText = int.Parse(limitBox.Text);
}
catch (Exception e1)
catch (Exception)
{
limitBox.Text = "999";
limitBoxText = 999;
Expand Down
6 changes: 3 additions & 3 deletions GelEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public override int GetPostCount(string domain, string tags)
ServicePointManager.DefaultConnectionLimit = 9999;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(domain + "/index.php?page=dapi&s=post&q=index&limit=1&tags=" + tags);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(domain + "/index.php?page=dapi&s=post&q=index&limit=1&tags=" + tags + "&api_key=" + this.apiKey + "&user_id=" + this.login);
request.UserAgent = ".NET Framework Test Client";
request.Accept = "text/xml";
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Expand All @@ -102,7 +102,7 @@ public override string DownloadPosts(string domain, string tags, int page, bool
ServicePointManager.DefaultConnectionLimit = 9999;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3;

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(domain + "/index.php?page=dapi&s=post&q=index&limit=1&tags=" + tags + "&pid=" + page);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(domain + "/index.php?page=dapi&s=post&q=index&limit=1&tags=" + tags + "&pid=" + page + "&api_key=" + this.apiKey + "&user_id=" + this.login);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (Stream stream = response.GetResponseStream())
{
Expand Down Expand Up @@ -138,6 +138,6 @@ public override string DownloadPosts(string domain, string tags, int page, bool
DownloadImage(url, postTags, keepOriginalNames, rating);
}
return url;
}
}
}
}

0 comments on commit ebd21d5

Please sign in to comment.