From 35712da12d7ab28175a64731b8db9aaa05b0e92d Mon Sep 17 00:00:00 2001 From: whimsical-c4lic0 Date: Sun, 8 Feb 2026 15:29:42 -0600 Subject: [PATCH] Refactor Archived entities into DTOs and application entities with standardized naming conventions and default values --- OF DL/Models/Archived/Archived.cs | 262 ------------------ OF DL/Models/Archived/ArchivedCollection.cs | 8 - OF DL/Models/Dtos/Archived/ArchivedDto.cs | 16 ++ OF DL/Models/Dtos/Archived/CountersDto.cs | 20 ++ OF DL/Models/Dtos/Archived/InfoDto.cs | 11 + OF DL/Models/Dtos/Archived/LinkedPostDto.cs | 96 +++++++ OF DL/Models/Dtos/Archived/ListItemDto.cs | 97 +++++++ OF DL/Models/Dtos/Archived/MediumDto.cs | 35 +++ OF DL/Models/Dtos/Common/AuthorDto.cs | 10 + OF DL/Models/Dtos/Common/DashDto.cs | 13 + OF DL/Models/Dtos/Common/DrmDto.cs | 11 + OF DL/Models/Dtos/Common/FilesDto.cs | 17 ++ OF DL/Models/Dtos/Common/FullDto.cs | 16 ++ OF DL/Models/Dtos/Common/HlsDto.cs | 13 + OF DL/Models/Dtos/Common/ManifestDto.cs | 10 + OF DL/Models/Dtos/Common/PreviewDto.cs | 14 + OF DL/Models/Dtos/Common/SignatureDto.cs | 10 + OF DL/Models/Dtos/Common/SourceDto.cs | 18 ++ OF DL/Models/Dtos/Common/SourcesDto.cs | 14 + OF DL/Models/Dtos/Common/SquarePreviewDto.cs | 14 + OF DL/Models/Dtos/Common/ThumbDto.cs | 14 + OF DL/Models/Dtos/Common/VideoSourcesDto.cs | 10 + OF DL/Models/Entities/Archived/Archived.cs | 10 + .../Entities/Archived/ArchivedCollection.cs | 10 + OF DL/Models/Entities/Archived/ListItem.cs | 24 ++ OF DL/Models/Entities/Archived/Medium.cs | 16 ++ OF DL/Models/Entities/Common/Author.cs | 6 + OF DL/Models/Entities/Common/Dash.cs | 10 + OF DL/Models/Entities/Common/Drm.cs | 8 + OF DL/Models/Entities/Common/Files.cs | 8 + OF DL/Models/Entities/Common/Full.cs | 6 + OF DL/Models/Entities/Common/Manifest.cs | 6 + OF DL/Models/Entities/Common/Signature.cs | 6 + OF DL/Models/Mappers/ArchivedMapper.cs | 137 +++++++++ OF DL/Program.cs | 19 +- OF DL/Services/APIService.cs | 88 +++--- OF DL/Services/DownloadService.cs | 73 +++-- OF DL/Services/IAPIService.cs | 2 +- OF DL/Services/IDownloadService.cs | 40 ++- 39 files changed, 831 insertions(+), 367 deletions(-) delete mode 100644 OF DL/Models/Archived/Archived.cs delete mode 100644 OF DL/Models/Archived/ArchivedCollection.cs create mode 100644 OF DL/Models/Dtos/Archived/ArchivedDto.cs create mode 100644 OF DL/Models/Dtos/Archived/CountersDto.cs create mode 100644 OF DL/Models/Dtos/Archived/InfoDto.cs create mode 100644 OF DL/Models/Dtos/Archived/LinkedPostDto.cs create mode 100644 OF DL/Models/Dtos/Archived/ListItemDto.cs create mode 100644 OF DL/Models/Dtos/Archived/MediumDto.cs create mode 100644 OF DL/Models/Dtos/Common/AuthorDto.cs create mode 100644 OF DL/Models/Dtos/Common/DashDto.cs create mode 100644 OF DL/Models/Dtos/Common/DrmDto.cs create mode 100644 OF DL/Models/Dtos/Common/FilesDto.cs create mode 100644 OF DL/Models/Dtos/Common/FullDto.cs create mode 100644 OF DL/Models/Dtos/Common/HlsDto.cs create mode 100644 OF DL/Models/Dtos/Common/ManifestDto.cs create mode 100644 OF DL/Models/Dtos/Common/PreviewDto.cs create mode 100644 OF DL/Models/Dtos/Common/SignatureDto.cs create mode 100644 OF DL/Models/Dtos/Common/SourceDto.cs create mode 100644 OF DL/Models/Dtos/Common/SourcesDto.cs create mode 100644 OF DL/Models/Dtos/Common/SquarePreviewDto.cs create mode 100644 OF DL/Models/Dtos/Common/ThumbDto.cs create mode 100644 OF DL/Models/Dtos/Common/VideoSourcesDto.cs create mode 100644 OF DL/Models/Entities/Archived/Archived.cs create mode 100644 OF DL/Models/Entities/Archived/ArchivedCollection.cs create mode 100644 OF DL/Models/Entities/Archived/ListItem.cs create mode 100644 OF DL/Models/Entities/Archived/Medium.cs create mode 100644 OF DL/Models/Entities/Common/Author.cs create mode 100644 OF DL/Models/Entities/Common/Dash.cs create mode 100644 OF DL/Models/Entities/Common/Drm.cs create mode 100644 OF DL/Models/Entities/Common/Files.cs create mode 100644 OF DL/Models/Entities/Common/Full.cs create mode 100644 OF DL/Models/Entities/Common/Manifest.cs create mode 100644 OF DL/Models/Entities/Common/Signature.cs create mode 100644 OF DL/Models/Mappers/ArchivedMapper.cs diff --git a/OF DL/Models/Archived/Archived.cs b/OF DL/Models/Archived/Archived.cs deleted file mode 100644 index 2ec4d68..0000000 --- a/OF DL/Models/Archived/Archived.cs +++ /dev/null @@ -1,262 +0,0 @@ -using Newtonsoft.Json; -using OF_DL.Utils; - -namespace OF_DL.Models.Archived; - -public class Archived -{ - public List list { get; set; } - public bool hasMore { get; set; } - public string headMarker { get; set; } - public string tailMarker { get; set; } - public Counters counters { get; set; } - - public class Author - { - public long id { get; set; } - public string _view { get; set; } - } - - public class Counters - { - public int? audiosCount { get; set; } - public int? photosCount { get; set; } - public int? videosCount { get; set; } - public int? mediasCount { get; set; } - public int? postsCount { get; set; } - public int? streamsCount { get; set; } - public int? archivedPostsCount { get; set; } - } - - public class Dash - { - [JsonProperty("CloudFront-Policy")] public string CloudFrontPolicy { get; set; } - - [JsonProperty("CloudFront-Signature")] public string CloudFrontSignature { get; set; } - - [JsonProperty("CloudFront-Key-Pair-Id")] - public string CloudFrontKeyPairId { get; set; } - } - - public class Drm - { - public Manifest manifest { get; set; } - public Signature signature { get; set; } - } - - public class Files - { - public Full full { get; set; } - public Thumb thumb { get; set; } - public Preview preview { get; set; } - public SquarePreview squarePreview { get; set; } - public Drm drm { get; set; } - } - - public class Full - { - public string url { get; set; } - public int width { get; set; } - public int height { get; set; } - public long size { get; set; } - public List sources { get; set; } - } - - public class SquarePreview - { - public string url { get; set; } - public int width { get; set; } - public int height { get; set; } - public long size { get; set; } - } - - public class Thumb - { - public string url { get; set; } - public int width { get; set; } - public int height { get; set; } - public long size { get; set; } - } - - public class Hls - { - [JsonProperty("CloudFront-Policy")] public string CloudFrontPolicy { get; set; } - - [JsonProperty("CloudFront-Signature")] public string CloudFrontSignature { get; set; } - - [JsonProperty("CloudFront-Key-Pair-Id")] - public string CloudFrontKeyPairId { get; set; } - } - - public class Info - { - public Source source { get; set; } - public Preview preview { get; set; } - } - - public class LinkedPost - { - private string _rawText; - public string responseType { get; set; } - public long? id { get; set; } - public DateTime? postedAt { get; set; } - public string postedAtPrecise { get; set; } - public object expiredAt { get; set; } - public Author author { get; set; } - public string text { get; set; } - - public string rawText - { - get - { - if (string.IsNullOrEmpty(_rawText)) - { - _rawText = XmlUtils.EvaluateInnerText(text); - } - - return _rawText; - } - set => _rawText = value; - } - - public bool? lockedText { get; set; } - public bool? isFavorite { get; set; } - public bool? canReport { get; set; } - public bool? canDelete { get; set; } - public bool? canComment { get; set; } - public bool? canEdit { get; set; } - public bool? isPinned { get; set; } - public int? favoritesCount { get; set; } - public int? mediaCount { get; set; } - public bool? isMediaReady { get; set; } - public object voting { get; set; } - public bool? isOpened { get; set; } - public bool? canToggleFavorite { get; set; } - public object streamId { get; set; } - public string? price { get; set; } - public bool? hasVoting { get; set; } - public bool? isAddedToBookmarks { get; set; } - public bool? isArchived { get; set; } - public bool? isPrivateArchived { get; set; } - public bool? isDeleted { get; set; } - public bool? hasUrl { get; set; } - public bool? isCouplePeopleMedia { get; set; } - public string cantCommentReason { get; set; } - public int? commentsCount { get; set; } - public List mentionedUsers { get; set; } - public List linkedUsers { get; set; } - public List media { get; set; } - public bool? canViewMedia { get; set; } - public List preview { get; set; } - } - - public class List - { - private string _rawText; - public string responseType { get; set; } - public long id { get; set; } - public DateTime postedAt { get; set; } - public string postedAtPrecise { get; set; } - public object expiredAt { get; set; } - public Author author { get; set; } - public string text { get; set; } - - public string rawText - { - get - { - if (string.IsNullOrEmpty(_rawText)) - { - _rawText = XmlUtils.EvaluateInnerText(text); - } - - return _rawText; - } - set => _rawText = value; - } - - public bool? lockedText { get; set; } - public bool? isFavorite { get; set; } - public bool? canReport { get; set; } - public bool? canDelete { get; set; } - public bool? canComment { get; set; } - public bool? canEdit { get; set; } - public bool? isPinned { get; set; } - public int? favoritesCount { get; set; } - public int? mediaCount { get; set; } - public bool? isMediaReady { get; set; } - public object voting { get; set; } - public bool isOpened { get; set; } - public bool? canToggleFavorite { get; set; } - public object streamId { get; set; } - public string price { get; set; } - public bool? hasVoting { get; set; } - public bool? isAddedToBookmarks { get; set; } - public bool isArchived { get; set; } - public bool? isPrivateArchived { get; set; } - public bool? isDeleted { get; set; } - public bool? hasUrl { get; set; } - public bool? isCouplePeopleMedia { get; set; } - public int? commentsCount { get; set; } - public List mentionedUsers { get; set; } - public List linkedUsers { get; set; } - public List media { get; set; } - public bool? canViewMedia { get; set; } - public List preview { get; set; } - public string cantCommentReason { get; set; } - } - - public class Manifest - { - public string hls { get; set; } - public string dash { get; set; } - } - - public class Medium - { - public long id { get; set; } - public string type { get; set; } - public bool? convertedToVideo { get; set; } - public bool canView { get; set; } - public bool? hasError { get; set; } - public DateTime? createdAt { get; set; } - public Info info { get; set; } - public Source source { get; set; } - public string squarePreview { get; set; } - public string full { get; set; } - public string preview { get; set; } - public string thumb { get; set; } - public Files files { get; set; } - public VideoSources videoSources { get; set; } - } - - public class Preview - { - public int? width { get; set; } - public int? height { get; set; } - public int? size { get; set; } - public string url { get; set; } - } - - public class Signature - { - public Hls hls { get; set; } - public Dash dash { get; set; } - } - - public class Source - { - public string source { get; set; } - public int? width { get; set; } - public int? height { get; set; } - public int? size { get; set; } - public int? duration { get; set; } - } - - public class VideoSources - { - [JsonProperty("720")] public string _720 { get; set; } - - [JsonProperty("240")] public string _240 { get; set; } - } -} diff --git a/OF DL/Models/Archived/ArchivedCollection.cs b/OF DL/Models/Archived/ArchivedCollection.cs deleted file mode 100644 index b4f6d6d..0000000 --- a/OF DL/Models/Archived/ArchivedCollection.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace OF_DL.Models.Archived; - -public class ArchivedCollection -{ - public List ArchivedPostMedia = new(); - public List ArchivedPostObjects = new(); - public Dictionary ArchivedPosts = new(); -} diff --git a/OF DL/Models/Dtos/Archived/ArchivedDto.cs b/OF DL/Models/Dtos/Archived/ArchivedDto.cs new file mode 100644 index 0000000..80d373a --- /dev/null +++ b/OF DL/Models/Dtos/Archived/ArchivedDto.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Archived; + +public class ArchivedDto +{ + [JsonProperty("list")] public List List { get; set; } = []; + + [JsonProperty("hasMore")] public bool HasMore { get; set; } + + [JsonProperty("headMarker")] public string HeadMarker { get; set; } = ""; + + [JsonProperty("tailMarker")] public string TailMarker { get; set; } = ""; + + [JsonProperty("counters")] public CountersDto Counters { get; set; } = new(); +} diff --git a/OF DL/Models/Dtos/Archived/CountersDto.cs b/OF DL/Models/Dtos/Archived/CountersDto.cs new file mode 100644 index 0000000..40e2500 --- /dev/null +++ b/OF DL/Models/Dtos/Archived/CountersDto.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Archived; + +public class CountersDto +{ + [JsonProperty("audiosCount")] public int? AudiosCount { get; set; } + + [JsonProperty("photosCount")] public int? PhotosCount { get; set; } + + [JsonProperty("videosCount")] public int? VideosCount { get; set; } + + [JsonProperty("mediasCount")] public int? MediasCount { get; set; } + + [JsonProperty("postsCount")] public int? PostsCount { get; set; } + + [JsonProperty("streamsCount")] public int? StreamsCount { get; set; } + + [JsonProperty("archivedPostsCount")] public int? ArchivedPostsCount { get; set; } +} diff --git a/OF DL/Models/Dtos/Archived/InfoDto.cs b/OF DL/Models/Dtos/Archived/InfoDto.cs new file mode 100644 index 0000000..1e4b13d --- /dev/null +++ b/OF DL/Models/Dtos/Archived/InfoDto.cs @@ -0,0 +1,11 @@ +using Newtonsoft.Json; +using OF_DL.Models.Dtos.Common; + +namespace OF_DL.Models.Dtos.Archived; + +public class InfoDto +{ + [JsonProperty("source")] public SourceDto Source { get; set; } = new(); + + [JsonProperty("preview")] public PreviewDto Preview { get; set; } = new(); +} diff --git a/OF DL/Models/Dtos/Archived/LinkedPostDto.cs b/OF DL/Models/Dtos/Archived/LinkedPostDto.cs new file mode 100644 index 0000000..3bedcae --- /dev/null +++ b/OF DL/Models/Dtos/Archived/LinkedPostDto.cs @@ -0,0 +1,96 @@ +using Newtonsoft.Json; +using OF_DL.Models.Dtos.Common; +using OF_DL.Utils; + +namespace OF_DL.Models.Dtos.Archived; + +public class LinkedPostDto +{ + private string _rawText = ""; + [JsonProperty("responseType")] public string ResponseType { get; set; } = ""; + + [JsonProperty("id")] public long? Id { get; set; } + + [JsonProperty("postedAt")] public DateTime? PostedAt { get; set; } + + [JsonProperty("postedAtPrecise")] public string PostedAtPrecise { get; set; } = ""; + + [JsonProperty("expiredAt")] public object ExpiredAt { get; set; } = new(); + + [JsonProperty("author")] public AuthorDto Author { get; set; } = new(); + + [JsonProperty("text")] public string Text { get; set; } = ""; + + [JsonProperty("rawText")] + public string RawText + { + get + { + if (string.IsNullOrEmpty(_rawText)) + { + _rawText = XmlUtils.EvaluateInnerText(Text); + } + + return _rawText; + } + set => _rawText = value; + } + + [JsonProperty("lockedText")] public bool? LockedText { get; set; } + + [JsonProperty("isFavorite")] public bool? IsFavorite { get; set; } + + [JsonProperty("canReport")] public bool? CanReport { get; set; } + + [JsonProperty("canDelete")] public bool? CanDelete { get; set; } + + [JsonProperty("canComment")] public bool? CanComment { get; set; } + + [JsonProperty("canEdit")] public bool? CanEdit { get; set; } + + [JsonProperty("isPinned")] public bool? IsPinned { get; set; } + + [JsonProperty("favoritesCount")] public int? FavoritesCount { get; set; } + + [JsonProperty("mediaCount")] public int? MediaCount { get; set; } + + [JsonProperty("isMediaReady")] public bool? IsMediaReady { get; set; } + + [JsonProperty("voting")] public object Voting { get; set; } = new(); + + [JsonProperty("isOpened")] public bool? IsOpened { get; set; } + + [JsonProperty("canToggleFavorite")] public bool? CanToggleFavorite { get; set; } + + [JsonProperty("streamId")] public object StreamId { get; set; } = new(); + + [JsonProperty("price")] public string? Price { get; set; } + + [JsonProperty("hasVoting")] public bool? HasVoting { get; set; } + + [JsonProperty("isAddedToBookmarks")] public bool? IsAddedToBookmarks { get; set; } + + [JsonProperty("isArchived")] public bool? IsArchived { get; set; } + + [JsonProperty("isPrivateArchived")] public bool? IsPrivateArchived { get; set; } + + [JsonProperty("isDeleted")] public bool? IsDeleted { get; set; } + + [JsonProperty("hasUrl")] public bool? HasUrl { get; set; } + + [JsonProperty("isCouplePeopleMedia")] public bool? IsCouplePeopleMedia { get; set; } + + [JsonProperty("cantCommentReason")] public string CantCommentReason { get; set; } = ""; + + [JsonProperty("commentsCount")] public int? CommentsCount { get; set; } + + [JsonProperty("mentionedUsers")] public List MentionedUsers { get; set; } = []; + + [JsonProperty("linkedUsers")] public List LinkedUsers { get; set; } = []; + + [JsonProperty("media")] public List Media { get; set; } = []; + + [JsonProperty("canViewMedia")] public bool? CanViewMedia { get; set; } + + [JsonProperty("preview")] public List Preview { get; set; } = []; +} diff --git a/OF DL/Models/Dtos/Archived/ListItemDto.cs b/OF DL/Models/Dtos/Archived/ListItemDto.cs new file mode 100644 index 0000000..d2106ed --- /dev/null +++ b/OF DL/Models/Dtos/Archived/ListItemDto.cs @@ -0,0 +1,97 @@ +using Newtonsoft.Json; +using OF_DL.Models.Dtos.Common; +using OF_DL.Utils; + +namespace OF_DL.Models.Dtos.Archived; + +public class ListItemDto +{ + private string _rawText = ""; + + [JsonProperty("responseType")] public string ResponseType { get; set; } = ""; + + [JsonProperty("id")] public long Id { get; set; } + + [JsonProperty("postedAt")] public DateTime PostedAt { get; set; } + + [JsonProperty("postedAtPrecise")] public string PostedAtPrecise { get; set; } = ""; + + [JsonProperty("expiredAt")] public object ExpiredAt { get; set; } = new(); + + [JsonProperty("author")] public AuthorDto Author { get; set; } = new(); + + [JsonProperty("text")] public string Text { get; set; } = ""; + + [JsonProperty("rawText")] + public string RawText + { + get + { + if (string.IsNullOrEmpty(_rawText)) + { + _rawText = XmlUtils.EvaluateInnerText(Text); + } + + return _rawText; + } + set => _rawText = value; + } + + [JsonProperty("lockedText")] public bool? LockedText { get; set; } + + [JsonProperty("isFavorite")] public bool? IsFavorite { get; set; } + + [JsonProperty("canReport")] public bool? CanReport { get; set; } + + [JsonProperty("canDelete")] public bool? CanDelete { get; set; } + + [JsonProperty("canComment")] public bool? CanComment { get; set; } + + [JsonProperty("canEdit")] public bool? CanEdit { get; set; } + + [JsonProperty("isPinned")] public bool? IsPinned { get; set; } + + [JsonProperty("favoritesCount")] public int? FavoritesCount { get; set; } + + [JsonProperty("mediaCount")] public int? MediaCount { get; set; } + + [JsonProperty("isMediaReady")] public bool? IsMediaReady { get; set; } + + [JsonProperty("voting")] public object Voting { get; set; } = new(); + + [JsonProperty("isOpened")] public bool IsOpened { get; set; } + + [JsonProperty("canToggleFavorite")] public bool? CanToggleFavorite { get; set; } + + [JsonProperty("streamId")] public object StreamId { get; set; } = new(); + + [JsonProperty("price")] public string Price { get; set; } = ""; + + [JsonProperty("hasVoting")] public bool? HasVoting { get; set; } + + [JsonProperty("isAddedToBookmarks")] public bool? IsAddedToBookmarks { get; set; } + + [JsonProperty("isArchived")] public bool IsArchived { get; set; } + + [JsonProperty("isPrivateArchived")] public bool? IsPrivateArchived { get; set; } + + [JsonProperty("isDeleted")] public bool? IsDeleted { get; set; } + + [JsonProperty("hasUrl")] public bool? HasUrl { get; set; } + + [JsonProperty("isCouplePeopleMedia")] public bool? IsCouplePeopleMedia { get; set; } + + [JsonProperty("commentsCount")] public int? CommentsCount { get; set; } + + [JsonProperty("mentionedUsers")] public List MentionedUsers { get; set; } = []; + + [JsonProperty("linkedUsers")] public List LinkedUsers { get; set; } = []; + + [JsonProperty("media")] public List Media { get; set; } = []; + + [JsonProperty("canViewMedia")] public bool? CanViewMedia { get; set; } + + [JsonProperty("preview")] public List Preview { get; set; } = []; + + [JsonProperty("cantCommentReason")] public string CantCommentReason { get; set; } = ""; +} diff --git a/OF DL/Models/Dtos/Archived/MediumDto.cs b/OF DL/Models/Dtos/Archived/MediumDto.cs new file mode 100644 index 0000000..de6570b --- /dev/null +++ b/OF DL/Models/Dtos/Archived/MediumDto.cs @@ -0,0 +1,35 @@ +using Newtonsoft.Json; +using OF_DL.Models.Dtos.Common; + +namespace OF_DL.Models.Dtos.Archived; + +public class MediumDto +{ + [JsonProperty("id")] public long Id { get; set; } + + [JsonProperty("type")] public string Type { get; set; } = ""; + + [JsonProperty("convertedToVideo")] public bool? ConvertedToVideo { get; set; } + + [JsonProperty("canView")] public bool CanView { get; set; } + + [JsonProperty("hasError")] public bool? HasError { get; set; } + + [JsonProperty("createdAt")] public DateTime? CreatedAt { get; set; } = new(); + + [JsonProperty("info")] public InfoDto Info { get; set; } = new(); + + [JsonProperty("source")] public SourceDto Source { get; set; } = new(); + + [JsonProperty("squarePreview")] public string SquarePreview { get; set; } = ""; + + [JsonProperty("full")] public string Full { get; set; } = ""; + + [JsonProperty("preview")] public string Preview { get; set; } = ""; + + [JsonProperty("thumb")] public string Thumb { get; set; } = ""; + + [JsonProperty("files")] public FilesDto Files { get; set; } = new(); + + [JsonProperty("videoSources")] public VideoSourcesDto VideoSources { get; set; } = new(); +} diff --git a/OF DL/Models/Dtos/Common/AuthorDto.cs b/OF DL/Models/Dtos/Common/AuthorDto.cs new file mode 100644 index 0000000..ab91233 --- /dev/null +++ b/OF DL/Models/Dtos/Common/AuthorDto.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Common; + +public class AuthorDto +{ + [JsonProperty("id")] public long Id { get; set; } + + [JsonProperty("_view")] public string View { get; set; } = ""; +} diff --git a/OF DL/Models/Dtos/Common/DashDto.cs b/OF DL/Models/Dtos/Common/DashDto.cs new file mode 100644 index 0000000..1a430b2 --- /dev/null +++ b/OF DL/Models/Dtos/Common/DashDto.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Common; + +public class DashDto +{ + [JsonProperty("CloudFront-Policy")] public string CloudFrontPolicy { get; set; } = ""; + + [JsonProperty("CloudFront-Signature")] public string CloudFrontSignature { get; set; } = ""; + + [JsonProperty("CloudFront-Key-Pair-Id")] + public string CloudFrontKeyPairId { get; set; } = ""; +} diff --git a/OF DL/Models/Dtos/Common/DrmDto.cs b/OF DL/Models/Dtos/Common/DrmDto.cs new file mode 100644 index 0000000..a5a2d86 --- /dev/null +++ b/OF DL/Models/Dtos/Common/DrmDto.cs @@ -0,0 +1,11 @@ +using Newtonsoft.Json; +using OF_DL.Models.Dtos.Archived; + +namespace OF_DL.Models.Dtos.Common; + +public class DrmDto +{ + [JsonProperty("manifest")] public ManifestDto Manifest { get; set; } = new(); + + [JsonProperty("signature")] public SignatureDto Signature { get; set; } = new(); +} diff --git a/OF DL/Models/Dtos/Common/FilesDto.cs b/OF DL/Models/Dtos/Common/FilesDto.cs new file mode 100644 index 0000000..12a4a6c --- /dev/null +++ b/OF DL/Models/Dtos/Common/FilesDto.cs @@ -0,0 +1,17 @@ +using Newtonsoft.Json; + + +namespace OF_DL.Models.Dtos.Common; + +public class FilesDto +{ + [JsonProperty("full")] public FullDto Full { get; set; } = new(); + + [JsonProperty("thumb")] public ThumbDto Thumb { get; set; } = new(); + + [JsonProperty("preview")] public PreviewDto Preview { get; set; } = new(); + + [JsonProperty("squarePreview")] public SquarePreviewDto SquarePreview { get; set; } = new(); + + [JsonProperty("drm")] public DrmDto Drm { get; set; } = new(); +} diff --git a/OF DL/Models/Dtos/Common/FullDto.cs b/OF DL/Models/Dtos/Common/FullDto.cs new file mode 100644 index 0000000..1fda737 --- /dev/null +++ b/OF DL/Models/Dtos/Common/FullDto.cs @@ -0,0 +1,16 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Common; + +public class FullDto +{ + [JsonProperty("url")] public string Url { get; set; } = ""; + + [JsonProperty("width")] public int Width { get; set; } + + [JsonProperty("height")] public int Height { get; set; } + + [JsonProperty("size")] public long Size { get; set; } + + [JsonProperty("sources")] public List Sources { get; set; } = []; +} diff --git a/OF DL/Models/Dtos/Common/HlsDto.cs b/OF DL/Models/Dtos/Common/HlsDto.cs new file mode 100644 index 0000000..d580efb --- /dev/null +++ b/OF DL/Models/Dtos/Common/HlsDto.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Common; + +public class HlsDto +{ + [JsonProperty("CloudFront-Policy")] public string CloudFrontPolicy { get; set; } = ""; + + [JsonProperty("CloudFront-Signature")] public string CloudFrontSignature { get; set; } = ""; + + [JsonProperty("CloudFront-Key-Pair-Id")] + public string CloudFrontKeyPairId { get; set; } = ""; +} diff --git a/OF DL/Models/Dtos/Common/ManifestDto.cs b/OF DL/Models/Dtos/Common/ManifestDto.cs new file mode 100644 index 0000000..89f39c3 --- /dev/null +++ b/OF DL/Models/Dtos/Common/ManifestDto.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Common; + +public class ManifestDto +{ + [JsonProperty("hls")] public string Hls { get; set; } = ""; + + [JsonProperty("dash")] public string Dash { get; set; } = ""; +} diff --git a/OF DL/Models/Dtos/Common/PreviewDto.cs b/OF DL/Models/Dtos/Common/PreviewDto.cs new file mode 100644 index 0000000..b1f96a2 --- /dev/null +++ b/OF DL/Models/Dtos/Common/PreviewDto.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Common; + +public class PreviewDto +{ + [JsonProperty("width")] public int? Width { get; set; } + + [JsonProperty("height")] public int? Height { get; set; } + + [JsonProperty("size")] public int? Size { get; set; } + + [JsonProperty("url")] public string Url { get; set; } = ""; +} diff --git a/OF DL/Models/Dtos/Common/SignatureDto.cs b/OF DL/Models/Dtos/Common/SignatureDto.cs new file mode 100644 index 0000000..42ccaaf --- /dev/null +++ b/OF DL/Models/Dtos/Common/SignatureDto.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Common; + +public class SignatureDto +{ + [JsonProperty("hls")] public HlsDto Hls { get; set; } = new(); + + [JsonProperty("dash")] public DashDto Dash { get; set; } = new(); +} diff --git a/OF DL/Models/Dtos/Common/SourceDto.cs b/OF DL/Models/Dtos/Common/SourceDto.cs new file mode 100644 index 0000000..ae37216 --- /dev/null +++ b/OF DL/Models/Dtos/Common/SourceDto.cs @@ -0,0 +1,18 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Common; + +public class SourceDto +{ + [JsonProperty("url")] public string Url { get; set; } = ""; + + [JsonProperty("width")] public int Width { get; set; } + + [JsonProperty("height")] public int Height { get; set; } + + [JsonProperty("duration")] public int Duration { get; set; } + + [JsonProperty("size")] public long Size { get; set; } + + [JsonProperty("sources")] public SourcesDto Sources { get; set; } = new(); +} diff --git a/OF DL/Models/Dtos/Common/SourcesDto.cs b/OF DL/Models/Dtos/Common/SourcesDto.cs new file mode 100644 index 0000000..a7d151f --- /dev/null +++ b/OF DL/Models/Dtos/Common/SourcesDto.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Common; + +public class SourcesDto +{ + [JsonProperty("720")] public string _720 { get; set; } = ""; + + [JsonProperty("240")] public string _240 { get; set; } = ""; + + [JsonProperty("w150")] public string W150 { get; set; } = ""; + + [JsonProperty("w480")] public string W480 { get; set; } = ""; +} diff --git a/OF DL/Models/Dtos/Common/SquarePreviewDto.cs b/OF DL/Models/Dtos/Common/SquarePreviewDto.cs new file mode 100644 index 0000000..fc67f0a --- /dev/null +++ b/OF DL/Models/Dtos/Common/SquarePreviewDto.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Common; + +public class SquarePreviewDto +{ + [JsonProperty("url")] public string Url { get; set; } = ""; + + [JsonProperty("width")] public int Width { get; set; } + + [JsonProperty("height")] public int Height { get; set; } + + [JsonProperty("size")] public long Size { get; set; } +} diff --git a/OF DL/Models/Dtos/Common/ThumbDto.cs b/OF DL/Models/Dtos/Common/ThumbDto.cs new file mode 100644 index 0000000..b18f9c1 --- /dev/null +++ b/OF DL/Models/Dtos/Common/ThumbDto.cs @@ -0,0 +1,14 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Common; + +public class ThumbDto +{ + [JsonProperty("url")] public string Url { get; set; } = ""; + + [JsonProperty("width")] public int Width { get; set; } + + [JsonProperty("height")] public int Height { get; set; } + + [JsonProperty("size")] public long Size { get; set; } +} diff --git a/OF DL/Models/Dtos/Common/VideoSourcesDto.cs b/OF DL/Models/Dtos/Common/VideoSourcesDto.cs new file mode 100644 index 0000000..3f22ccf --- /dev/null +++ b/OF DL/Models/Dtos/Common/VideoSourcesDto.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Common; + +public class VideoSourcesDto +{ + [JsonProperty("720")] public string _720 { get; set; } = ""; + + [JsonProperty("240")] public string _240 { get; set; } = ""; +} diff --git a/OF DL/Models/Entities/Archived/Archived.cs b/OF DL/Models/Entities/Archived/Archived.cs new file mode 100644 index 0000000..80bd9f6 --- /dev/null +++ b/OF DL/Models/Entities/Archived/Archived.cs @@ -0,0 +1,10 @@ +namespace OF_DL.Models.Entities.Archived; + +public class Archived +{ + public List List { get; set; } = []; + + public bool HasMore { get; set; } + + public string? TailMarker { get; set; } +} diff --git a/OF DL/Models/Entities/Archived/ArchivedCollection.cs b/OF DL/Models/Entities/Archived/ArchivedCollection.cs new file mode 100644 index 0000000..d4662ed --- /dev/null +++ b/OF DL/Models/Entities/Archived/ArchivedCollection.cs @@ -0,0 +1,10 @@ +namespace OF_DL.Models.Entities.Archived; + +public class ArchivedCollection +{ + public List ArchivedPostMedia { get; set; } = []; + + public List ArchivedPostObjects { get; set; } = []; + + public Dictionary ArchivedPosts { get; set; } = new(); +} diff --git a/OF DL/Models/Entities/Archived/ListItem.cs b/OF DL/Models/Entities/Archived/ListItem.cs new file mode 100644 index 0000000..b7dd2d1 --- /dev/null +++ b/OF DL/Models/Entities/Archived/ListItem.cs @@ -0,0 +1,24 @@ +using OF_DL.Models.Entities.Common; + +namespace OF_DL.Models.Entities.Archived; + +public class ListItem +{ + public long Id { get; set; } + + public DateTime PostedAt { get; set; } + + public Author? Author { get; set; } + + public string? Text { get; set; } + + public string? Price { get; set; } + + public bool IsOpened { get; set; } + + public bool IsArchived { get; set; } + + public List? Media { get; set; } + + public List? Preview { get; set; } +} diff --git a/OF DL/Models/Entities/Archived/Medium.cs b/OF DL/Models/Entities/Archived/Medium.cs new file mode 100644 index 0000000..bebf52d --- /dev/null +++ b/OF DL/Models/Entities/Archived/Medium.cs @@ -0,0 +1,16 @@ +using OF_DL.Models.Entities.Common; + +namespace OF_DL.Models.Entities.Archived; + +public class Medium +{ + public long Id { get; set; } + + public string? Type { get; set; } + + public bool CanView { get; set; } + + public Files? Files { get; set; } + + public string? Preview { get; set; } +} diff --git a/OF DL/Models/Entities/Common/Author.cs b/OF DL/Models/Entities/Common/Author.cs new file mode 100644 index 0000000..50983e2 --- /dev/null +++ b/OF DL/Models/Entities/Common/Author.cs @@ -0,0 +1,6 @@ +namespace OF_DL.Models.Entities.Common; + +public class Author +{ + public long Id { get; set; } +} diff --git a/OF DL/Models/Entities/Common/Dash.cs b/OF DL/Models/Entities/Common/Dash.cs new file mode 100644 index 0000000..380f375 --- /dev/null +++ b/OF DL/Models/Entities/Common/Dash.cs @@ -0,0 +1,10 @@ +namespace OF_DL.Models.Entities.Common; + +public class Dash +{ + public string? CloudFrontPolicy { get; set; } + + public string? CloudFrontSignature { get; set; } + + public string? CloudFrontKeyPairId { get; set; } +} diff --git a/OF DL/Models/Entities/Common/Drm.cs b/OF DL/Models/Entities/Common/Drm.cs new file mode 100644 index 0000000..2ccdbbb --- /dev/null +++ b/OF DL/Models/Entities/Common/Drm.cs @@ -0,0 +1,8 @@ +namespace OF_DL.Models.Entities.Common; + +public class Drm +{ + public Manifest? Manifest { get; set; } + + public Signature? Signature { get; set; } +} diff --git a/OF DL/Models/Entities/Common/Files.cs b/OF DL/Models/Entities/Common/Files.cs new file mode 100644 index 0000000..4dec6a1 --- /dev/null +++ b/OF DL/Models/Entities/Common/Files.cs @@ -0,0 +1,8 @@ +namespace OF_DL.Models.Entities.Common; + +public class Files +{ + public Full? Full { get; set; } + + public Drm? Drm { get; set; } +} diff --git a/OF DL/Models/Entities/Common/Full.cs b/OF DL/Models/Entities/Common/Full.cs new file mode 100644 index 0000000..38032dc --- /dev/null +++ b/OF DL/Models/Entities/Common/Full.cs @@ -0,0 +1,6 @@ +namespace OF_DL.Models.Entities.Common; + +public class Full +{ + public string? Url { get; set; } +} diff --git a/OF DL/Models/Entities/Common/Manifest.cs b/OF DL/Models/Entities/Common/Manifest.cs new file mode 100644 index 0000000..dbb5f1f --- /dev/null +++ b/OF DL/Models/Entities/Common/Manifest.cs @@ -0,0 +1,6 @@ +namespace OF_DL.Models.Entities.Common; + +public class Manifest +{ + public string? Dash { get; set; } +} diff --git a/OF DL/Models/Entities/Common/Signature.cs b/OF DL/Models/Entities/Common/Signature.cs new file mode 100644 index 0000000..cb174ab --- /dev/null +++ b/OF DL/Models/Entities/Common/Signature.cs @@ -0,0 +1,6 @@ +namespace OF_DL.Models.Entities.Common; + +public class Signature +{ + public Dash? Dash { get; set; } +} diff --git a/OF DL/Models/Mappers/ArchivedMapper.cs b/OF DL/Models/Mappers/ArchivedMapper.cs new file mode 100644 index 0000000..22666b8 --- /dev/null +++ b/OF DL/Models/Mappers/ArchivedMapper.cs @@ -0,0 +1,137 @@ +using OF_DL.Models.Dtos.Archived; +using OF_DL.Models.Dtos.Common; +using OF_DL.Models.Entities.Archived; + +namespace OF_DL.Models.Mappers; + +public static class ArchivedMapper +{ + public static Archived FromDto(ArchivedDto? dto) + { + Archived mapped = new() { HasMore = dto?.HasMore ?? false, TailMarker = dto?.TailMarker }; + + if (dto?.List == null) + { + return mapped; + } + + foreach (ListItemDto entry in dto.List) + { + mapped.List.Add(MapList(entry)); + } + + return mapped; + } + + private static ListItem MapList(ListItemDto dto) => + new() + { + Id = dto.Id, + PostedAt = dto.PostedAt, + Author = MapAuthor(dto.Author), + Text = dto.Text, + Price = dto.Price, + IsOpened = dto.IsOpened, + IsArchived = dto.IsArchived, + Media = MapMedia(dto.Media), + Preview = dto.Preview + }; + + private static Entities.Common.Author? MapAuthor(AuthorDto? dto) + { + if (dto == null) + { + return null; + } + + return new Entities.Common.Author { Id = dto.Id }; + } + + private static List? MapMedia(List? media) + { + if (media == null) + { + return null; + } + + return media.Select(MapMedium).ToList(); + } + + private static Medium MapMedium(MediumDto dto) => + new() + { + Id = dto.Id, + Type = dto.Type, + CanView = dto.CanView, + Files = MapFiles(dto.Files), + Preview = dto.Preview + }; + + private static Entities.Common.Files? MapFiles(FilesDto? dto) + { + if (dto == null) + { + return null; + } + + return new Entities.Common.Files { Full = MapFull(dto.Full), Drm = MapDrm(dto.Drm) }; + } + + private static Entities.Common.Full? MapFull(FullDto? dto) + { + if (dto == null) + { + return null; + } + + return new Entities.Common.Full { Url = dto.Url }; + } + + private static Entities.Common.Drm? MapDrm(DrmDto? dto) + { + if (dto == null) + { + return null; + } + + return new Entities.Common.Drm + { + Manifest = MapManifest(dto.Manifest), Signature = MapSignature(dto.Signature) + }; + } + + private static Entities.Common.Manifest? MapManifest(ManifestDto? dto) + { + if (dto == null) + { + return null; + } + + return new Entities.Common.Manifest { Dash = dto.Dash }; + } + + private static Entities.Common.Signature? MapSignature(SignatureDto? dto) + { + if (dto == null) + { + return null; + } + + return new Entities.Common.Signature { Dash = MapDash(dto.Dash) }; + } + + private static Entities.Common.Dash? MapDash(DashDto? dto) + { + if (dto == null) + { + return null; + } + + return new Entities.Common.Dash + { + CloudFrontPolicy = dto.CloudFrontPolicy, + CloudFrontSignature = dto.CloudFrontSignature, + CloudFrontKeyPairId = dto.CloudFrontKeyPairId + }; + } +} diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 1e14abe..1cbe8d0 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -7,17 +7,16 @@ using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OF_DL.CLI; using OF_DL.Models; -using OF_DL.Models.Archived; using OF_DL.Models.Messages; using OF_DL.Models.Post; using OF_DL.Models.Purchased; using OF_DL.Models.Streams; using OF_DL.Enumerations; using OF_DL.Helpers; +using OF_DL.Models.Entities.Archived; using OF_DL.Services; using Serilog; using Spectre.Console; -using static OF_DL.Models.Messages.Messages; using Constants = OF_DL.Widevine.Constants; namespace OF_DL; @@ -1522,7 +1521,7 @@ public class Program(IServiceProvider serviceProvider) pssh); } - Medium? mediaInfo = + Messages.Medium? mediaInfo = purchasedPosts?.PaidPostMedia?.FirstOrDefault(m => m.id == purchasedPostKVP.Key); Purchased.List? postInfo = mediaInfo != null ? purchasedPosts?.PaidPostObjects?.FirstOrDefault(p => @@ -1557,7 +1556,7 @@ public class Program(IServiceProvider serviceProvider) } else { - Medium? mediaInfo = + Messages.Medium? mediaInfo = purchasedPosts?.PaidPostMedia?.FirstOrDefault(m => m.id == purchasedPostKVP.Key); Purchased.List? postInfo = mediaInfo != null ? purchasedPosts?.PaidPostObjects?.FirstOrDefault(p => @@ -1671,7 +1670,7 @@ public class Program(IServiceProvider serviceProvider) pssh); } - Medium? mediaInfo = + Messages.Medium? mediaInfo = paidMessageCollection.PaidMessageMedia.FirstOrDefault(m => m.id == paidMessageKVP.Key); Purchased.List? messageInfo = @@ -1708,7 +1707,7 @@ public class Program(IServiceProvider serviceProvider) } else { - Medium? mediaInfo = + Messages.Medium? mediaInfo = paidMessageCollection.PaidMessageMedia.FirstOrDefault(m => m.id == paidMessageKVP.Key); Purchased.List messageInfo = paidMessageCollection.PaidMessageObjects.FirstOrDefault(p => @@ -1898,7 +1897,7 @@ public class Program(IServiceProvider serviceProvider) pssh); } - Medium? mediaInfo = + Messages.Medium? mediaInfo = singlePaidMessageCollection.PreviewSingleMessageMedia.FirstOrDefault(m => m.id == paidMessageKVP.Key); SingleMessage? messageInfo = @@ -1935,7 +1934,7 @@ public class Program(IServiceProvider serviceProvider) } else { - Medium? mediaInfo = + Messages.Medium? mediaInfo = singlePaidMessageCollection.PreviewSingleMessageMedia.FirstOrDefault(m => m.id == paidMessageKVP.Key); SingleMessage? messageInfo = @@ -2038,7 +2037,7 @@ public class Program(IServiceProvider serviceProvider) pssh); } - Medium? mediaInfo = + Messages.Medium? mediaInfo = singlePaidMessageCollection.SingleMessageMedia.FirstOrDefault(m => m.id == paidMessageKVP.Key); SingleMessage? messageInfo = @@ -2075,7 +2074,7 @@ public class Program(IServiceProvider serviceProvider) } else { - Medium? mediaInfo = + Messages.Medium? mediaInfo = singlePaidMessageCollection.SingleMessageMedia.FirstOrDefault(m => m.id == paidMessageKVP.Key); SingleMessage? messageInfo = diff --git a/OF DL/Services/APIService.cs b/OF DL/Services/APIService.cs index a02f8f7..03cee60 100644 --- a/OF DL/Services/APIService.cs +++ b/OF DL/Services/APIService.cs @@ -6,7 +6,6 @@ using System.Xml.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OF_DL.Models; -using OF_DL.Models.Archived; using OF_DL.Models.Highlights; using OF_DL.Models.Lists; using OF_DL.Models.Messages; @@ -15,6 +14,10 @@ using OF_DL.Models.Purchased; using OF_DL.Models.Stories; using OF_DL.Models.Streams; using OF_DL.Enumerations; +using OF_DL.Models.Dtos.Archived; +using OF_DL.Models.Entities; +using OF_DL.Models.Entities.Archived; +using OF_DL.Models.Mappers; using OF_DL.Widevine; using Serilog; using Spectre.Console; @@ -1390,28 +1393,31 @@ public class APIService(IAuthService authService, IConfigService configService, configService.CurrentConfig.CustomDate); string? body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient()); - archived = JsonConvert.DeserializeObject(body, m_JsonSerializerSettings); - ctx.Status($"[red]Getting Archived Posts\n[/] [red]Found {archived.list.Count}[/]"); + ArchivedDto archivedDto = JsonConvert.DeserializeObject(body, m_JsonSerializerSettings); + archived = ArchivedMapper.FromDto(archivedDto); + ctx.Status($"[red]Getting Archived Posts\n[/] [red]Found {archived.List.Count}[/]"); ctx.Spinner(Spinner.Known.Dots); ctx.SpinnerStyle(Style.Parse("blue")); - if (archived != null && archived.hasMore) + if (archived != null && archived.HasMore) { UpdateGetParamsForDateSelection( downloadDateSelection, ref getParams, - archived.tailMarker); + archived.TailMarker); while (true) { Archived newarchived = new(); string? loopbody = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient()); - newarchived = JsonConvert.DeserializeObject(loopbody, m_JsonSerializerSettings); + ArchivedDto newarchivedDto = + JsonConvert.DeserializeObject(loopbody, m_JsonSerializerSettings); + newarchived = ArchivedMapper.FromDto(newarchivedDto); - archived.list.AddRange(newarchived.list); - ctx.Status($"[red]Getting Archived Posts\n[/] [red]Found {archived.list.Count}[/]"); + archived.List.AddRange(newarchived.List); + ctx.Status($"[red]Getting Archived Posts\n[/] [red]Found {archived.List.Count}[/]"); ctx.Spinner(Spinner.Known.Dots); ctx.SpinnerStyle(Style.Parse("blue")); - if (!newarchived.hasMore) + if (!newarchived.HasMore) { break; } @@ -1419,18 +1425,18 @@ public class APIService(IAuthService authService, IConfigService configService, UpdateGetParamsForDateSelection( downloadDateSelection, ref getParams, - newarchived.tailMarker); + newarchived.TailMarker); } } - foreach (Archived.List archive in archived.list) + foreach (ListItem archive in archived.List) { List previewids = new(); - if (archive.preview != null) + if (archive.Preview != null) { - for (int i = 0; i < archive.preview.Count; i++) + for (int i = 0; i < archive.Preview.Count; i++) { - if (archive.preview[i] is long previewId) + if (archive.Preview[i] is long previewId) { if (!previewids.Contains(previewId)) { @@ -1440,61 +1446,61 @@ public class APIService(IAuthService authService, IConfigService configService, } } - await dbService.AddPost(folder, archive.id, archive.text != null ? archive.text : string.Empty, - archive.price != null ? archive.price : "0", - archive.price != null && archive.isOpened ? true : false, archive.isArchived, archive.postedAt); + await dbService.AddPost(folder, archive.Id, archive.Text != null ? archive.Text : string.Empty, + archive.Price != null ? archive.Price : "0", + archive.Price != null && archive.IsOpened ? true : false, archive.IsArchived, archive.PostedAt); archivedCollection.ArchivedPostObjects.Add(archive); - if (archive.media != null && archive.media.Count > 0) + if (archive.Media != null && archive.Media.Count > 0) { - foreach (Archived.Medium medium in archive.media) + foreach (Medium medium in archive.Media) { - if (medium.type == "photo" && !configService.CurrentConfig.DownloadImages) + if (medium.Type == "photo" && !configService.CurrentConfig.DownloadImages) { continue; } - if (medium.type == "video" && !configService.CurrentConfig.DownloadVideos) + if (medium.Type == "video" && !configService.CurrentConfig.DownloadVideos) { continue; } - if (medium.type == "gif" && !configService.CurrentConfig.DownloadVideos) + if (medium.Type == "gif" && !configService.CurrentConfig.DownloadVideos) { continue; } - if (medium.type == "audio" && !configService.CurrentConfig.DownloadAudios) + if (medium.Type == "audio" && !configService.CurrentConfig.DownloadAudios) { continue; } - if (medium.canView && medium.files != null && medium.files.full != null && - !string.IsNullOrEmpty(medium.files.full.url)) + if (medium.CanView && medium.Files != null && medium.Files.Full != null && + !string.IsNullOrEmpty(medium.Files.Full.Url)) { - if (!archivedCollection.ArchivedPosts.ContainsKey(medium.id)) + if (!archivedCollection.ArchivedPosts.ContainsKey(medium.Id)) { - await dbService.AddMedia(folder, medium.id, archive.id, medium.files.full.url, null, + await dbService.AddMedia(folder, medium.Id, archive.Id, medium.Files.Full.Url, null, null, null, "Posts", - medium.type == "photo" ? "Images" : - medium.type == "video" || medium.type == "gif" ? "Videos" : - medium.type == "audio" ? "Audios" : null, - previewids.Contains(medium.id) ? true : false, false, null); - archivedCollection.ArchivedPosts.Add(medium.id, medium.files.full.url); + medium.Type == "photo" ? "Images" : + medium.Type == "video" || medium.Type == "gif" ? "Videos" : + medium.Type == "audio" ? "Audios" : null, + previewids.Contains(medium.Id) ? true : false, false, null); + archivedCollection.ArchivedPosts.Add(medium.Id, medium.Files.Full.Url); archivedCollection.ArchivedPostMedia.Add(medium); } } - else if (medium.canView && medium.files != null && medium.files.drm != null) + else if (medium.CanView && medium.Files != null && medium.Files.Drm != null) { - if (!archivedCollection.ArchivedPosts.ContainsKey(medium.id)) + if (!archivedCollection.ArchivedPosts.ContainsKey(medium.Id)) { - await dbService.AddMedia(folder, medium.id, archive.id, medium.files.drm.manifest.dash, + await dbService.AddMedia(folder, medium.Id, archive.Id, medium.Files.Drm.Manifest.Dash, null, null, null, "Posts", - medium.type == "photo" ? "Images" : - medium.type == "video" || medium.type == "gif" ? "Videos" : - medium.type == "audio" ? "Audios" : null, - previewids.Contains(medium.id) ? true : false, false, null); - archivedCollection.ArchivedPosts.Add(medium.id, - $"{medium.files.drm.manifest.dash},{medium.files.drm.signature.dash.CloudFrontPolicy},{medium.files.drm.signature.dash.CloudFrontSignature},{medium.files.drm.signature.dash.CloudFrontKeyPairId},{medium.id},{archive.id}"); + medium.Type == "photo" ? "Images" : + medium.Type == "video" || medium.Type == "gif" ? "Videos" : + medium.Type == "audio" ? "Audios" : null, + previewids.Contains(medium.Id) ? true : false, false, null); + archivedCollection.ArchivedPosts.Add(medium.Id, + $"{medium.Files.Drm.Manifest.Dash},{medium.Files.Drm.Signature.Dash.CloudFrontPolicy},{medium.Files.Drm.Signature.Dash.CloudFrontSignature},{medium.Files.Drm.Signature.Dash.CloudFrontKeyPairId},{medium.Id},{archive.Id}"); archivedCollection.ArchivedPostMedia.Add(medium); } } diff --git a/OF DL/Services/DownloadService.cs b/OF DL/Services/DownloadService.cs index 2867dc0..5495d8a 100644 --- a/OF DL/Services/DownloadService.cs +++ b/OF DL/Services/DownloadService.cs @@ -4,12 +4,13 @@ using System.Xml.Linq; using FFmpeg.NET; using FFmpeg.NET.Events; using OF_DL.Models; -using OF_DL.Models.Archived; using OF_DL.Models.Messages; using OF_DL.Models.Post; using OF_DL.Models.Purchased; using OF_DL.Models.Streams; using OF_DL.Enumerations; +using OF_DL.Models.Entities; +using OF_DL.Models.Entities.Archived; using OF_DL.Utils; using Serilog; using Serilog.Events; @@ -1036,7 +1037,7 @@ public class DownloadService( public async Task DownloadMessageMedia(string url, string folder, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, List? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, List? messageInfo, Messages.Medium? messageMedia, Messages.FromUser? fromUser, Dictionary users) { string path; @@ -1059,7 +1060,8 @@ public class DownloadService( } public async Task DownloadMessagePreviewMedia(string url, string folder, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, + Messages.Medium? messageMedia, FromUser? fromUser, Dictionary users) { string path; @@ -1083,8 +1085,9 @@ public class DownloadService( public async Task DownloadArchivedMedia(string url, string folder, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, Archived.List? messageInfo, - Archived.Medium? messageMedia, Archived.Author? author, Dictionary users) + IProgressReporter progressReporter, string? filenameFormat, ListItem? messageInfo, + OF_DL.Models.Entities.Archived.Medium? messageMedia, Models.Entities.Common.Author? author, + Dictionary users) { string path = "/Archived/Posts/Free"; Uri uri = new(url); @@ -1107,7 +1110,8 @@ public class DownloadService( } public async Task DownloadPurchasedMedia(string url, string folder, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, + Messages.Medium? messageMedia, Purchased.FromUser? fromUser, Dictionary users) { string path; @@ -1130,7 +1134,8 @@ public class DownloadService( } public async Task DownloadSinglePurchasedMedia(string url, string folder, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, + Messages.Medium? messageMedia, FromUser? fromUser, Dictionary users) { string path; @@ -1159,7 +1164,7 @@ public class DownloadService( IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, - Medium? messageMedia, + Messages.Medium? messageMedia, Purchased.FromUser? fromUser, Dictionary users) { @@ -1189,7 +1194,7 @@ public class DownloadService( public async Task DownloadMessageDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, List? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, List? messageInfo, Messages.Medium? messageMedia, Messages.FromUser? fromUser, Dictionary users) { try @@ -1318,7 +1323,8 @@ public class DownloadService( public async Task DownloadSingleMessagePreviewDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, + Messages.Medium? messageMedia, FromUser? fromUser, Dictionary users) { try @@ -1448,7 +1454,8 @@ public class DownloadService( public async Task DownloadPurchasedMessageDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, + Messages.Medium? messageMedia, Purchased.FromUser? fromUser, Dictionary users) { try @@ -1576,7 +1583,8 @@ public class DownloadService( public async Task DownloadSinglePurchasedMessageDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, + Messages.Medium? messageMedia, FromUser? fromUser, Dictionary users) { try @@ -2089,7 +2097,8 @@ public class DownloadService( public async Task DownloadPurchasedPostDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, Purchased.List? postInfo, Medium? postMedia, + IProgressReporter progressReporter, string? filenameFormat, Purchased.List? postInfo, + Messages.Medium? postMedia, Purchased.FromUser? fromUser, Dictionary users) { try @@ -2219,8 +2228,9 @@ public class DownloadService( public async Task DownloadArchivedPostDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, Archived.List? postInfo, Archived.Medium? postMedia, - Archived.Author? author, Dictionary users) + IProgressReporter progressReporter, string? filenameFormat, ListItem? postInfo, + OF_DL.Models.Entities.Archived.Medium? postMedia, + Models.Entities.Common.Author? author, Dictionary users) { try { @@ -2502,10 +2512,10 @@ public class DownloadService( pssh); } - Archived.Medium? mediaInfo = - archived.ArchivedPostMedia.FirstOrDefault(m => m.id == archivedKVP.Key); - Archived.List? postInfo = - archived.ArchivedPostObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); + OF_DL.Models.Entities.Archived.Medium? mediaInfo = + archived.ArchivedPostMedia.FirstOrDefault(m => m.Id == archivedKVP.Key); + ListItem? postInfo = + archived.ArchivedPostObjects.FirstOrDefault(p => p?.Media?.Contains(mediaInfo) == true); isNew = await DownloadArchivedPostDRMVideo( policy, @@ -2522,7 +2532,7 @@ public class DownloadService( string.Empty, postInfo, mediaInfo, - postInfo?.author, + postInfo?.Author, users); } else @@ -2532,9 +2542,10 @@ public class DownloadService( } else { - Archived.Medium? mediaInfo = archived.ArchivedPostMedia.FirstOrDefault(m => m.id == archivedKVP.Key); - Archived.List? postInfo = - archived.ArchivedPostObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); + OF_DL.Models.Entities.Archived.Medium? mediaInfo = + archived.ArchivedPostMedia.FirstOrDefault(m => m.Id == archivedKVP.Key); + ListItem? postInfo = + archived.ArchivedPostObjects.FirstOrDefault(p => p?.Media?.Contains(mediaInfo) == true); isNew = await DownloadArchivedMedia( archivedKVP.Value, @@ -2546,7 +2557,7 @@ public class DownloadService( string.Empty, postInfo, mediaInfo, - postInfo?.author, + postInfo?.Author, users); } @@ -2631,7 +2642,7 @@ public class DownloadService( pssh); } - Medium? mediaInfo = messages.MessageMedia.FirstOrDefault(m => m.id == messageKVP.Key); + Messages.Medium? mediaInfo = messages.MessageMedia.FirstOrDefault(m => m.id == messageKVP.Key); List? messageInfo = messages.MessageObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); @@ -2660,7 +2671,7 @@ public class DownloadService( } else { - Medium? mediaInfo = messages.MessageMedia.FirstOrDefault(m => m.id == messageKVP.Key); + Messages.Medium? mediaInfo = messages.MessageMedia.FirstOrDefault(m => m.id == messageKVP.Key); List? messageInfo = messages.MessageObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); isNew = await DownloadMessageMedia( @@ -2747,7 +2758,8 @@ public class DownloadService( $"https://onlyfans.com/api2/v2/users/media/{parsed[4]}/drm/message/{parsed[5]}?type=widevine", pssh); - Medium? mediaInfo = paidMessageCollection.PaidMessageMedia.FirstOrDefault(m => m.id == kvp.Key); + Messages.Medium? mediaInfo = + paidMessageCollection.PaidMessageMedia.FirstOrDefault(m => m.id == kvp.Key); Purchased.List? messageInfo = paidMessageCollection.PaidMessageObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); @@ -2764,7 +2776,8 @@ public class DownloadService( } else { - Medium? mediaInfo = paidMessageCollection.PaidMessageMedia.FirstOrDefault(m => m.id == kvp.Key); + Messages.Medium? mediaInfo = + paidMessageCollection.PaidMessageMedia.FirstOrDefault(m => m.id == kvp.Key); Purchased.List? messageInfo = paidMessageCollection.PaidMessageObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); isNew = await DownloadPurchasedMedia(kvp.Value, path, kvp.Key, "Messages", progressReporter, @@ -3020,7 +3033,7 @@ public class DownloadService( $"https://onlyfans.com/api2/v2/users/media/{parsed[4]}/drm/post/{parsed[5]}?type=widevine", pssh); - Medium? mediaInfo = purchasedPosts.PaidPostMedia.FirstOrDefault(m => m.id == postKVP.Key); + Messages.Medium? mediaInfo = purchasedPosts.PaidPostMedia.FirstOrDefault(m => m.id == postKVP.Key); Purchased.List? postInfo = purchasedPosts.PaidPostObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); @@ -3036,7 +3049,7 @@ public class DownloadService( } else { - Medium? mediaInfo = purchasedPosts.PaidPostMedia.FirstOrDefault(m => m.id == postKVP.Key); + Messages.Medium? mediaInfo = purchasedPosts.PaidPostMedia.FirstOrDefault(m => m.id == postKVP.Key); Purchased.List? postInfo = purchasedPosts.PaidPostObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); isNew = await DownloadPurchasedPostMedia(postKVP.Value, path, postKVP.Key, "Posts", progressReporter, diff --git a/OF DL/Services/IAPIService.cs b/OF DL/Services/IAPIService.cs index 869f50e..5606b5c 100644 --- a/OF DL/Services/IAPIService.cs +++ b/OF DL/Services/IAPIService.cs @@ -1,11 +1,11 @@ using Newtonsoft.Json.Linq; using OF_DL.Models; -using OF_DL.Models.Archived; using OF_DL.Models.Messages; using OF_DL.Models.Post; using OF_DL.Models.Purchased; using OF_DL.Models.Streams; using OF_DL.Enumerations; +using OF_DL.Models.Entities.Archived; using Spectre.Console; namespace OF_DL.Services; diff --git a/OF DL/Services/IDownloadService.cs b/OF DL/Services/IDownloadService.cs index 399702b..63916c3 100644 --- a/OF DL/Services/IDownloadService.cs +++ b/OF DL/Services/IDownloadService.cs @@ -1,5 +1,5 @@ using OF_DL.Models; -using OF_DL.Models.Archived; +using OF_DL.Models.Entities.Archived; using OF_DL.Models.Messages; using OF_DL.Models.Post; using OF_DL.Models.Purchased; @@ -17,13 +17,15 @@ public interface IDownloadService string serverFileName, string resolvedFileName, string extension, IProgressReporter progressReporter); Task DownloadArchivedMedia(string url, string folder, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, Archived.List? messageInfo, - Archived.Medium? messageMedia, Archived.Author? author, Dictionary users); + IProgressReporter progressReporter, string? filenameFormat, ListItem? messageInfo, + OF_DL.Models.Entities.Archived.Medium? messageMedia, Models.Entities.Common.Author? author, + Dictionary users); Task DownloadArchivedPostDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, Archived.List? postInfo, Archived.Medium? postMedia, - Archived.Author? author, Dictionary users); + IProgressReporter progressReporter, string? filenameFormat, ListItem? postInfo, + OF_DL.Models.Entities.Archived.Medium? postMedia, + Models.Entities.Common.Author? author, Dictionary users); Task DownloadPostDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, IProgressReporter progressReporter, @@ -39,11 +41,11 @@ public interface IDownloadService Task DownloadMessageDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, IProgressReporter progressReporter, - string? filenameFormat, List? messageInfo, Medium? messageMedia, Messages.FromUser? fromUser, + string? filenameFormat, List? messageInfo, Messages.Medium? messageMedia, Messages.FromUser? fromUser, Dictionary users); Task DownloadMessageMedia(string url, string folder, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, List? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, List? messageInfo, Messages.Medium? messageMedia, Messages.FromUser? fromUser, Dictionary users); Task DownloadPostMedia(string url, string folder, long media_id, string api_type, @@ -55,30 +57,36 @@ public interface IDownloadService SinglePost.Author? author, Dictionary users); Task DownloadPurchasedMedia(string url, string folder, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, + Messages.Medium? messageMedia, Purchased.FromUser? fromUser, Dictionary users); Task DownloadSinglePurchasedMedia(string url, string folder, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, + Messages.Medium? messageMedia, FromUser? fromUser, Dictionary users); Task DownloadPurchasedMessageDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, + Messages.Medium? messageMedia, Purchased.FromUser? fromUser, Dictionary users); Task DownloadSinglePurchasedMessageDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, + Messages.Medium? messageMedia, FromUser? fromUser, Dictionary users); Task DownloadPurchasedPostDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, Purchased.List? postInfo, Medium? postMedia, + IProgressReporter progressReporter, string? filenameFormat, Purchased.List? postInfo, + Messages.Medium? postMedia, Purchased.FromUser? fromUser, Dictionary users); Task DownloadPurchasedPostMedia(string url, string folder, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, + Messages.Medium? messageMedia, Purchased.FromUser? fromUser, Dictionary users); Task DownloadStoryMedia(string url, string folder, long media_id, string api_type, @@ -95,11 +103,13 @@ public interface IDownloadService Task DownloadSingleMessagePreviewDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, string folder, DateTime lastModified, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, + Messages.Medium? messageMedia, FromUser? fromUser, Dictionary users); Task DownloadMessagePreviewMedia(string url, string folder, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, + Messages.Medium? messageMedia, FromUser? fromUser, Dictionary users); Task DownloadHighlights(string username, long userId, string path, HashSet paidPostIds,