Repository navigation
Expand file tree
/
Copy pathProgram.cs
More file actions
242 lines (187 loc) · 8.54 KB
/
Copy pathProgram.cs
File metadata and controls
242 lines (187 loc) · 8.54 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
using System;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using System.Collections.Generic;
using AngleSharp;
using AngleSharp.Dom;
using Microsoft.Data.Sqlite;
using System.Threading;
// <a href="../fotos1304/bu1304x002.jpg"><img src="../fotos1304/tn_bu1304x002.jpg" hspace="0" vspace="0" border="0" width="116" height="175"></a>
// <a href="bonus015/zbon15x001.jpg"><img src="bonus015/tn_zbon15x001.jpg" hspace="0" vspace="0" border="0" width="175" height="131"></a>
class Program
{
static bool IsAlbumLink(string href)
{
//Console.WriteLine(href);
if (href == null) return false;
return href.Contains("pfoto") || href.Contains("bonus") ;
}
static bool IsFotoLink(string href)
{
//Console.WriteLine(href);
if (href == null) return false;
return href.Contains("jpg") && (href.Contains("bonus") || href.Contains("fotos"));
}
static async Task ProcessAlbumAsync(HttpClient client, string albumLink, Config appConfig, AlbumTracker tracker, SemaphoreSlim semaphore)
{
await semaphore.WaitAsync();
try
{
var albumName = albumLink.Replace(".htm", "");
if (tracker.IsProcessed(appConfig.ModelName, albumName))
{
Console.WriteLine($"Skipping already processed album: {albumName}");
return;
}
Console.WriteLine("Process Album");
var albumUrl = appConfig.MemberBaseUrl + albumLink;
var albumResponse = await client.GetAsync(albumUrl);
var albumHtml = await albumResponse.Content.ReadAsStringAsync();
var config = Configuration.Default;
var context = BrowsingContext.New(config);
var album = await context.OpenAsync(req => req.Content(albumHtml));
var imageLinks = album.QuerySelectorAll("a[href]");
foreach (var link in imageLinks)
{
var href = link.GetAttribute("href");
if (href == null)
continue;
if (!IsFotoLink(href))
continue;
await DownloadAndSaveFoto(client, href, albumName, appConfig);
}
tracker.MarkAsProcessed(appConfig.ModelName, albumName);
}
finally
{
semaphore.Release();
}
}
static async Task DownloadAndSaveFoto(HttpClient client, string href, string album, Config config)
{
var fotoUrl = config.MemberBaseUrl +href.Replace("../", "");
//Console.WriteLine("Downloading: " + fotoUrl);
var fotoResponse = await client.GetAsync(fotoUrl);
var fotoBytes = await fotoResponse.Content.ReadAsByteArrayAsync();
var fileName = href.Substring(href.LastIndexOf('/') + 1);
// can the download path implemented as a "global" property of the main-class?
var downloadPath = config.DownloadLocation + config.ModelName + "/" + album + "/";
System.IO.Directory.CreateDirectory(downloadPath);
fileName = downloadPath + fileName;
await System.IO.File.WriteAllBytesAsync(fileName, fotoBytes);
// Console.WriteLine("Saved: " + fileName);
}
static HttpClient CreateHttpClientWithCookies()
{
var handler = new HttpClientHandler
{
UseCookies = true,
CookieContainer = new CookieContainer(),
AllowAutoRedirect = true,
};
var client = new HttpClient(handler);
client.DefaultRequestHeaders.UserAgent.ParseAdd(
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Safari/605.1.15");
return client;
}
static List<string> albumLinks = new List<string>();
static List<string> fotoLinks = new List<string>();
static async Task Main()
{
var appConfig = new Config
{
//BaseUrl = "https://www.southern-charms3.com/",
//ModelName = "jessicajones",
//BaseUrl = "https://www.southern-charms.com/",
//ModelName = "kinkybootslut",
//BaseUrl = "https://www.southern-charms3.com/",
//ModelName = "alaya",
BaseUrl = "https://www.southern-charms.com/",
ModelName = "andrea",
Username = "jomannx17",
Password = "20postmannx17",
Realm = "",
RedirectUrl = "",
//DownloadLocation = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "/Downloads/AngelScraper/"
DownloadLocation = "/Volumes/4tbx/AngleScraper/",
authRoot = "auth.form",
//memberRoot = "previous.htm",
//memberRoot = "previous2.htm",
//memberRoot = "previous3.htm",
memberRoot = "members.htm"
//sidecarFile = "/Volumes/4tbx/AngleScraper/kinkybootslut/hidden_albums.txt"
};
appConfig.MemberBaseUrl = appConfig.BaseUrl + appConfig.ModelName + "/private/";
appConfig.MemberMainUrl = appConfig.MemberBaseUrl + appConfig.memberRoot;
appConfig.loginUrl = appConfig.BaseUrl + appConfig.authRoot;
var dbPath = appConfig.DownloadLocation + appConfig.ModelName + "/albums.db";
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(dbPath));
//check if the sidear file exists. If so. read the album names (they are already fullqualified path) and add them to albumLinks. This way they will be processed like normal albums, but we can control them by just editing the textfile.
if (System.IO.File.Exists(appConfig.sidecarFile))
{
var hiddenAlbums = System.IO.File.ReadAllLines(appConfig.sidecarFile);
foreach (var album in hiddenAlbums)
{
if (!string.IsNullOrWhiteSpace(album))
{
albumLinks.Add(album.Trim());
}
}
}
var tracker = new AlbumTracker(dbPath);
using var client = CreateHttpClientWithCookies();
// get the main membership site that redirects to the login page if not authenticated.
// We need some form-data from the login page.
var redirectResponse = await client.GetAsync(appConfig.MemberMainUrl);
var redirectHtml = await redirectResponse.Content.ReadAsStringAsync();
// Parse HTML with AngleSharp
var config = Configuration.Default;
var context = BrowsingContext.New(config);
var loginForm = await context.OpenAsync(req => req.Content(redirectHtml));
var inputs = loginForm.QuerySelectorAll("input");
var formData = new Dictionary<string, string>();
foreach (var input in inputs)
{
var name = input.GetAttribute("name");
if (string.IsNullOrWhiteSpace(name))
continue;
var value = input.GetAttribute("value") ?? "";
formData[name] = value;
}
formData["uid"] = appConfig.Username;
formData["pwd"] = appConfig.Password;
formData.Remove("rmb");
formData.Remove("img");
var loginContent = new FormUrlEncodedContent(formData);
var loginResponse = await client.PostAsync(appConfig.loginUrl, loginContent);
Console.WriteLine("Login status: " + loginResponse.StatusCode);
// 3. Fetch main page (authenticated)
var mainResponse = await client.GetAsync(appConfig.MemberMainUrl);
var mainHtml = await mainResponse.Content.ReadAsStringAsync();
// 4. Parse HTML with AngleSharp
//var config = Configuration.Default;
//var context = BrowsingContext.New(config);
var document = await context.OpenAsync(req => req.Content(mainHtml));
// Example: extract all links with a specific CSS selector
//var links = document.QuerySelectorAll("a.some-class");
var links = document.QuerySelectorAll("a[href]");
foreach (var link in links)
{
var href = link.GetAttribute("href");
if (href == null)
continue;
if (!IsAlbumLink(href))
continue;
albumLinks.Add(href);
}
var semaphore = new SemaphoreSlim(5);
var tasks = new List<Task>();
foreach (var albumLink in albumLinks)
{
tasks.Add(ProcessAlbumAsync(client, albumLink, appConfig, tracker, semaphore));
}
await Task.WhenAll(tasks);
Console.WriteLine("Done.");
}
}