forked from sim0n00ps/OF-DL
Attempt to correct the 'already downloaded' message when nothing has actually been downloaded successfully.
This commit is contained in:
parent
616aaef1c8
commit
29c7110521
210
OF DL/Program.cs
210
OF DL/Program.cs
@ -2689,82 +2689,66 @@ public class Program
|
||||
return;
|
||||
}
|
||||
|
||||
long totalSize = 0;
|
||||
if (downloadContext.DownloadConfig.ShowScrapeSize)
|
||||
{
|
||||
totalSize = await downloadContext.DownloadHelper.CalculateTotalFileSize(post.SinglePosts.Values.ToList());
|
||||
}
|
||||
else
|
||||
{
|
||||
totalSize = post.SinglePosts.Count;
|
||||
}
|
||||
bool isNew = false;
|
||||
await AnsiConsole.Progress()
|
||||
.Columns(GetProgressColumns(downloadContext.DownloadConfig.ShowScrapeSize))
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
var task = ctx.AddTask($"[red]Downloading Post[/]", autoStart: false);
|
||||
task.MaxValue = totalSize;
|
||||
task.StartTask();
|
||||
foreach (KeyValuePair<long, string> postKVP in post.SinglePosts)
|
||||
long totalSize = 0;
|
||||
if (downloadContext.DownloadConfig.ShowScrapeSize)
|
||||
{
|
||||
if (postKVP.Value.Contains("cdn3.onlyfans.com/dash/files"))
|
||||
totalSize = await downloadContext.DownloadHelper.CalculateTotalFileSize(post.SinglePosts.Values.ToList());
|
||||
}
|
||||
else
|
||||
{
|
||||
totalSize = post.SinglePosts.Count;
|
||||
}
|
||||
|
||||
bool anyNew = false;
|
||||
bool anyExisting = false;
|
||||
bool anyFailed = false;
|
||||
await AnsiConsole.Progress()
|
||||
.Columns(GetProgressColumns(downloadContext.DownloadConfig.ShowScrapeSize))
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
var task = ctx.AddTask($"[red]Downloading Post[/]", autoStart: false);
|
||||
task.MaxValue = totalSize;
|
||||
task.StartTask();
|
||||
foreach (KeyValuePair<long, string> postKVP in post.SinglePosts)
|
||||
{
|
||||
string[] messageUrlParsed = postKVP.Value.Split(',');
|
||||
string mpdURL = messageUrlParsed[0];
|
||||
string policy = messageUrlParsed[1];
|
||||
string signature = messageUrlParsed[2];
|
||||
string kvp = messageUrlParsed[3];
|
||||
string mediaId = messageUrlParsed[4];
|
||||
string postId = messageUrlParsed[5];
|
||||
string? licenseURL = null;
|
||||
string? pssh = await downloadContext.ApiHelper.GetDRMMPDPSSH(mpdURL, policy, signature, kvp);
|
||||
if (pssh == null)
|
||||
if (postKVP.Value.Contains("cdn3.onlyfans.com/dash/files"))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
string[] messageUrlParsed = postKVP.Value.Split(',');
|
||||
string mpdURL = messageUrlParsed[0];
|
||||
string policy = messageUrlParsed[1];
|
||||
string signature = messageUrlParsed[2];
|
||||
string kvp = messageUrlParsed[3];
|
||||
string mediaId = messageUrlParsed[4];
|
||||
string postId = messageUrlParsed[5];
|
||||
string? licenseURL = null;
|
||||
string? pssh = await downloadContext.ApiHelper.GetDRMMPDPSSH(mpdURL, policy, signature, kvp);
|
||||
if (pssh == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
DateTime lastModified = await downloadContext.ApiHelper.GetDRMMPDLastModified(mpdURL, policy, signature, kvp);
|
||||
Dictionary<string, string> drmHeaders = downloadContext.ApiHelper.GetDynamicHeaders($"/api2/v2/users/media/{mediaId}/drm/post/{postId}", "?type=widevine");
|
||||
string decryptionKey;
|
||||
if (clientIdBlobMissing || devicePrivateKeyMissing)
|
||||
{
|
||||
decryptionKey = await downloadContext.ApiHelper.GetDecryptionKeyOFDL(drmHeaders, $"https://onlyfans.com/api2/v2/users/media/{mediaId}/drm/post/{postId}?type=widevine", pssh);
|
||||
}
|
||||
else
|
||||
{
|
||||
decryptionKey = await downloadContext.ApiHelper.GetDecryptionKeyCDM(drmHeaders, $"https://onlyfans.com/api2/v2/users/media/{mediaId}/drm/post/{postId}?type=widevine", pssh);
|
||||
}
|
||||
SinglePost.Medium mediaInfo = post.SinglePostMedia.FirstOrDefault(m => m.id == postKVP.Key);
|
||||
SinglePost postInfo = post.SinglePostObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true);
|
||||
DateTime lastModified = await downloadContext.ApiHelper.GetDRMMPDLastModified(mpdURL, policy, signature, kvp);
|
||||
Dictionary<string, string> drmHeaders = downloadContext.ApiHelper.GetDynamicHeaders($"/api2/v2/users/media/{mediaId}/drm/post/{postId}", "?type=widevine");
|
||||
string decryptionKey;
|
||||
if (clientIdBlobMissing || devicePrivateKeyMissing)
|
||||
{
|
||||
decryptionKey = await downloadContext.ApiHelper.GetDecryptionKeyOFDL(drmHeaders, $"https://onlyfans.com/api2/v2/users/media/{mediaId}/drm/post/{postId}?type=widevine", pssh);
|
||||
}
|
||||
else
|
||||
{
|
||||
decryptionKey = await downloadContext.ApiHelper.GetDecryptionKeyCDM(drmHeaders, $"https://onlyfans.com/api2/v2/users/media/{mediaId}/drm/post/{postId}?type=widevine", pssh);
|
||||
}
|
||||
SinglePost.Medium mediaInfo = post.SinglePostMedia.FirstOrDefault(m => m.id == postKVP.Key);
|
||||
SinglePost postInfo = post.SinglePostObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true);
|
||||
|
||||
isNew = await downloadContext.DownloadHelper.DownloadPostDRMVideo(
|
||||
policy: policy,
|
||||
signature: signature,
|
||||
kvp: kvp,
|
||||
url: mpdURL,
|
||||
decryptionKey: decryptionKey,
|
||||
folder: path,
|
||||
lastModified: lastModified,
|
||||
media_id: postKVP.Key,
|
||||
api_type: "Posts",
|
||||
task: task,
|
||||
filenameFormat: downloadContext.FileNameFormatConfig.PostFileNameFormat ?? string.Empty,
|
||||
postInfo: postInfo,
|
||||
postMedia: mediaInfo,
|
||||
author: postInfo?.author,
|
||||
users: users);
|
||||
}
|
||||
else
|
||||
{
|
||||
try
|
||||
{
|
||||
SinglePost.Medium? mediaInfo = post.SinglePostMedia.FirstOrDefault(m => (m?.id == postKVP.Key) == true);
|
||||
SinglePost? postInfo = post.SinglePostObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true);
|
||||
|
||||
isNew = await downloadContext.DownloadHelper.DownloadPostMedia(
|
||||
url: postKVP.Value,
|
||||
bool downloaded = await downloadContext.DownloadHelper.DownloadPostDRMVideo(
|
||||
policy: policy,
|
||||
signature: signature,
|
||||
kvp: kvp,
|
||||
url: mpdURL,
|
||||
decryptionKey: decryptionKey,
|
||||
folder: path,
|
||||
lastModified: lastModified,
|
||||
media_id: postKVP.Key,
|
||||
api_type: "Posts",
|
||||
task: task,
|
||||
@ -2773,26 +2757,84 @@ public class Program
|
||||
postMedia: mediaInfo,
|
||||
author: postInfo?.author,
|
||||
users: users);
|
||||
if (downloaded)
|
||||
{
|
||||
anyNew = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool recorded = await downloadContext.DBHelper.CheckDownloaded(path, postKVP.Key, "Posts");
|
||||
if (recorded)
|
||||
{
|
||||
anyExisting = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
anyFailed = true;
|
||||
Log.Error("Failed to download DRM media {MediaId} for post {PostId}; not marked downloaded", postKVP.Key, post_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
else
|
||||
{
|
||||
Console.WriteLine("Media was null");
|
||||
try
|
||||
{
|
||||
SinglePost.Medium? mediaInfo = post.SinglePostMedia.FirstOrDefault(m => (m?.id == postKVP.Key) == true);
|
||||
SinglePost? postInfo = post.SinglePostObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true);
|
||||
|
||||
bool downloaded = await downloadContext.DownloadHelper.DownloadPostMedia(
|
||||
url: postKVP.Value,
|
||||
folder: path,
|
||||
media_id: postKVP.Key,
|
||||
api_type: "Posts",
|
||||
task: task,
|
||||
filenameFormat: downloadContext.FileNameFormatConfig.PostFileNameFormat ?? string.Empty,
|
||||
postInfo: postInfo,
|
||||
postMedia: mediaInfo,
|
||||
author: postInfo?.author,
|
||||
users: users);
|
||||
if (downloaded)
|
||||
{
|
||||
anyNew = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
bool recorded = await downloadContext.DBHelper.CheckDownloaded(path, postKVP.Key, "Posts");
|
||||
if (recorded)
|
||||
{
|
||||
anyExisting = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
anyFailed = true;
|
||||
Log.Error("Failed to download media {MediaId} for post {PostId}; not marked downloaded", postKVP.Key, post_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
Console.WriteLine("Media was null");
|
||||
}
|
||||
}
|
||||
}
|
||||
task.StopTask();
|
||||
});
|
||||
if (anyNew)
|
||||
{
|
||||
AnsiConsole.Markup($"[red]Post {post_id} downloaded\n[/]");
|
||||
Log.Debug($"Post {post_id} downloaded");
|
||||
}
|
||||
else if (anyExisting && !anyFailed)
|
||||
{
|
||||
AnsiConsole.Markup($"[red]Post {post_id} already downloaded\n[/]");
|
||||
Log.Debug($"Post {post_id} already downloaded");
|
||||
}
|
||||
else
|
||||
{
|
||||
AnsiConsole.Markup($"[red]Post {post_id} failed to download; no media marked as downloaded\n[/]");
|
||||
Log.Error("Post {PostId} failed to download; no media marked as downloaded", post_id);
|
||||
}
|
||||
task.StopTask();
|
||||
});
|
||||
if (isNew)
|
||||
{
|
||||
AnsiConsole.Markup($"[red]Post {post_id} downloaded\n[/]");
|
||||
Log.Debug($"Post {post_id} downloaded");
|
||||
}
|
||||
else
|
||||
{
|
||||
AnsiConsole.Markup($"[red]Post {post_id} already downloaded\n[/]");
|
||||
Log.Debug($"Post {post_id} already downloaded");
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task<(bool IsExit, Dictionary<string, long>? selectedUsers, Entities.Config? updatedConfig)> HandleUserSelection(APIHelper apiHelper, Entities.Config currentConfig, Dictionary<string, long> users, Dictionary<string, long> lists)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user