Compare commits

..

No commits in common. "already_downloaded_error" and "master" have entirely different histories.

View File

@ -2809,66 +2809,82 @@ public class Program
return;
}
long totalSize = 0;
if (downloadContext.DownloadConfig.ShowScrapeSize)
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)
{
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)
if (postKVP.Value.Contains("cdn3.onlyfans.com/dash/files"))
{
if (postKVP.Value.Contains("cdn3.onlyfans.com/dash/files"))
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)
{
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;
}
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);
bool downloaded = await downloadContext.DownloadHelper.DownloadPostDRMVideo(
policy: policy,
signature: signature,
kvp: kvp,
url: mpdURL,
decryptionKey: decryptionKey,
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,
folder: path,
lastModified: lastModified,
media_id: postKVP.Key,
api_type: "Posts",
task: task,
@ -2877,84 +2893,26 @@ 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);
}
}
}
else
catch
{
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");
}
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)
{