From d5d0b00baa1e1f1dc714038bbf0d946e27a07e2d Mon Sep 17 00:00:00 2001 From: sim0n00ps Date: Fri, 23 Aug 2024 00:03:46 +0100 Subject: [PATCH] FFMPEG download fixes and fix null refs for createdAt --- OF DL/Entities/Highlights/HighlightMedia.cs | 6 ++--- OF DL/Entities/Highlights/Highlights.cs | 4 ++-- OF DL/Entities/Post/SinglePost.cs | 2 +- OF DL/Entities/Stories/Stories.cs | 4 ++-- OF DL/Entities/Streams/Streams.cs | 2 +- OF DL/Helpers/APIHelper.cs | 25 ++++++++++++++++----- OF DL/Helpers/DownloadHelper.cs | 2 +- 7 files changed, 30 insertions(+), 15 deletions(-) diff --git a/OF DL/Entities/Highlights/HighlightMedia.cs b/OF DL/Entities/Highlights/HighlightMedia.cs index a40703b..d4b141a 100644 --- a/OF DL/Entities/Highlights/HighlightMedia.cs +++ b/OF DL/Entities/Highlights/HighlightMedia.cs @@ -15,7 +15,7 @@ public class HighlightMedia public int coverStoryId { get; set; } public string cover { get; set; } public int storiesCount { get; set; } - public DateTime createdAt { get; set; } + public DateTime? createdAt { get; set; } public List stories { get; set; } public class Files { @@ -41,7 +41,7 @@ public class Medium public bool convertedToVideo { get; set; } public bool canView { get; set; } public bool hasError { get; set; } - public DateTime createdAt { get; set; } + public DateTime? createdAt { get; set; } public Files files { get; set; } } @@ -91,7 +91,7 @@ public class Story public bool isWatched { get; set; } public bool isReady { get; set; } public List media { get; set; } - public DateTime createdAt { get; set; } + public DateTime? createdAt { get; set; } public object question { get; set; } public bool canLike { get; set; } public bool isLiked { get; set; } diff --git a/OF DL/Entities/Highlights/Highlights.cs b/OF DL/Entities/Highlights/Highlights.cs index ed5a5f7..fc29ff7 100644 --- a/OF DL/Entities/Highlights/Highlights.cs +++ b/OF DL/Entities/Highlights/Highlights.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -18,7 +18,7 @@ public class List public int coverStoryId { get; set; } public string cover { get; set; } public int storiesCount { get; set; } - public DateTime createdAt { get; set; } + public DateTime? createdAt { get; set; } } } } diff --git a/OF DL/Entities/Post/SinglePost.cs b/OF DL/Entities/Post/SinglePost.cs index e7d1c18..749ec86 100644 --- a/OF DL/Entities/Post/SinglePost.cs +++ b/OF DL/Entities/Post/SinglePost.cs @@ -119,7 +119,7 @@ public class Medium public bool convertedToVideo { get; set; } public bool canView { get; set; } public bool hasError { get; set; } - public DateTime createdAt { get; set; } + public DateTime? createdAt { get; set; } public Info info { get; set; } public Source source { get; set; } public string squarePreview { get; set; } diff --git a/OF DL/Entities/Stories/Stories.cs b/OF DL/Entities/Stories/Stories.cs index ae0e853..0d8961d 100644 --- a/OF DL/Entities/Stories/Stories.cs +++ b/OF DL/Entities/Stories/Stories.cs @@ -14,7 +14,7 @@ public class Stories public bool isWatched { get; set; } public bool isReady { get; set; } public List media { get; set; } - public DateTime createdAt { get; set; } + public DateTime? createdAt { get; set; } public object question { get; set; } public bool canLike { get; set; } public bool isLiked { get; set; } @@ -42,7 +42,7 @@ public class Medium public bool convertedToVideo { get; set; } public bool canView { get; set; } public bool hasError { get; set; } - public DateTime createdAt { get; set; } + public DateTime? createdAt { get; set; } public Files files { get; set; } } diff --git a/OF DL/Entities/Streams/Streams.cs b/OF DL/Entities/Streams/Streams.cs index cfc83b5..183f21e 100644 --- a/OF DL/Entities/Streams/Streams.cs +++ b/OF DL/Entities/Streams/Streams.cs @@ -139,7 +139,7 @@ public class Medium public bool convertedToVideo { get; set; } public bool canView { get; set; } public bool hasError { get; set; } - public DateTime createdAt { get; set; } + public DateTime? createdAt { get; set; } public Info info { get; set; } public Source source { get; set; } public string squarePreview { get; set; } diff --git a/OF DL/Helpers/APIHelper.cs b/OF DL/Helpers/APIHelper.cs index 00ce091..fd9c567 100644 --- a/OF DL/Helpers/APIHelper.cs +++ b/OF DL/Helpers/APIHelper.cs @@ -17,6 +17,7 @@ using System.Text.Json; using System.Xml.Linq; using WidevineClient.Widevine; +using static OF_DL.Entities.Highlights.HighlightMedia; using static WidevineClient.HttpUtil; namespace OF_DL.Helpers; @@ -523,17 +524,20 @@ public async Task> GetMedia(MediaType mediatype, Log.Debug("Media Stories - " + endpoint); var stories = JsonConvert.DeserializeObject>(body, m_JsonSerializerSettings) ?? new List(); - stories = stories.OrderByDescending(x => x.createdAt).ToList(); foreach (Stories story in stories) { - if (story.createdAt != null) + if (story.media[0].createdAt.HasValue) { - await m_DBHelper.AddStory(folder, story.id, string.Empty, "0", false, false, story.createdAt); + await m_DBHelper.AddStory(folder, story.id, string.Empty, "0", false, false, story.media[0].createdAt.Value); + } + else if (story.createdAt.HasValue) + { + await m_DBHelper.AddStory(folder, story.id, string.Empty, "0", false, false, story.createdAt.Value); } else { - await m_DBHelper.AddStory(folder, story.id, string.Empty, "0", false, false, story.media[0].createdAt); + await m_DBHelper.AddStory(folder, story.id, string.Empty, "0", false, false, DateTime.Now); } if (story.media != null && story.media.Count > 0) { @@ -624,7 +628,18 @@ public async Task> GetMedia(MediaType mediatype, { foreach (HighlightMedia.Story item in highlightMedia.stories) { - await m_DBHelper.AddStory(folder, item.id, string.Empty, "0", false, false, item.createdAt); + if (item.media[0].createdAt.HasValue) + { + await m_DBHelper.AddStory(folder, item.id, string.Empty, "0", false, false, item.media[0].createdAt.Value); + } + else if (item.createdAt.HasValue) + { + await m_DBHelper.AddStory(folder, item.id, string.Empty, "0", false, false, item.createdAt.Value); + } + else + { + await m_DBHelper.AddStory(folder, item.id, string.Empty, "0", false, false, DateTime.Now); + } if (item.media.Count > 0 && !item.media[0].files.full.url.Contains("upload")) { foreach (HighlightMedia.Medium medium in item.media) diff --git a/OF DL/Helpers/DownloadHelper.cs b/OF DL/Helpers/DownloadHelper.cs index b4b9081..9af3d17 100644 --- a/OF DL/Helpers/DownloadHelper.cs +++ b/OF DL/Helpers/DownloadHelper.cs @@ -598,7 +598,7 @@ private async Task DownloadDrmMedia(string user_agent, string policy, stri ProcessStartInfo ffmpegStartInfo = new() { FileName = downloadConfig.FFmpegPath, - Arguments = $"-cenc_decryption_key {decKey} -headers \"Cookie:CloudFront-Policy={policy}; CloudFront-Signature={signature}; CloudFront-Key-Pair-Id={kvp}; {sess}\r\nOrigin: https://onlyfans.com\r\nReferer: https://onlyfans.com\r\nUser-Agent: {user_agent}\r\n\r\n\" -y -i \"{url}\" -codec copy \"{tempFilename}\"", + Arguments = $"-cenc_decryption_key {decKey} -headers \"Cookie:CloudFront-Policy={policy}; CloudFront-Signature={signature}; CloudFront-Key-Pair-Id={kvp}; {sess} Origin: https://onlyfans.com Referer: https://onlyfans.com User-Agent: {user_agent}\" -y -i \"{url}\" -codec copy \"{tempFilename}\"", CreateNoWindow = true, UseShellExecute = false, RedirectStandardOutput = false,