Added additional info logging

This commit is contained in:
Casper Sparre 2025-10-08 22:07:37 +02:00
parent f3815ba993
commit af6a9818d6

View File

@ -861,7 +861,8 @@ public class Program
}
}
AnsiConsole.Markup($"[green]Logged In successfully as {validate.name} {validate.username}\n[/]");
Log.Information("Logged In successfully as {Name:l} ({Username:l})", validate.name, validate.username);
AnsiConsole.Markup($"[green]Logged In successfully as {validate.name} ({validate.username})\n[/]");
try
{
@ -942,6 +943,7 @@ public class Program
DateTime startTime = DateTime.Now;
Dictionary<string, int> users = new();
Log.Information("Getting Active Subscriptions (Include Restricted: {IncludeRestrictedSubscriptions})", Config.IncludeRestrictedSubscriptions);
AnsiConsole.Markup($"[green]Getting Active Subscriptions (Include Restricted: {Config.IncludeRestrictedSubscriptions})\n[/]");
Dictionary<string, int> subsActive = await m_ApiHelper.GetActiveSubscriptions("/subscriptions/subscribes", Config.IncludeRestrictedSubscriptions, Config) ?? [];
@ -959,6 +961,7 @@ public class Program
{
Log.Debug("Inactive Subscriptions: ");
Log.Information("Getting Expired Subscriptions (Include Restricted: {IncludeRestrictedSubscriptions})", Config.IncludeRestrictedSubscriptions);
AnsiConsole.Markup($"[green]Getting Expired Subscriptions (Include Restricted: {Config.IncludeRestrictedSubscriptions})\n[/]");
Dictionary<string, int> subsExpired = await m_ApiHelper.GetExpiredSubscriptions("/subscriptions/subscribes", Config.IncludeRestrictedSubscriptions, Config) ?? [];
@ -1003,6 +1006,7 @@ public class Program
if (!lists.TryGetValue(listName, out int listId))
continue;
Log.Information("Getting Users from list '{ListName:l}' (Include Restricted: {IncludeRestrictedSubscriptions})", listName, Config.IncludeRestrictedSubscriptions);
AnsiConsole.Markup($"[green]Getting Users from list '{listName}' (Include Restricted: {Config.IncludeRestrictedSubscriptions})\n[/]");
Dictionary<string, int> list = await m_ApiHelper.GetUsersFromList($"/lists/{listId}/users", config.IncludeRestrictedSubscriptions, Config);
@ -1026,6 +1030,7 @@ public class Program
else if (Config.NonInteractiveMode && !string.IsNullOrEmpty(Config.NonInteractiveModeListName))
{
var listId = lists[Config.NonInteractiveModeListName];
Log.Information("Getting Users from list '{ListName:l}' (Include Restricted: {IncludeRestrictedSubscriptions})", Config.NonInteractiveModeListName, Config.IncludeRestrictedSubscriptions);
AnsiConsole.Markup($"[green]Getting Users from list '{Config.NonInteractiveModeListName}' (Include Restricted: {Config.IncludeRestrictedSubscriptions})\n[/]");
users = await m_ApiHelper.GetUsersFromList($"/lists/{listId}/users", config.IncludeRestrictedSubscriptions, Config);
hasSelectedUsersKVP = new KeyValuePair<bool, Dictionary<string, int>>(true, users);
@ -1155,11 +1160,13 @@ public class Program
Log.Debug($"Download path: {p}");
List<PurchasedTabCollection> purchasedTabCollections = await m_ApiHelper.GetPurchasedTab("/posts/paid", p, Config, users);
int userNum = 1;
int userNum = 0;
int userCount = purchasedTabCollections.Count;
foreach (PurchasedTabCollection purchasedTabCollection in purchasedTabCollections)
{
AnsiConsole.Markup($"[red]\nScraping Data for {purchasedTabCollection.Username} ({userNum++} of {userCount})\n[/]");
Log.Information("Scraping Data for '{Username:l}' ({UserNum} of {UserCount})", purchasedTabCollection.Username, ++userNum, userCount);
AnsiConsole.Markup($"[red]\nScraping Data for {purchasedTabCollection.Username} ({userNum} of {userCount})\n[/]");
string path = "";
if (!string.IsNullOrEmpty(Config.DownloadPath))
{
@ -1269,8 +1276,10 @@ public class Program
else if (hasSelectedUsersKVP.Key && !hasSelectedUsersKVP.Value.ContainsKey("ConfigChanged"))
{
//Iterate over each user in the list of users
int userNum = 1;
int userNum = 0;
int userCount = hasSelectedUsersKVP.Value.Count;
LoggerWithConfigContext(config).Information("Scraping Data for {UserCount} user(s)", userCount);
foreach (KeyValuePair<string, int> user in hasSelectedUsersKVP.Value)
{
int paidPostCount = 0;
@ -1281,9 +1290,9 @@ public class Program
int highlightsCount = 0;
int messagesCount = 0;
int paidMessagesCount = 0;
AnsiConsole.Markup($"[red]\nScraping Data for {user.Key} ({userNum++} of {userCount})\n[/]");
Log.Debug($"Scraping Data for {user.Key}");
Log.Information("Scraping Data for '{Username:l}' ({UserNum} of {UserCount})", user.Key, ++userNum, userCount);
AnsiConsole.Markup($"[red]\nScraping Data for {user.Key} ({userNum} of {userCount})\n[/]");
string path = "";
if (!string.IsNullOrEmpty(Config.DownloadPath))
@ -1376,10 +1385,17 @@ public class Program
.AddItem("Messages", messagesCount, Color.LightGreen)
.AddItem("Paid Messages", paidMessagesCount, Color.Aqua));
AnsiConsole.Markup("\n");
}
Log.Information(
"Scraped Data for '{Username:l}' [P: {PostCount}] [PP: {PaidPostCount}] [M: {MessagesCount}] [PM: {PaidMessagesCount}]",
user.Key, postCount, paidPostCount, messagesCount, paidMessagesCount, storiesCount, archivedCount
);
}
DateTime endTime = DateTime.Now;
TimeSpan totalTime = endTime - startTime;
AnsiConsole.Markup($"[green]Scrape Completed in {totalTime.TotalMinutes:0.00} minutes\n[/]");
Log.Information("Scrape Completed in {TotalMinutes:0.00} minutes", totalTime.TotalMinutes);
AnsiConsole.Markup($"[green]Scrape Completed in {totalTime.TotalMinutes:0.00} minutes\n[/]");
}
else if (hasSelectedUsersKVP.Key && hasSelectedUsersKVP.Value != null && hasSelectedUsersKVP.Value.ContainsKey("ConfigChanged"))
{
@ -3468,4 +3484,25 @@ public class Program
Environment.Exit(0);
}
static ILogger LoggerWithConfigContext(Entities.Config config)
=> Log.Logger.ForContext(nameof(Entities.Config.DownloadPath), config.DownloadPath)
.ForContext(nameof(Entities.Config.DownloadPosts), config.DownloadPosts)
.ForContext(nameof(Entities.Config.DownloadPaidPosts), config.DownloadPaidPosts)
.ForContext(nameof(Entities.Config.DownloadMessages), config.DownloadMessages)
.ForContext(nameof(Entities.Config.DownloadPaidMessages), config.DownloadPaidMessages)
.ForContext(nameof(Entities.Config.DownloadStories), config.DownloadStories)
.ForContext(nameof(Entities.Config.DownloadStreams), config.DownloadStreams)
.ForContext(nameof(Entities.Config.DownloadHighlights), config.DownloadHighlights)
.ForContext(nameof(Entities.Config.DownloadArchived), config.DownloadArchived)
.ForContext(nameof(Entities.Config.DownloadAvatarHeaderPhoto), config.DownloadAvatarHeaderPhoto)
.ForContext(nameof(Entities.Config.DownloadImages), config.DownloadImages)
.ForContext(nameof(Entities.Config.DownloadVideos), config.DownloadVideos)
.ForContext(nameof(Entities.Config.DownloadAudios), config.DownloadAudios)
.ForContext(nameof(Entities.Config.IgnoreOwnMessages), config.IgnoreOwnMessages)
.ForContext(nameof(Entities.Config.DownloadPostsIncrementally), config.DownloadPostsIncrementally)
.ForContext(nameof(Entities.Config.BypassContentForCreatorsWhoNoLongerExist), config.BypassContentForCreatorsWhoNoLongerExist)
.ForContext(nameof(Entities.Config.SkipAds), config.SkipAds)
.ForContext(nameof(Entities.Config.IncludeExpiredSubscriptions), config.IncludeExpiredSubscriptions)
.ForContext(nameof(Entities.Config.IncludeRestrictedSubscriptions), config.IncludeRestrictedSubscriptions);
}