Compare commits

..

2 Commits

3 changed files with 44 additions and 27 deletions

View File

@ -893,7 +893,7 @@ public class APIHelper : IAPIHelper
}
public async Task<PaidPostCollection> GetPaidPosts(string endpoint, string folder, string username, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx)
public async Task<PaidPostCollection> GetPaidPosts(string endpoint, string folder, string username, int userId, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx)
{
Log.Debug($"Calling GetPaidPosts - {username}");
@ -902,12 +902,14 @@ public class APIHelper : IAPIHelper
Purchased paidPosts = new();
PaidPostCollection paidPostCollection = new();
int post_limit = 50;
int offset = 0;
Dictionary<string, string> getParams = new()
{
{ "limit", post_limit.ToString() },
{ "order", "publish_date_desc" },
{ "skip_users", "all" },
{ "format", "infinite" },
{ "user_id", username }
{ "offset", offset.ToString() },
{ "author", username },
};
var body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config));
@ -917,9 +919,10 @@ public class APIHelper : IAPIHelper
ctx.SpinnerStyle(Style.Parse("blue"));
if (paidPosts != null && paidPosts.hasMore)
{
getParams["offset"] = paidPosts.list.Count.ToString();
while (true)
{
offset += post_limit;
getParams["offset"] = offset.ToString();
Purchased newPaidPosts = new();
@ -934,7 +937,6 @@ public class APIHelper : IAPIHelper
{
break;
}
getParams["offset"] = Convert.ToString(Convert.ToInt32(getParams["offset"]) + post_limit);
}
}
@ -943,6 +945,9 @@ public class APIHelper : IAPIHelper
{
if (purchase.responseType == "post" && purchase.media != null && purchase.media.Count > 0)
{
if (purchase.fromUser.id != userId)
continue; // Ensures only posts from current model are included
List<long> previewids = new();
if (purchase.previews != null)
{
@ -1691,7 +1696,8 @@ public class APIHelper : IAPIHelper
Dictionary<string, string> getParams = new()
{
{ "limit", post_limit.ToString() },
{ "order", "desc" }
{ "order", "desc" },
{ "skip_users", "all" },
};
var body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config));
@ -1701,9 +1707,10 @@ public class APIHelper : IAPIHelper
ctx.SpinnerStyle(Style.Parse("blue"));
if (messages.hasMore)
{
getParams["id"] = messages.list[^1].id.ToString();
while (true)
{
getParams["id"] = messages.list[^1].id.ToString();
Messages newmessages = new();
var loopbody = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config));
@ -1717,7 +1724,6 @@ public class APIHelper : IAPIHelper
{
break;
}
getParams["id"] = newmessages.list[newmessages.list.Count - 1].id.ToString();
}
}
@ -1993,7 +1999,7 @@ public class APIHelper : IAPIHelper
}
public async Task<PaidMessageCollection> GetPaidMessages(string endpoint, string folder, string username, IDownloadConfig config, StatusContext ctx)
public async Task<PaidMessageCollection> GetPaidMessages(string endpoint, string folder, string username, int userId, IDownloadConfig config, StatusContext ctx)
{
Log.Debug($"Calling GetPaidMessages - {username}");
@ -2002,12 +2008,14 @@ public class APIHelper : IAPIHelper
Purchased paidMessages = new();
PaidMessageCollection paidMessageCollection = new();
int post_limit = 50;
int offset = 0;
Dictionary<string, string> getParams = new()
{
{ "limit", post_limit.ToString() },
{ "order", "publish_date_desc" },
{ "skip_users", "all" },
{ "format", "infinite" },
{ "user_id", username }
{ "offset", offset.ToString() },
{ "author", username },
};
var body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config));
@ -2017,9 +2025,11 @@ public class APIHelper : IAPIHelper
ctx.SpinnerStyle(Style.Parse("blue"));
if (paidMessages != null && paidMessages.hasMore)
{
getParams["offset"] = paidMessages.list.Count.ToString();
while (true)
{
offset += post_limit;
getParams["offset"] = offset.ToString();
string loopqueryParams = "?" + string.Join("&", getParams.Select(kvp => $"{kvp.Key}={kvp.Value}"));
Purchased newpaidMessages = new();
Dictionary<string, string> loopheaders = GetDynamicHeaders("/api2/v2" + endpoint, loopqueryParams);
@ -2031,12 +2041,14 @@ public class APIHelper : IAPIHelper
{
looprequest.Headers.Add(keyValuePair.Key, keyValuePair.Value);
}
using (var loopresponse = await loopclient.SendAsync(looprequest))
{
loopresponse.EnsureSuccessStatusCode();
var loopbody = await loopresponse.Content.ReadAsStringAsync();
newpaidMessages = JsonConvert.DeserializeObject<Purchased>(loopbody, m_JsonSerializerSettings);
}
paidMessages.list.AddRange(newpaidMessages.list);
ctx.Status($"[red]Getting Paid Messages\n[/] [red]Found {paidMessages.list.Count}[/]");
ctx.Spinner(Spinner.Known.Dots);
@ -2045,16 +2057,21 @@ public class APIHelper : IAPIHelper
{
break;
}
getParams["offset"] = Convert.ToString(Convert.ToInt32(getParams["offset"]) + post_limit);
}
}
if (paidMessages.list != null && paidMessages.list.Count > 0)
{
int ownUserId = Convert.ToInt32(auth.USER_ID);
int[] validUserIds = [ownUserId, userId];
foreach (Purchased.List purchase in paidMessages.list.Where(p => p.responseType == "message").OrderByDescending(p => p.postedAt ?? p.createdAt))
{
if (!config.IgnoreOwnMessages || purchase.fromUser.id != Convert.ToInt32(auth.USER_ID))
if (!config.IgnoreOwnMessages || purchase.fromUser.id != ownUserId)
{
if (!validUserIds.Contains(purchase.fromUser.id))
continue; // Ensures only messages from current model (or self) are included
if (purchase.postedAt != null)
{
await m_DBHelper.AddMessage(folder, purchase.id, purchase.text != null ? purchase.text : string.Empty, purchase.price != null ? purchase.price : "0", true, false, purchase.postedAt.Value, purchase.fromUser.id);

View File

@ -20,13 +20,13 @@ namespace OF_DL.Helpers
Task<List<string>> GetListUsers(string endpoint, IDownloadConfig config);
Task<Dictionary<string, int>?> GetUsersFromList(string endpoint, bool includeRestricted, IDownloadConfig config);
Task<Dictionary<long, string>> GetMedia(MediaType mediatype, string endpoint, string? username, string folder, IDownloadConfig config, List<long> paid_post_ids);
Task<PaidPostCollection> GetPaidPosts(string endpoint, string folder, string username, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx);
Task<PaidPostCollection> GetPaidPosts(string endpoint, string folder, string username, int userId, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx);
Task<PostCollection> GetPosts(string endpoint, string folder, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx);
Task<SinglePostCollection> GetPost(string endpoint, string folder, IDownloadConfig config);
Task<StreamsCollection> GetStreams(string endpoint, string folder, IDownloadConfig config, List<long> paid_post_ids, StatusContext ctx);
Task<ArchivedCollection> GetArchived(string endpoint, string folder, IDownloadConfig config, StatusContext ctx);
Task<MessageCollection> GetMessages(string endpoint, string folder, IDownloadConfig config, StatusContext ctx);
Task<PaidMessageCollection> GetPaidMessages(string endpoint, string folder, string username, IDownloadConfig config, StatusContext ctx);
Task<PaidMessageCollection> GetPaidMessages(string endpoint, string folder, string username, int userId, IDownloadConfig config, StatusContext ctx);
Task<Dictionary<string, int>> GetPurchasedTabUsers(string endpoint, IDownloadConfig config, Dictionary<string, int> users);
Task<List<PurchasedTabCollection>> GetPurchasedTab(string endpoint, string folder, IDownloadConfig config, Dictionary<string, int> users);
Task<User> GetUserInfo(string endpoint);

View File

@ -1356,15 +1356,15 @@ public class Program
AnsiConsole.Markup("\n");
AnsiConsole.Write(new BreakdownChart()
.FullSize()
.AddItem("Paid Posts", paidPostCount, Color.Red)
.AddItem("Posts", postCount, Color.Blue)
.AddItem("Archived", archivedCount, Color.Green)
.AddItem("Streams", streamsCount, Color.Purple)
.AddItem("Stories", storiesCount, Color.Yellow)
.AddItem("Highlights", highlightsCount, Color.Orange1)
.AddItem("Messages", messagesCount, Color.LightGreen)
.AddItem("Paid Messages", paidMessagesCount, Color.Aqua));
.FullSize()
.AddItem("Paid Posts", paidPostCount, Color.Red)
.AddItem("Posts", postCount, Color.Blue)
.AddItem("Archived", archivedCount, Color.Green)
.AddItem("Streams", streamsCount, Color.Purple)
.AddItem("Stories", storiesCount, Color.Yellow)
.AddItem("Highlights", highlightsCount, Color.Orange1)
.AddItem("Messages", messagesCount, Color.LightGreen)
.AddItem("Paid Messages", paidMessagesCount, Color.Aqua));
AnsiConsole.Markup("\n");
}
DateTime endTime = DateTime.Now;
@ -1428,7 +1428,7 @@ public class Program
await AnsiConsole.Status()
.StartAsync("[red]Getting Paid Messages[/]", async ctx =>
{
paidMessageCollection = await downloadContext.ApiHelper.GetPaidMessages("/posts/paid", path, user.Key, downloadContext.DownloadConfig!, ctx);
paidMessageCollection = await downloadContext.ApiHelper.GetPaidMessages("/posts/paid/chat", path, user.Key, user.Value, downloadContext.DownloadConfig!, ctx);
});
int oldPaidMessagesCount = 0;
int newPaidMessagesCount = 0;
@ -2091,7 +2091,7 @@ public class Program
await AnsiConsole.Status()
.StartAsync("[red]Getting Paid Posts[/]", async ctx =>
{
purchasedPosts = await downloadContext.ApiHelper.GetPaidPosts("/posts/paid", path, user.Key, downloadContext.DownloadConfig!, paid_post_ids, ctx);
purchasedPosts = await downloadContext.ApiHelper.GetPaidPosts("/posts/paid/post", path, user.Key, user.Value, downloadContext.DownloadConfig!, paid_post_ids, ctx);
});
int oldPaidPostCount = 0;