Compare commits

..

4 Commits

View File

@ -83,7 +83,8 @@ public class Program
AnsiConsole.MarkupLine($"[red]Press any key to exit.[/]");
Log.Error(e, "auth invalid after attempt to get auth from browser");
Environment.Exit(2);
Log.CloseAndFlush();
Environment.Exit(2);
}
if (auth == null)
@ -95,7 +96,8 @@ public class Program
AnsiConsole.MarkupLine($"[red]Press any key to exit.[/]");
Log.Error("auth invalid after attempt to get auth from browser");
Environment.Exit(2);
Log.CloseAndFlush();
Environment.Exit(2);
}
else
{
@ -117,7 +119,7 @@ public class Program
.Enrich.WithProperty("StartTime", $"{DateTime.Now:yyyy-MM-dd HH:mm:ss} ")
.Enrich.WithProperty("MachineName", Environment.MachineName)
.MinimumLevel.ControlledBy(levelSwitch)
.WriteTo.File("logs/OFDL.txt", rollingInterval: RollingInterval.Day)
.WriteTo.File("logs/OFDL.txt", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Error)
.WriteTo.Seq("https://seq.cajetan.dk")
.CreateLogger();
@ -244,6 +246,8 @@ public class Program
{
Console.ReadKey();
}
Log.CloseAndFlush();
Environment.Exit(3);
}
}
@ -373,7 +377,9 @@ public class Program
{
Console.ReadKey();
}
Environment.Exit(3);
Log.CloseAndFlush();
Environment.Exit(3);
}
}
else
@ -482,7 +488,9 @@ public class Program
{
Console.ReadKey();
}
Environment.Exit(3);
Log.CloseAndFlush();
Environment.Exit(3);
}
@ -498,6 +506,8 @@ public class Program
config.NonInteractiveMode = true;
Log.Logger = Log.Logger.ForContext("Mode", "NonInteractiveMode");
int indexOfSpecificListsArg = Array.FindIndex(args, a => a.Contains(SPECIFIC_LISTS_ARG, StringComparison.OrdinalIgnoreCase));
int indexOfSpecificUsersArg = Array.FindIndex(args, a => a.Contains(SPECIFIC_USERS_ARG, StringComparison.OrdinalIgnoreCase));
char[] separator = [','];
@ -511,6 +521,8 @@ public class Program
{
config.NonInteractiveSpecificLists = strListValues;
config.NonInteractiveModeListName = string.Empty;
Log.Logger = Log.Logger.ForContext("NonInteractiveSpecificLists", string.Join(",", strListValues));
}
}
@ -521,6 +533,8 @@ public class Program
if (strUserValues.Length > 0)
{
config.NonInteractiveSpecificUsers = strUserValues;
Log.Logger = Log.Logger.ForContext("NonInteractiveSpecificUsers", string.Join(",", strUserValues));
}
}
}
@ -531,6 +545,8 @@ public class Program
{
config.NonInteractiveMode = true;
config.OutputBlockedUsers = true;
Log.Logger = Log.Logger.ForContext("Mode", "OutputBlockedUsers");
}
const string UPDATE_ALL_USER_INFO_ARG = "--update-userinfo";
@ -539,6 +555,8 @@ public class Program
{
config.NonInteractiveMode = true;
config.UpdateAllUserInfo = true;
Log.Logger = Log.Logger.ForContext("Mode", "UpdateAllUserInfo");
}
Log.Debug("Additional arguments:");
@ -566,7 +584,9 @@ public class Program
{
Console.ReadKey();
}
Environment.Exit(1);
Log.CloseAndFlush();
Environment.Exit(1);
}
else
{
@ -649,7 +669,8 @@ public class Program
AnsiConsole.MarkupLine($"[red]Press any key to exit.[/]");
Console.ReadKey();
Environment.Exit(2);
Log.CloseAndFlush();
Environment.Exit(2);
}
@ -665,6 +686,7 @@ public class Program
AnsiConsole.MarkupLine($"[red]Press any key to exit.[/]");
Console.ReadKey();
Log.CloseAndFlush();
Environment.Exit(2);
}
}
@ -679,7 +701,8 @@ public class Program
AnsiConsole.MarkupLine($"[red]Press any key to exit.[/]");
Console.ReadKey();
Environment.Exit(2);
Log.CloseAndFlush();
Environment.Exit(2);
}
if (!config!.DisableBrowserAuth)
@ -694,6 +717,7 @@ public class Program
AnsiConsole.MarkupLine($"[red]Press any key to exit.[/]");
Console.ReadKey();
Log.CloseAndFlush();
Environment.Exit(2);
}
}
@ -723,7 +747,9 @@ public class Program
{
Console.ReadKey();
}
Environment.Exit(2);
Log.CloseAndFlush();
Environment.Exit(2);
}
}
@ -811,7 +837,9 @@ public class Program
{
Console.ReadKey();
}
Environment.Exit(4);
Log.CloseAndFlush();
Environment.Exit(4);
}
if (!File.Exists(Path.Join(WidevineClient.Widevine.Constants.DEVICES_FOLDER, WidevineClient.Widevine.Constants.DEVICE_NAME, "device_client_id_blob")))
@ -867,9 +895,12 @@ public class Program
{
AnsiConsole.MarkupLine($"\n[red]Auth failed. Please try again or use other authentication methods detailed here:[/]\n");
AnsiConsole.MarkupLine($"[link]https://docs.ofdl.tools/config/auth[/]\n");
Console.ReadKey();
Console.ReadKey();
Log.CloseAndFlush();
Environment.Exit(2);
}
}
}
Log.Information("Logged In successfully as {Name:l} ({Username:l})", validate.name, validate.username);
@ -910,6 +941,7 @@ public class Program
{
Console.ReadKey();
}
Log.CloseAndFlush();
Environment.Exit(5);
}
@ -986,10 +1018,12 @@ public class Program
using (LogContext.PushProperty("Username", username))
using (LogContext.PushProperty("UserId", userId))
using (LogContext.PushProperty("UserNum", prevValue+1))
using (LogContext.PushProperty("UserTotal", users.Count))
{
try
{
Log.Information("Updating User Info for for: {Username:l}");
Log.Information("[{UserNum:0} of {UserTotal}] Updating User Info for for: {Username:l}");
User? user_info = await m_ApiHelper.GetUserInfo(username, $"/users/{username}");
await dbHelper.UpdateUserInfo(username, user_info);
@ -997,7 +1031,7 @@ public class Program
}
catch (Exception ex)
{
Log.Warning(ex, "Failed to update User Info for: {Username:l}");
Log.Warning(ex, "[{UserNum:0} of {UserTotal}] Failed to update User Info for: {Username:l}");
AnsiConsole.Markup($"[red]Failed to update User Info for '{username}'\n[/]");
updateTask.Description = $"{description} - FAILED: {ex.Message}";
@ -1355,6 +1389,15 @@ public class Program
}
else if (hasSelectedUsersKVP.Key && !hasSelectedUsersKVP.Value.ContainsKey("ConfigChanged"))
{
int totalNewPaidPostCount = 0;
int totalNewPostCount = 0;
int totalNewArchivedCount = 0;
int totalNewStreamsCount = 0;
int totalNewStoriesCount = 0;
int totalNewHighlightsCount = 0;
int totalNewMessagesCount = 0;
int totalNewPaidMessagesCount = 0;
//Iterate over each user in the list of users
int userNum = 0;
int userCount = hasSelectedUsersKVP.Value.Count;
@ -1425,44 +1468,52 @@ public class Program
if (Config.DownloadPaidPosts)
{
(paidPostCount, newPaidPostCount) = await DownloadPaidPosts(downloadContext, hasSelectedUsersKVP, user, paidPostCount, path);
totalNewPaidPostCount += newPaidPostCount;
}
if (Config.DownloadPosts)
{
(postCount, newPostCount) = await DownloadFreePosts(downloadContext, hasSelectedUsersKVP, user, postCount, path);
}
totalNewPostCount += newPostCount;
}
if (Config.DownloadArchived)
if (Config.DownloadArchived)
{
(archivedCount, newArchivedCount) = await DownloadArchived(downloadContext, hasSelectedUsersKVP, user, archivedCount, path);
}
totalNewArchivedCount += newArchivedCount;
}
if (Config.DownloadStreams)
if (Config.DownloadStreams)
{
(streamsCount, newStreamsCount) = await DownloadStreams(downloadContext, hasSelectedUsersKVP, user, streamsCount, path);
}
totalNewStreamsCount += newStreamsCount;
}
if (Config.DownloadStories)
if (Config.DownloadStories)
{
(storiesCount, newStoriesCount) = await DownloadStories(downloadContext, user, storiesCount, path);
}
totalNewStoriesCount += newStoriesCount;
}
if (Config.DownloadHighlights)
if (Config.DownloadHighlights)
{
(highlightsCount, newHighlightsCount) = await DownloadHighlights(downloadContext, user, highlightsCount, path);
}
totalNewHighlightsCount += newHighlightsCount;
}
if (Config.DownloadMessages)
if (Config.DownloadMessages)
{
(messagesCount, newMessagesCount) = await DownloadMessages(downloadContext, hasSelectedUsersKVP, user, messagesCount, path);
}
totalNewMessagesCount += newMessagesCount;
}
if (Config.DownloadPaidMessages)
if (Config.DownloadPaidMessages)
{
(paidMessagesCount, newPaidMessagesCount) = await DownloadPaidMessages(downloadContext, hasSelectedUsersKVP, user, paidMessagesCount, path);
}
totalNewPaidMessagesCount += newPaidMessagesCount;
}
AnsiConsole.Markup("\n");
AnsiConsole.Markup("\n");
AnsiConsole.Write(new BreakdownChart()
.FullSize()
.AddItem("Paid Posts", paidPostCount, Color.Red)
@ -1491,7 +1542,15 @@ public class Program
DateTime endTime = DateTime.Now;
TimeSpan totalTime = endTime - startTime;
Log.Information("Scrape Completed in {TotalMinutes:0.00} minutes", totalTime.TotalMinutes);
Log.ForContext("Paid Posts", totalNewPaidPostCount)
.ForContext("Posts", totalNewPostCount)
.ForContext("Archived", totalNewArchivedCount)
.ForContext("Streams", totalNewStreamsCount)
.ForContext("Stories", totalNewStoriesCount)
.ForContext("Highlights", totalNewHighlightsCount)
.ForContext("Messages", totalNewMessagesCount)
.ForContext("Paid Messages", totalNewPaidMessagesCount)
.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"))