Compare commits

..

16 Commits

7 changed files with 46 additions and 43 deletions

3
.gitignore vendored
View File

@ -376,4 +376,5 @@ venv/
/site
# Cajetan
.dev/
.dev/
*Publish/

View File

@ -21,7 +21,7 @@ public class CajetanDownloadEventHandler : ICajetanDownloadEventHandler
=> _eventHandler.OnMessage(message);
public void OnMessage(string message, string color)
=> AnsiConsole.Markup($"[{color.ToLowerInvariant()}]{Markup.Escape(message)}\n[/]");
=> AnsiConsole.MarkupLine($"[{color.ToLowerInvariant()}]{Markup.Escape(message)}[/]");
public void OnNoContentFound(string contentType)
=> _eventHandler.OnNoContentFound(contentType);

View File

@ -255,7 +255,7 @@ public class CajetanApiService(IAuthService authService, IConfigService configSe
Log.Debug("Calling GetAllSubscrptions");
const int limit = 30;
const int limit = 50;
int offset = 0;
Dictionary<string, string> getParams = new()
@ -321,43 +321,40 @@ public class CajetanApiService(IAuthService authService, IConfigService configSe
try
{
int limit = 60;
const int limit = 60;
int offset = 0;
Dictionary<string, string> getParams = new()
{
{ "limit", $"{limit}" },
{ "offset", "0" },
{ "skip_users", "all" },
{ "order", "recent" }
["order"] = "recent",
["skip_users"] = "all",
["filter"] = "unread",
["limit"] = $"{limit}",
};
if (onlyUnread)
getParams["filter"] = "unread";
if (onlyUnread is false)
getParams.Remove("filter");
string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient());
MessageDtos.ChatsDto? chats = DeserializeJson<MessageDtos.ChatsDto>(body, s_mJsonSerializerSettings);
if (chats is null)
return allChats;
if (chats.HasMore)
while (true)
{
getParams["offset"] = $"{chats.NextOffset}";
getParams["offset"] = $"{offset}";
while (true)
{
string? loopbody = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient());
MessageDtos.ChatsDto? newChats = DeserializeJson<MessageDtos.ChatsDto>(loopbody, s_mJsonSerializerSettings);
string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient());
if (newChats is null)
break;
if (string.IsNullOrWhiteSpace(body))
break;
allChats.List.AddRange(newChats.List);
MessageDtos.ChatsDto? chats = DeserializeJson<MessageDtos.ChatsDto>(body, s_mJsonSerializerSettings);
if (!newChats.HasMore)
break;
if (chats?.List is null)
break;
getParams["offset"] = $"{newChats.NextOffset}";
}
allChats.List.AddRange(chats.List);
if (chats.HasMore is false)
break;
offset = chats.NextOffset;
}
}
catch (Exception ex)

View File

