forked from sim0n00ps/OF-DL
Compare commits
2 Commits
ae5ce7e491
...
7201fe9ddf
| Author | SHA1 | Date | |
|---|---|---|---|
| 7201fe9ddf | |||
| 38722bd4d2 |
@ -1,10 +1,14 @@
|
||||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
AnsiConsole.Write(new FigletText("Welcome to OF-DL").Color(Color.Red));
|
||||
|
||||
ServiceCollection services = await ConfigureServices(args);
|
||||
ServiceProvider serviceProvider = services.BuildServiceProvider();
|
||||
|
||||
ExitIfOtherProcess(serviceProvider);
|
||||
|
||||
AnsiConsole.Write(new FigletText("Welcome to OF-DL").Color(Color.Red));
|
||||
|
||||
Worker worker = serviceProvider.GetRequiredService<Worker>();
|
||||
await worker.RunAsync();
|
||||
|
||||
@ -149,3 +153,23 @@ static bool ParseCommandlineArgs(string[] args, Config currentConfig, out Cajeta
|
||||
}
|
||||
}
|
||||
|
||||
static void ExitIfOtherProcess(ServiceProvider serviceProvider)
|
||||
{
|
||||
Assembly? entryAssembly = Assembly.GetEntryAssembly();
|
||||
AssemblyName? entryAssemblyName = entryAssembly?.GetName();
|
||||
|
||||
if (entryAssemblyName?.Name is null)
|
||||
return;
|
||||
|
||||
Process thisProcess = Process.GetCurrentProcess();
|
||||
Process[] otherProcesses = [.. Process.GetProcessesByName(entryAssemblyName.Name).Where(p => p.Id != thisProcess.Id)];
|
||||
|
||||
if (otherProcesses.Length <= 0)
|
||||
return;
|
||||
|
||||
AnsiConsole.Markup($"[green]Other OF DL process detected, exiting..\n[/]");
|
||||
Log.Warning("Other OF DL process detected, exiting..");
|
||||
|
||||
serviceProvider.GetRequiredService<ExitHelper>().ExitWithCode(0);
|
||||
}
|
||||
|
||||
|
||||
@ -17,6 +17,8 @@ public class CreatorDownloadResult
|
||||
public int MessagesCount { get; set; }
|
||||
|
||||
public int PaidMessagesCount { get; set; }
|
||||
|
||||
public CreatorDownloadResult? NewDownloads { get; set; }
|
||||
}
|
||||
|
||||
public class UserListResult
|
||||
|
||||
@ -160,6 +160,7 @@ public class DownloadOrchestrationService(
|
||||
{
|
||||
Config config = configService.CurrentConfig;
|
||||
CreatorDownloadResult counts = new();
|
||||
CreatorDownloadResult newCounts = new();
|
||||
|
||||
eventHandler.OnUserStarting(username);
|
||||
Log.Debug($"Scraping Data for {username}");
|
||||
@ -185,7 +186,8 @@ public class DownloadOrchestrationService(
|
||||
posts => posts.PaidPosts.Values.ToList(),
|
||||
async (posts, reporter) => await downloadService.DownloadPaidPosts(username, userId, path, users,
|
||||
clientIdBlobMissing, devicePrivateKeyMissing, posts, reporter),
|
||||
eventHandler);
|
||||
eventHandler,
|
||||
n => newCounts.PaidPostCount = n);
|
||||
}
|
||||
|
||||
if (config.DownloadPosts)
|
||||
@ -202,7 +204,8 @@ public class DownloadOrchestrationService(
|
||||
posts => posts.Posts.Values.ToList(),
|
||||
async (posts, reporter) => await downloadService.DownloadFreePosts(username, userId, path, users,
|
||||
clientIdBlobMissing, devicePrivateKeyMissing, posts, reporter),
|
||||
eventHandler);
|
||||
eventHandler,
|
||||
n => newCounts.PostCount = n);
|
||||
}
|
||||
|
||||
if (config.DownloadArchived)
|
||||
@ -215,7 +218,8 @@ public class DownloadOrchestrationService(
|
||||
archived => archived.ArchivedPosts.Values.ToList(),
|
||||
async (archived, reporter) => await downloadService.DownloadArchived(username, userId, path, users,
|
||||
clientIdBlobMissing, devicePrivateKeyMissing, archived, reporter),
|
||||
eventHandler);
|
||||
eventHandler,
|
||||
n => newCounts.ArchivedCount = n);
|
||||
}
|
||||
|
||||
if (config.DownloadStreams)
|
||||
@ -228,7 +232,8 @@ public class DownloadOrchestrationService(
|
||||
streams => streams.Streams.Values.ToList(),
|
||||
async (streams, reporter) => await downloadService.DownloadStreams(username, userId, path, users,
|
||||
clientIdBlobMissing, devicePrivateKeyMissing, streams, reporter),
|
||||
eventHandler);
|
||||
eventHandler,
|
||||
n => newCounts.StreamsCount = n);
|
||||
}
|
||||
|
||||
if (config.DownloadStories)
|
||||
@ -252,6 +257,7 @@ public class DownloadOrchestrationService(
|
||||
|
||||
eventHandler.OnDownloadComplete("Stories", result);
|
||||
counts.StoriesCount = result.TotalCount;
|
||||
newCounts.StoriesCount = result.NewDownloads;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -280,6 +286,7 @@ public class DownloadOrchestrationService(
|
||||
|
||||
eventHandler.OnDownloadComplete("Highlights", result);
|
||||
counts.HighlightsCount = result.TotalCount;
|
||||
newCounts.HighlightsCount = result.NewDownloads;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -297,7 +304,8 @@ public class DownloadOrchestrationService(
|
||||
messages => messages.Messages.Values.ToList(),
|
||||
async (messages, reporter) => await downloadService.DownloadMessages(username, userId, path, users,
|
||||
clientIdBlobMissing, devicePrivateKeyMissing, messages, reporter),
|
||||
eventHandler);
|
||||
eventHandler,
|
||||
n => newCounts.MessagesCount = n);
|
||||
}
|
||||
|
||||
if (config.DownloadPaidMessages)
|
||||
@ -310,10 +318,13 @@ public class DownloadOrchestrationService(
|
||||
paidMessages => paidMessages.PaidMessages.Values.ToList(),
|
||||
async (paidMessages, reporter) => await downloadService.DownloadPaidMessages(username, path, users,
|
||||
clientIdBlobMissing, devicePrivateKeyMissing, paidMessages, reporter),
|
||||
eventHandler);
|
||||
eventHandler,
|
||||
n => newCounts.PaidMessagesCount = n);
|
||||
}
|
||||
|
||||
eventHandler.OnUserComplete(username, counts);
|
||||
|
||||
counts.NewDownloads = newCounts;
|
||||
return counts;
|
||||
}
|
||||
|
||||
@ -612,7 +623,8 @@ public class DownloadOrchestrationService(
|
||||
Func<T, int> getObjectCount,
|
||||
Func<T, List<string>?> getUrls,
|
||||
Func<T, IProgressReporter, Task<DownloadResult>> downloadData,
|
||||
IDownloadEventHandler eventHandler)
|
||||
IDownloadEventHandler eventHandler,
|
||||
Action<int>? newPostAssignmentAction)
|
||||
{
|
||||
T data = await eventHandler.WithStatusAsync($"Getting {contentType}",
|
||||
async statusReporter => await fetchData(statusReporter));
|
||||
@ -643,6 +655,8 @@ public class DownloadOrchestrationService(
|
||||
Log.Debug(
|
||||
$"{contentType} Already Downloaded: {result.ExistingDownloads} New {contentType} Downloaded: {result.NewDownloads}");
|
||||
|
||||
newPostAssignmentAction?.Invoke(result.NewDownloads);
|
||||
|
||||
return result.TotalCount;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user