Skip to content

Commit

Permalink
FFMPEG download fixes and fix null refs for createdAt
Browse files Browse the repository at this point in the history
  • Loading branch information
sim0n00ps committed Aug 22, 2024
1 parent a32f435 commit d5d0b00
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 15 deletions.
6 changes: 3 additions & 3 deletions OF DL/Entities/Highlights/HighlightMedia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Story> stories { get; set; }
public class Files
{
Expand All @@ -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; }
}

Expand Down Expand Up @@ -91,7 +91,7 @@ public class Story
public bool isWatched { get; set; }
public bool isReady { get; set; }
public List<Medium> 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; }
Expand Down
4 changes: 2 additions & 2 deletions OF DL/Entities/Highlights/Highlights.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand All @@ -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; }
}
}
}
2 changes: 1 addition & 1 deletion OF DL/Entities/Post/SinglePost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
4 changes: 2 additions & 2 deletions OF DL/Entities/Stories/Stories.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class Stories
public bool isWatched { get; set; }
public bool isReady { get; set; }
public List<Medium> 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; }
Expand Down Expand Up @@ -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; }
}

Expand Down
2 changes: 1 addition & 1 deletion OF DL/Entities/Streams/Streams.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
25 changes: 20 additions & 5 deletions OF DL/Helpers/APIHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -523,17 +524,20 @@ public async Task<Dictionary<long, string>> GetMedia(MediaType mediatype,
Log.Debug("Media Stories - " + endpoint);

var stories = JsonConvert.DeserializeObject<List<Stories>>(body, m_JsonSerializerSettings) ?? new List<Stories>();
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)
{
Expand Down Expand Up @@ -624,7 +628,18 @@ public async Task<Dictionary<long, string>> 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)
Expand Down
2 changes: 1 addition & 1 deletion OF DL/Helpers/DownloadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ private async Task<bool> 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,
Expand Down

0 comments on commit d5d0b00

Please sign in to comment.