@ -8,8 +8,7 @@ public class CajetanDbService(IConfigService configService)
public async Task InitializeUserInfoTablesAsync()
{
await using SqliteConnection connection = new($"Data Source={Directory.GetCurrentDirectory()}/users.db");
connection.Open();
await connection.OpenAsync();
using (SqliteCommand cmdInfo = new("CREATE TABLE IF NOT EXISTS user_info (user_id INTEGER NOT NULL, name VARCHAR NOT NULL, about VARCHAR NULL, expires_on TIMESTAMP NULL, photo_count INT NOT NULL, video_count INT NOT NULL, PRIMARY KEY(user_id));", connection))
{
@ -30,6 +29,7 @@ public class CajetanDbService(IConfigService configService)
public async Task<Dictionary<string, long>> GetUsersAsync()
{
await using SqliteConnection connection = new($"Data Source={Directory.GetCurrentDirectory()}/users.db");
await connection.OpenAsync();
using SqliteCommand cmd = new("SELECT user_id, username FROM users", connection);
using SqliteDataReader reader = cmd.ExecuteReader();
@ -53,6 +53,7 @@ public class CajetanDbService(IConfigService configService)
return;
await using SqliteConnection connection = new($"Data Source={Directory.GetCurrentDirectory()}/users.db");
await connection.OpenAsync();
Log.Debug("Database data source: " + connection.DataSource);
@ -115,6 +116,7 @@ public class CajetanDbService(IConfigService configService)
return;
await using SqliteConnection connection = new($"Data Source={Directory.GetCurrentDirectory()}/users.db");
await connection.OpenAsync();
Log.Debug("Database data source: " + connection.DataSource);

View File

@ -152,7 +152,11 @@ internal class Worker(IServiceProvider serviceProvider)
LoggerWithConfigContext(_configService.CurrentConfig, _cajetanConfig)
.Information("Scraping Data for {UserCount} user(s)", usersToDownload.Count);
eventHandler.OnMessage($"Scraping Data for {usersToDownload.Count} user(s)\n");
eventHandler.OnMessage(
$"\nScraping Data for {usersToDownload.Count} user(s)\n" +
$"{"======================================================================================================"}\n"
);
foreach ((string username, long userId) in usersToDownload)
{
@ -322,7 +326,7 @@ internal class Worker(IServiceProvider serviceProvider)
continue;
Log.Information("Getting Users from list '{ListName:l}' (Include Restricted: {IncludeRestrictedSubscriptions})", name, currentConfig.IncludeRestrictedSubscriptions);
AnsiConsole.Markup($"[green]Getting Users from list '{name}' (Include Restricted: {currentConfig.IncludeRestrictedSubscriptions})\n[/]");
AnsiConsole.MarkupLine($"[green]Getting Users from list '{name}' (Include Restricted: {currentConfig.IncludeRestrictedSubscriptions})[/]");
List<string> listUsernames = await _apiService.GetListUsers($"/lists/{listId}/users") ?? [];
@ -373,7 +377,7 @@ internal class Worker(IServiceProvider serviceProvider)
async Task FetchUsersAsync()
{
Log.Information("Getting Active Subscriptions (Include Restricted: {IncludeRestrictedSubscriptions})", currentConfig.IncludeRestrictedSubscriptions);
AnsiConsole.Markup($"[green]Getting Active Subscriptions (Include Restricted: {currentConfig.IncludeRestrictedSubscriptions})\n[/]");
AnsiConsole.MarkupLine($"[green]Getting Active Subscriptions (Include Restricted: {currentConfig.IncludeRestrictedSubscriptions})[/]");
Dictionary<string, long>? activeSubs = await _apiService.GetActiveSubscriptions("/subscriptions/subscribes", currentConfig.IncludeRestrictedSubscriptions);
AddToResult(activeSubs);
@ -381,7 +385,7 @@ internal class Worker(IServiceProvider serviceProvider)
if (currentConfig.IncludeExpiredSubscriptions)
{
Log.Information("Getting Expired Subscriptions (Include Restricted: {IncludeRestrictedSubscriptions})", currentConfig.IncludeRestrictedSubscriptions);
AnsiConsole.Markup($"[green]Getting Expired Subscriptions (Include Restricted: {currentConfig.IncludeRestrictedSubscriptions})\n[/]");
AnsiConsole.MarkupLine($"[green]Getting Expired Subscriptions (Include Restricted: {currentConfig.IncludeRestrictedSubscriptions})[/]");
Dictionary<string, long>? expiredSubs = await _apiService.GetExpiredSubscriptions("/subscriptions/subscribes", currentConfig.IncludeRestrictedSubscriptions);
AddToResult(expiredSubs);
@ -410,7 +414,7 @@ internal class Worker(IServiceProvider serviceProvider)
Dictionary<string, long> usersInNonNudeLists = await GetUsersFromSpecificListsAsync(result, [.. listNames]);
AnsiConsole.Markup($"[green]Updating Non-Nude collection with {usersInNonNudeLists.Count} Users[/]");
AnsiConsole.MarkupLine($"[grey]Updating Non-Nude collection with {usersInNonNudeLists.Count} Users[/]");
await _dbService.UpdateNonNudeCollectionAsync(usersInNonNudeLists);
AnsiConsole.WriteLine();

View File

@ -6,26 +6,23 @@ ECHO ==============================
ECHO == Cleaning Output ===========
ECHO ==============================
dotnet clean ".\Cajetan.OF-DL\Cajetan.OF-DL.csproj" -v minimal
DEL /Q /F ".\Publish"
DEL /Q /F ".\Cajetan.OF-DL_Publish"
ECHO.
ECHO ==============================
ECHO == Publishing Cajetan OF-DL ==
ECHO ==============================
dotnet publish ".\Cajetan.OF-DL\Cajetan.OF-DL.csproj" -o ".\Publish" -c Debug
dotnet publish ".\Cajetan.OF-DL\Cajetan.OF-DL.csproj" -o ".\Cajetan.OF-DL_Publish" -c Debug
ECHO.
ECHO ==============================
ECHO == Renaming to 'OF DL.exe' ===
ECHO ==============================
REM REN ".\Publish\Cajetan.OF-DL.exe" "OF DL.exe"
REM REN ".\Publish\Cajetan.OF-DL.pdb" "OF DL.pdb"
REN ".\Cajetan.OF-DL_Publish\Cajetan.OF-DL.exe" "OF DL.exe"
ECHO.
GOTO Exit
ECHO ==============================
ECHO == Copy to network drive? ====
ECHO ==============================
@ -34,7 +31,7 @@ CHOICE /C yn /m "Copy published files to network drive? "
IF %ERRORLEVEL%==1 (GOTO Copy) ELSE (GOTO Exit)
:Copy
xcopy .\Publish\* p:\_Utils\OF_DL /I /Y /Q /EXCLUDE:.\excludes.txt
xcopy .\Cajetan.OF-DL_Publish\* p:\_Utils\OF_DL /I /Y /Q /EXCLUDE:.\excludes.txt
:Exit
ECHO.

2
excludes.txt Normal file
View File

@ -0,0 +1,2 @@
excludes.txt
rules.json