From 2e3f17945e231a4eaf66b161a4daae37e133a004 Mon Sep 17 00:00:00 2001 From: whimsical-c4lic0 Date: Sun, 8 Feb 2026 16:16:38 -0600 Subject: [PATCH] Refactor Highlight entities into DTOs and application entities with standardized naming conventions and default values --- OF DL/Models/Dtos/Common/PreviewDto.cs | 2 + OF DL/Models/Dtos/Common/SquarePreviewDto.cs | 2 + .../Dtos/Highlights/HighlightMediaDto.cs | 22 +++ OF DL/Models/Dtos/Highlights/HighlightsDto.cs | 10 ++ OF DL/Models/Dtos/Highlights/ListItemDto.cs | 20 +++ OF DL/Models/Dtos/Highlights/MediumDto.cs | 21 +++ OF DL/Models/Dtos/Highlights/StoryDto.cs | 24 ++++ .../Entities/Highlights/HighlightMedia.cs | 6 + .../Models/Entities/Highlights/Highlights.cs | 8 ++ OF DL/Models/Entities/Highlights/ListItem.cs | 6 + OF DL/Models/Entities/Highlights/Medium.cs | 16 +++ OF DL/Models/Entities/Highlights/Story.cs | 10 ++ OF DL/Models/Highlights/HighlightMedia.cs | 102 ------------- OF DL/Models/Highlights/Highlights.cs | 18 --- OF DL/Models/Mappers/HighlightsMapper.cs | 66 +++++++++ OF DL/Program.cs | 20 +-- OF DL/Services/APIService.cs | 134 +++++++++--------- OF DL/Services/DownloadService.cs | 53 ++++--- OF DL/Services/IAPIService.cs | 4 +- OF DL/Services/IDownloadService.cs | 32 ++--- 20 files changed, 335 insertions(+), 241 deletions(-) create mode 100644 OF DL/Models/Dtos/Highlights/HighlightMediaDto.cs create mode 100644 OF DL/Models/Dtos/Highlights/HighlightsDto.cs create mode 100644 OF DL/Models/Dtos/Highlights/ListItemDto.cs create mode 100644 OF DL/Models/Dtos/Highlights/MediumDto.cs create mode 100644 OF DL/Models/Dtos/Highlights/StoryDto.cs create mode 100644 OF DL/Models/Entities/Highlights/HighlightMedia.cs create mode 100644 OF DL/Models/Entities/Highlights/Highlights.cs create mode 100644 OF DL/Models/Entities/Highlights/ListItem.cs create mode 100644 OF DL/Models/Entities/Highlights/Medium.cs create mode 100644 OF DL/Models/Entities/Highlights/Story.cs delete mode 100644 OF DL/Models/Highlights/HighlightMedia.cs delete mode 100644 OF DL/Models/Highlights/Highlights.cs create mode 100644 OF DL/Models/Mappers/HighlightsMapper.cs diff --git a/OF DL/Models/Dtos/Common/PreviewDto.cs b/OF DL/Models/Dtos/Common/PreviewDto.cs index ad19606..c33df6b 100644 --- a/OF DL/Models/Dtos/Common/PreviewDto.cs +++ b/OF DL/Models/Dtos/Common/PreviewDto.cs @@ -11,4 +11,6 @@ public class PreviewDto [JsonProperty("size")] public int? Size { get; set; } [JsonProperty("url")] public string Url { get; set; } = ""; + + [JsonProperty("sources")] public SourcesDto Sources { get; set; } = new(); } diff --git a/OF DL/Models/Dtos/Common/SquarePreviewDto.cs b/OF DL/Models/Dtos/Common/SquarePreviewDto.cs index 1457778..d5f8f82 100644 --- a/OF DL/Models/Dtos/Common/SquarePreviewDto.cs +++ b/OF DL/Models/Dtos/Common/SquarePreviewDto.cs @@ -11,4 +11,6 @@ public class SquarePreviewDto [JsonProperty("height")] public int Height { get; set; } [JsonProperty("size")] public long Size { get; set; } + + [JsonProperty("sources")] public SourcesDto Sources { get; set; } = new(); } diff --git a/OF DL/Models/Dtos/Highlights/HighlightMediaDto.cs b/OF DL/Models/Dtos/Highlights/HighlightMediaDto.cs new file mode 100644 index 0000000..1ceba1d --- /dev/null +++ b/OF DL/Models/Dtos/Highlights/HighlightMediaDto.cs @@ -0,0 +1,22 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Highlights; + +public class HighlightMediaDto +{ + [JsonProperty("id")] public long Id { get; set; } + + [JsonProperty("userId")] public long UserId { get; set; } + + [JsonProperty("title")] public string Title { get; set; } = ""; + + [JsonProperty("coverStoryId")] public long CoverStoryId { get; set; } + + [JsonProperty("cover")] public string Cover { get; set; } = ""; + + [JsonProperty("storiesCount")] public int StoriesCount { get; set; } + + [JsonProperty("createdAt")] public DateTime? CreatedAt { get; set; } + + [JsonProperty("stories")] public List Stories { get; set; } = []; +} diff --git a/OF DL/Models/Dtos/Highlights/HighlightsDto.cs b/OF DL/Models/Dtos/Highlights/HighlightsDto.cs new file mode 100644 index 0000000..1178828 --- /dev/null +++ b/OF DL/Models/Dtos/Highlights/HighlightsDto.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Highlights; + +public class HighlightsDto +{ + [JsonProperty("list")] public List List { get; set; } = []; + + [JsonProperty("hasMore")] public bool HasMore { get; set; } +} diff --git a/OF DL/Models/Dtos/Highlights/ListItemDto.cs b/OF DL/Models/Dtos/Highlights/ListItemDto.cs new file mode 100644 index 0000000..ffeecd7 --- /dev/null +++ b/OF DL/Models/Dtos/Highlights/ListItemDto.cs @@ -0,0 +1,20 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Highlights; + +public class ListItemDto +{ + [JsonProperty("id")] public long Id { get; set; } + + [JsonProperty("userId")] public long UserId { get; set; } + + [JsonProperty("title")] public string Title { get; set; } = ""; + + [JsonProperty("coverStoryId")] public long CoverStoryId { get; set; } + + [JsonProperty("cover")] public string Cover { get; set; } = ""; + + [JsonProperty("storiesCount")] public int StoriesCount { get; set; } + + [JsonProperty("createdAt")] public DateTime? CreatedAt { get; set; } +} diff --git a/OF DL/Models/Dtos/Highlights/MediumDto.cs b/OF DL/Models/Dtos/Highlights/MediumDto.cs new file mode 100644 index 0000000..cf6bc4c --- /dev/null +++ b/OF DL/Models/Dtos/Highlights/MediumDto.cs @@ -0,0 +1,21 @@ +using Newtonsoft.Json; +using OF_DL.Models.Dtos.Common; + +namespace OF_DL.Models.Dtos.Highlights; + +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; } + + [JsonProperty("files")] public FilesDto Files { get; set; } = new(); +} diff --git a/OF DL/Models/Dtos/Highlights/StoryDto.cs b/OF DL/Models/Dtos/Highlights/StoryDto.cs new file mode 100644 index 0000000..053215a --- /dev/null +++ b/OF DL/Models/Dtos/Highlights/StoryDto.cs @@ -0,0 +1,24 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Highlights; + +public class StoryDto +{ + [JsonProperty("id")] public long Id { get; set; } + + [JsonProperty("userId")] public long UserId { get; set; } + + [JsonProperty("isWatched")] public bool IsWatched { get; set; } + + [JsonProperty("isReady")] public bool IsReady { get; set; } + + [JsonProperty("media")] public List Media { get; set; } = []; + + [JsonProperty("createdAt")] public DateTime? CreatedAt { get; set; } + + [JsonProperty("question")] public object Question { get; set; } = new(); + + [JsonProperty("canLike")] public bool CanLike { get; set; } + + [JsonProperty("isLiked")] public bool IsLiked { get; set; } +} diff --git a/OF DL/Models/Entities/Highlights/HighlightMedia.cs b/OF DL/Models/Entities/Highlights/HighlightMedia.cs new file mode 100644 index 0000000..e082a0a --- /dev/null +++ b/OF DL/Models/Entities/Highlights/HighlightMedia.cs @@ -0,0 +1,6 @@ +namespace OF_DL.Models.Entities.Highlights; + +public class HighlightMedia +{ + public List Stories { get; set; } = []; +} diff --git a/OF DL/Models/Entities/Highlights/Highlights.cs b/OF DL/Models/Entities/Highlights/Highlights.cs new file mode 100644 index 0000000..a0a916c --- /dev/null +++ b/OF DL/Models/Entities/Highlights/Highlights.cs @@ -0,0 +1,8 @@ +namespace OF_DL.Models.Entities.Highlights; + +public class Highlights +{ + public List List { get; set; } = []; + + public bool HasMore { get; set; } +} diff --git a/OF DL/Models/Entities/Highlights/ListItem.cs b/OF DL/Models/Entities/Highlights/ListItem.cs new file mode 100644 index 0000000..6d6a407 --- /dev/null +++ b/OF DL/Models/Entities/Highlights/ListItem.cs @@ -0,0 +1,6 @@ +namespace OF_DL.Models.Entities.Highlights; + +public class ListItem +{ + public long Id { get; set; } +} diff --git a/OF DL/Models/Entities/Highlights/Medium.cs b/OF DL/Models/Entities/Highlights/Medium.cs new file mode 100644 index 0000000..e3855eb --- /dev/null +++ b/OF DL/Models/Entities/Highlights/Medium.cs @@ -0,0 +1,16 @@ +using OF_DL.Models.Entities.Common; + +namespace OF_DL.Models.Entities.Highlights; + +public class Medium +{ + public long Id { get; set; } + + public string? Type { get; set; } + + public bool CanView { get; set; } + + public DateTime? CreatedAt { get; set; } + + public Files? Files { get; set; } +} diff --git a/OF DL/Models/Entities/Highlights/Story.cs b/OF DL/Models/Entities/Highlights/Story.cs new file mode 100644 index 0000000..ef2fb81 --- /dev/null +++ b/OF DL/Models/Entities/Highlights/Story.cs @@ -0,0 +1,10 @@ +namespace OF_DL.Models.Entities.Highlights; + +public class Story +{ + public long Id { get; set; } + + public DateTime? CreatedAt { get; set; } + + public List? Media { get; set; } +} diff --git a/OF DL/Models/Highlights/HighlightMedia.cs b/OF DL/Models/Highlights/HighlightMedia.cs deleted file mode 100644 index 93c4c92..0000000 --- a/OF DL/Models/Highlights/HighlightMedia.cs +++ /dev/null @@ -1,102 +0,0 @@ -using Newtonsoft.Json; - -namespace OF_DL.Models.Highlights; - -public class HighlightMedia -{ - public long id { get; set; } - public long userId { get; set; } - public string title { get; set; } - public long coverStoryId { get; set; } - public string cover { get; set; } - public int storiesCount { get; set; } - public DateTime? createdAt { get; set; } - public List stories { 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 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 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 Files files { get; set; } - } - - public class Preview - { - public string url { get; set; } - public int width { get; set; } - public int height { get; set; } - public long size { get; set; } - public Sources sources { get; set; } - } - - public class Source - { - public string url { get; set; } - public int width { get; set; } - public int height { get; set; } - public int duration { get; set; } - public long size { get; set; } - public Sources sources { get; set; } - } - - public class Sources - { - [JsonProperty("720")] public string _720 { get; set; } - - [JsonProperty("240")] public string _240 { get; set; } - - public string w150 { get; set; } - public string w480 { 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 Sources sources { get; set; } - } - - public class Story - { - public long id { get; set; } - public long userId { get; set; } - public bool isWatched { get; set; } - public bool isReady { get; set; } - public List media { get; set; } - public DateTime? createdAt { get; set; } - public object question { get; set; } - public bool canLike { get; set; } - public bool isLiked { 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; } - } -} diff --git a/OF DL/Models/Highlights/Highlights.cs b/OF DL/Models/Highlights/Highlights.cs deleted file mode 100644 index 7057a8a..0000000 --- a/OF DL/Models/Highlights/Highlights.cs +++ /dev/null @@ -1,18 +0,0 @@ -namespace OF_DL.Models.Highlights; - -public class Highlights -{ - public List list { get; set; } - public bool hasMore { get; set; } - - public class List - { - public long id { get; set; } - public long userId { get; set; } - public string title { get; set; } - public long coverStoryId { get; set; } - public string cover { get; set; } - public int storiesCount { get; set; } - public DateTime? createdAt { get; set; } - } -} diff --git a/OF DL/Models/Mappers/HighlightsMapper.cs b/OF DL/Models/Mappers/HighlightsMapper.cs new file mode 100644 index 0000000..450ea00 --- /dev/null +++ b/OF DL/Models/Mappers/HighlightsMapper.cs @@ -0,0 +1,66 @@ +using OF_DL.Models.Dtos.Common; +using OF_DL.Models.Dtos.Highlights; +using OF_DL.Models.Entities.Common; +using OF_DL.Models.Entities.Highlights; + +namespace OF_DL.Models.Mappers; + +public static class HighlightsMapper +{ + public static Highlights FromDto(HighlightsDto? dto) + { + Highlights mapped = new() { HasMore = dto?.HasMore ?? false }; + + if (dto?.List == null) + { + return mapped; + } + + foreach (ListItemDto entry in dto.List) + { + mapped.List.Add(MapListItem(entry)); + } + + return mapped; + } + + public static HighlightMedia FromDto(HighlightMediaDto? dto) + { + HighlightMedia mapped = new(); + + if (dto?.Stories == null) + { + return mapped; + } + + foreach (StoryDto story in dto.Stories) + { + mapped.Stories.Add(MapStory(story)); + } + + return mapped; + } + + private static ListItem MapListItem(ListItemDto dto) => new() { Id = dto.Id }; + + private static Story MapStory(StoryDto dto) => + new() { Id = dto.Id, CreatedAt = dto.CreatedAt, Media = MapMedia(dto.Media) }; + + private static List? MapMedia(List? media) => + media?.Select(MapMedium).ToList(); + + private static Medium MapMedium(MediumDto dto) => + new() + { + Id = dto.Id, + Type = dto.Type, + CanView = dto.CanView, + CreatedAt = dto.CreatedAt, + Files = MapFiles(dto.Files) + }; + + private static Files? MapFiles(FilesDto? dto) => dto == null ? null : new Files { Full = MapFull(dto.Full) }; + + private static Full? MapFull(FullDto? dto) => + dto == null ? null : new Full { Url = dto.Url }; +} diff --git a/OF DL/Program.cs b/OF DL/Program.cs index 1cbe8d0..18250ce 100644 --- a/OF DL/Program.cs +++ b/OF DL/Program.cs @@ -13,11 +13,11 @@ 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 ArchivedModels = OF_DL.Models.Entities.Archived; using OF_DL.Services; using Serilog; using Spectre.Console; -using Constants = OF_DL.Widevine.Constants; +using WidevineConstants = OF_DL.Widevine.Constants; namespace OF_DL; @@ -502,7 +502,8 @@ public class Program(IServiceProvider serviceProvider) Environment.Exit(4); } - if (!File.Exists(Path.Join(Constants.DEVICES_FOLDER, Constants.DEVICE_NAME, "device_client_id_blob"))) + if (!File.Exists(Path.Join(WidevineConstants.DEVICES_FOLDER, WidevineConstants.DEVICE_NAME, + "device_client_id_blob"))) { clientIdBlobMissing = true; Log.Debug("clientIdBlobMissing missing"); @@ -510,11 +511,12 @@ public class Program(IServiceProvider serviceProvider) else { AnsiConsole.Markup("[green]device_client_id_blob located successfully![/]\n"); - Log.Debug("clientIdBlobMissing found: " + File.Exists(Path.Join(Constants.DEVICES_FOLDER, - Constants.DEVICE_NAME, "device_client_id_blob"))); + Log.Debug("clientIdBlobMissing found: " + File.Exists(Path.Join(WidevineConstants.DEVICES_FOLDER, + WidevineConstants.DEVICE_NAME, "device_client_id_blob"))); } - if (!File.Exists(Path.Join(Constants.DEVICES_FOLDER, Constants.DEVICE_NAME, "device_private_key"))) + if (!File.Exists(Path.Join(WidevineConstants.DEVICES_FOLDER, WidevineConstants.DEVICE_NAME, + "device_private_key"))) { devicePrivateKeyMissing = true; Log.Debug("devicePrivateKeyMissing missing"); @@ -522,8 +524,8 @@ public class Program(IServiceProvider serviceProvider) else { AnsiConsole.Markup("[green]device_private_key located successfully![/]\n"); - Log.Debug("devicePrivateKeyMissing found: " + File.Exists(Path.Join(Constants.DEVICES_FOLDER, - Constants.DEVICE_NAME, "device_private_key"))); + Log.Debug("devicePrivateKeyMissing found: " + File.Exists(Path.Join(WidevineConstants.DEVICES_FOLDER, + WidevineConstants.DEVICE_NAME, "device_private_key"))); } if (clientIdBlobMissing || devicePrivateKeyMissing) @@ -1272,7 +1274,7 @@ public class Program(IServiceProvider serviceProvider) IAPIService apiService = serviceProvider.GetRequiredService(); IDownloadService downloadService = serviceProvider.GetRequiredService(); - ArchivedCollection archived = new(); + ArchivedModels.ArchivedCollection archived = new(); await AnsiConsole.Status() .StartAsync("[red]Getting Archived Posts[/]", diff --git a/OF DL/Services/APIService.cs b/OF DL/Services/APIService.cs index 03cee60..04beede 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.Highlights; using OF_DL.Models.Lists; using OF_DL.Models.Messages; using OF_DL.Models.Post; @@ -15,8 +14,9 @@ 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.Dtos.Highlights; +using ArchivedModels = OF_DL.Models.Entities.Archived; +using HighlightEntities = OF_DL.Models.Entities.Highlights; using OF_DL.Models.Mappers; using OF_DL.Widevine; using Serilog; @@ -452,24 +452,25 @@ public class APIService(IAuthService authService, IConfigService configService, else if (mediatype == MediaType.Highlights) { List highlight_ids = new(); - Highlights highlights = JsonConvert.DeserializeObject(body, m_JsonSerializerSettings) ?? - new Highlights(); + HighlightsDto? highlightsDto = + JsonConvert.DeserializeObject(body, m_JsonSerializerSettings); + HighlightEntities.Highlights highlights = HighlightsMapper.FromDto(highlightsDto); - if (highlights.hasMore) + if (highlights.HasMore) { offset += 5; getParams["offset"] = offset.ToString(); while (true) { - Highlights newhighlights = new(); - Log.Debug("Media Highlights - " + endpoint); string? loopbody = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient()); - newhighlights = JsonConvert.DeserializeObject(loopbody, m_JsonSerializerSettings); + HighlightsDto? newHighlightsDto = + JsonConvert.DeserializeObject(loopbody, m_JsonSerializerSettings); + HighlightEntities.Highlights newHighlights = HighlightsMapper.FromDto(newHighlightsDto); - highlights.list.AddRange(newhighlights.list); - if (!newhighlights.hasMore) + highlights.List.AddRange(newHighlights.List); + if (!newHighlights.HasMore) { break; } @@ -479,17 +480,16 @@ public class APIService(IAuthService authService, IConfigService configService, } } - foreach (Highlights.List list in highlights.list) + foreach (HighlightEntities.ListItem list in highlights.List) { - if (!highlight_ids.Contains(list.id.ToString())) + if (!highlight_ids.Contains(list.Id.ToString())) { - highlight_ids.Add(list.id.ToString()); + highlight_ids.Add(list.Id.ToString()); } } foreach (string highlight_id in highlight_ids) { - HighlightMedia highlightMedia = new(); Dictionary highlight_headers = GetDynamicHeaders("/api2/v2/stories/highlights/" + highlight_id, string.Empty); @@ -506,61 +506,61 @@ public class APIService(IAuthService authService, IConfigService configService, using HttpResponseMessage highlightResponse = await highlight_client.SendAsync(highlight_request); highlightResponse.EnsureSuccessStatusCode(); string highlightBody = await highlightResponse.Content.ReadAsStringAsync(); - highlightMedia = - JsonConvert.DeserializeObject(highlightBody, m_JsonSerializerSettings); - if (highlightMedia != null) + HighlightMediaDto? highlightMediaDto = + JsonConvert.DeserializeObject(highlightBody, m_JsonSerializerSettings); + HighlightEntities.HighlightMedia highlightMedia = HighlightsMapper.FromDto(highlightMediaDto); + + foreach (HighlightEntities.Story item in highlightMedia.Stories) { - foreach (HighlightMedia.Story item in highlightMedia.stories) + if (item.Media != null && item.Media.Count > 0 && item.Media[0].CreatedAt.HasValue) { - if (item.media[0].createdAt.HasValue) - { - await dbService.AddStory(folder, item.id, string.Empty, "0", false, false, - item.media[0].createdAt.Value); - } - else if (item.createdAt.HasValue) - { - await dbService.AddStory(folder, item.id, string.Empty, "0", false, false, - item.createdAt.Value); - } - else - { - await dbService.AddStory(folder, item.id, string.Empty, "0", false, false, - DateTime.Now); - } + await dbService.AddStory(folder, item.Id, string.Empty, "0", false, false, + item.Media[0].CreatedAt.Value); + } + else if (item.CreatedAt.HasValue) + { + await dbService.AddStory(folder, item.Id, string.Empty, "0", false, false, + item.CreatedAt.Value); + } + else + { + await dbService.AddStory(folder, item.Id, string.Empty, "0", false, false, + DateTime.Now); + } - if (item.media.Count > 0 && item.media[0].canView) + if (item.Media != null && item.Media.Count > 0 && item.Media[0].CanView) + { + foreach (HighlightEntities.Medium medium in item.Media) { - foreach (HighlightMedia.Medium medium in item.media) + string storyUrl = item.Media[0].Files?.Full?.Url ?? string.Empty; + await dbService.AddMedia(folder, medium.Id, item.Id, storyUrl, null, null, null, + "Stories", + medium.Type == "photo" ? "Images" : + medium.Type == "video" || medium.Type == "gif" ? "Videos" : + medium.Type == "audio" ? "Audios" : null, false, false, null); + if (medium.Type == "photo" && !configService.CurrentConfig.DownloadImages) { - await dbService.AddMedia(folder, medium.id, item.id, item.media[0].files.full.url, - null, null, null, "Stories", - medium.type == "photo" ? "Images" : - medium.type == "video" || medium.type == "gif" ? "Videos" : - medium.type == "audio" ? "Audios" : null, false, false, null); - if (medium.type == "photo" && !configService.CurrentConfig.DownloadImages) - { - continue; - } + continue; + } - if (medium.type == "video" && !configService.CurrentConfig.DownloadVideos) - { - continue; - } + if (medium.Type == "video" && !configService.CurrentConfig.DownloadVideos) + { + continue; + } - if (medium.type == "gif" && !configService.CurrentConfig.DownloadVideos) - { - continue; - } + if (medium.Type == "gif" && !configService.CurrentConfig.DownloadVideos) + { + continue; + } - if (medium.type == "audio" && !configService.CurrentConfig.DownloadAudios) - { - continue; - } + if (medium.Type == "audio" && !configService.CurrentConfig.DownloadAudios) + { + continue; + } - if (!return_urls.ContainsKey(medium.id)) - { - return_urls.Add(medium.id, item.media[0].files.full.url); - } + if (!return_urls.ContainsKey(medium.Id) && !string.IsNullOrEmpty(storyUrl)) + { + return_urls.Add(medium.Id, storyUrl); } } } @@ -1361,14 +1361,14 @@ public class APIService(IAuthService authService, IConfigService configService, } - public async Task GetArchived(string endpoint, string folder, StatusContext ctx) + public async Task GetArchived(string endpoint, string folder, StatusContext ctx) { Log.Debug($"Calling GetArchived - {endpoint}"); try { - Archived archived = new(); - ArchivedCollection archivedCollection = new(); + ArchivedModels.Archived archived = new(); + ArchivedModels.ArchivedCollection archivedCollection = new(); int post_limit = 50; Dictionary getParams = new() { @@ -1406,7 +1406,7 @@ public class APIService(IAuthService authService, IConfigService configService, archived.TailMarker); while (true) { - Archived newarchived = new(); + ArchivedModels.Archived newarchived = new(); string? loopbody = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient()); ArchivedDto newarchivedDto = @@ -1429,7 +1429,7 @@ public class APIService(IAuthService authService, IConfigService configService, } } - foreach (ListItem archive in archived.List) + foreach (ArchivedModels.ListItem archive in archived.List) { List previewids = new(); if (archive.Preview != null) @@ -1452,7 +1452,7 @@ public class APIService(IAuthService authService, IConfigService configService, archivedCollection.ArchivedPostObjects.Add(archive); if (archive.Media != null && archive.Media.Count > 0) { - foreach (Medium medium in archive.Media) + foreach (ArchivedModels.Medium medium in archive.Media) { if (medium.Type == "photo" && !configService.CurrentConfig.DownloadImages) { diff --git a/OF DL/Services/DownloadService.cs b/OF DL/Services/DownloadService.cs index 5495d8a..509433b 100644 --- a/OF DL/Services/DownloadService.cs +++ b/OF DL/Services/DownloadService.cs @@ -9,8 +9,7 @@ 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 ArchivedModels = OF_DL.Models.Entities.Archived; using OF_DL.Utils; using Serilog; using Serilog.Events; @@ -1037,7 +1036,7 @@ public class DownloadService( public async Task DownloadMessageMedia(string url, string folder, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, List? messageInfo, Messages.Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, List? messageInfo, Medium? messageMedia, Messages.FromUser? fromUser, Dictionary users) { string path; @@ -1061,7 +1060,7 @@ public class DownloadService( public async Task DownloadMessagePreviewMedia(string url, string folder, long media_id, string api_type, IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, - Messages.Medium? messageMedia, + Medium? messageMedia, FromUser? fromUser, Dictionary users) { string path; @@ -1085,8 +1084,8 @@ public class DownloadService( public async Task DownloadArchivedMedia(string url, string folder, long media_id, string api_type, - IProgressReporter progressReporter, string? filenameFormat, ListItem? messageInfo, - OF_DL.Models.Entities.Archived.Medium? messageMedia, Models.Entities.Common.Author? author, + IProgressReporter progressReporter, string? filenameFormat, ArchivedModels.ListItem? messageInfo, + ArchivedModels.Medium? messageMedia, Models.Entities.Common.Author? author, Dictionary users) { string path = "/Archived/Posts/Free"; @@ -1111,7 +1110,7 @@ public class DownloadService( public async Task DownloadPurchasedMedia(string url, string folder, long media_id, string api_type, IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, - Messages.Medium? messageMedia, + Medium? messageMedia, Purchased.FromUser? fromUser, Dictionary users) { string path; @@ -1135,7 +1134,7 @@ public class DownloadService( public async Task DownloadSinglePurchasedMedia(string url, string folder, long media_id, string api_type, IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, - Messages.Medium? messageMedia, + Medium? messageMedia, FromUser? fromUser, Dictionary users) { string path; @@ -1164,7 +1163,7 @@ public class DownloadService( IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, - Messages.Medium? messageMedia, + Medium? messageMedia, Purchased.FromUser? fromUser, Dictionary users) { @@ -1194,7 +1193,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, Messages.Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, List? messageInfo, Medium? messageMedia, Messages.FromUser? fromUser, Dictionary users) { try @@ -1324,7 +1323,7 @@ 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, - Messages.Medium? messageMedia, + Medium? messageMedia, FromUser? fromUser, Dictionary users) { try @@ -1455,7 +1454,7 @@ 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, - Messages.Medium? messageMedia, + Medium? messageMedia, Purchased.FromUser? fromUser, Dictionary users) { try @@ -1584,7 +1583,7 @@ 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, - Messages.Medium? messageMedia, + Medium? messageMedia, FromUser? fromUser, Dictionary users) { try @@ -2098,7 +2097,7 @@ 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, - Messages.Medium? postMedia, + Medium? postMedia, Purchased.FromUser? fromUser, Dictionary users) { try @@ -2228,8 +2227,8 @@ 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, ListItem? postInfo, - OF_DL.Models.Entities.Archived.Medium? postMedia, + IProgressReporter progressReporter, string? filenameFormat, ArchivedModels.ListItem? postInfo, + ArchivedModels.Medium? postMedia, Models.Entities.Common.Author? author, Dictionary users) { try @@ -2455,7 +2454,7 @@ public class DownloadService( public async Task DownloadArchived(string username, long userId, string path, Dictionary users, bool clientIdBlobMissing, bool devicePrivateKeyMissing, - ArchivedCollection archived, IProgressReporter progressReporter) + ArchivedModels.ArchivedCollection archived, IProgressReporter progressReporter) { Log.Debug($"Calling DownloadArchived - {username}"); @@ -2512,9 +2511,9 @@ public class DownloadService( pssh); } - OF_DL.Models.Entities.Archived.Medium? mediaInfo = + ArchivedModels.Medium? mediaInfo = archived.ArchivedPostMedia.FirstOrDefault(m => m.Id == archivedKVP.Key); - ListItem? postInfo = + ArchivedModels.ListItem? postInfo = archived.ArchivedPostObjects.FirstOrDefault(p => p?.Media?.Contains(mediaInfo) == true); isNew = await DownloadArchivedPostDRMVideo( @@ -2542,9 +2541,9 @@ public class DownloadService( } else { - OF_DL.Models.Entities.Archived.Medium? mediaInfo = + ArchivedModels.Medium? mediaInfo = archived.ArchivedPostMedia.FirstOrDefault(m => m.Id == archivedKVP.Key); - ListItem? postInfo = + ArchivedModels.ListItem? postInfo = archived.ArchivedPostObjects.FirstOrDefault(p => p?.Media?.Contains(mediaInfo) == true); isNew = await DownloadArchivedMedia( @@ -2642,7 +2641,7 @@ public class DownloadService( pssh); } - Messages.Medium? mediaInfo = messages.MessageMedia.FirstOrDefault(m => m.id == messageKVP.Key); + Medium? mediaInfo = messages.MessageMedia.FirstOrDefault(m => m.id == messageKVP.Key); List? messageInfo = messages.MessageObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); @@ -2671,7 +2670,7 @@ public class DownloadService( } else { - Messages.Medium? mediaInfo = messages.MessageMedia.FirstOrDefault(m => m.id == messageKVP.Key); + Medium? mediaInfo = messages.MessageMedia.FirstOrDefault(m => m.id == messageKVP.Key); List? messageInfo = messages.MessageObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); isNew = await DownloadMessageMedia( @@ -2758,7 +2757,7 @@ public class DownloadService( $"https://onlyfans.com/api2/v2/users/media/{parsed[4]}/drm/message/{parsed[5]}?type=widevine", pssh); - Messages.Medium? mediaInfo = + Medium? mediaInfo = paidMessageCollection.PaidMessageMedia.FirstOrDefault(m => m.id == kvp.Key); Purchased.List? messageInfo = paidMessageCollection.PaidMessageObjects.FirstOrDefault(p => @@ -2776,7 +2775,7 @@ public class DownloadService( } else { - Messages.Medium? mediaInfo = + Medium? mediaInfo = paidMessageCollection.PaidMessageMedia.FirstOrDefault(m => m.id == kvp.Key); Purchased.List? messageInfo = paidMessageCollection.PaidMessageObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); @@ -3033,7 +3032,7 @@ public class DownloadService( $"https://onlyfans.com/api2/v2/users/media/{parsed[4]}/drm/post/{parsed[5]}?type=widevine", pssh); - Messages.Medium? mediaInfo = purchasedPosts.PaidPostMedia.FirstOrDefault(m => m.id == postKVP.Key); + Medium? mediaInfo = purchasedPosts.PaidPostMedia.FirstOrDefault(m => m.id == postKVP.Key); Purchased.List? postInfo = purchasedPosts.PaidPostObjects.FirstOrDefault(p => p?.media?.Contains(mediaInfo) == true); @@ -3049,7 +3048,7 @@ public class DownloadService( } else { - Messages.Medium? mediaInfo = purchasedPosts.PaidPostMedia.FirstOrDefault(m => m.id == postKVP.Key); + 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 5606b5c..ae00a9f 100644 --- a/OF DL/Services/IAPIService.cs +++ b/OF DL/Services/IAPIService.cs @@ -5,7 +5,7 @@ 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 ArchivedModels = OF_DL.Models.Entities.Archived; using Spectre.Console; namespace OF_DL.Services; @@ -28,7 +28,7 @@ public interface IAPIService Task GetPosts(string endpoint, string folder, List paid_post_ids, StatusContext ctx); Task GetPost(string endpoint, string folder); Task GetStreams(string endpoint, string folder, List paid_post_ids, StatusContext ctx); - Task GetArchived(string endpoint, string folder, StatusContext ctx); + Task GetArchived(string endpoint, string folder, StatusContext ctx); Task GetMessages(string endpoint, string folder, StatusContext ctx); Task GetPaidMessages(string endpoint, string folder, string username, StatusContext ctx); Task GetPaidMessage(string endpoint, string folder); diff --git a/OF DL/Services/IDownloadService.cs b/OF DL/Services/IDownloadService.cs index 63916c3..b334e91 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.Entities.Archived; +using ArchivedModels = OF_DL.Models.Entities.Archived; using OF_DL.Models.Messages; using OF_DL.Models.Post; using OF_DL.Models.Purchased; @@ -17,14 +17,14 @@ 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, ListItem? messageInfo, - OF_DL.Models.Entities.Archived.Medium? messageMedia, Models.Entities.Common.Author? author, + IProgressReporter progressReporter, string? filenameFormat, ArchivedModels.ListItem? messageInfo, + ArchivedModels.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, ListItem? postInfo, - OF_DL.Models.Entities.Archived.Medium? postMedia, + IProgressReporter progressReporter, string? filenameFormat, ArchivedModels.ListItem? postInfo, + ArchivedModels.Medium? postMedia, Models.Entities.Common.Author? author, Dictionary users); Task DownloadPostDRMVideo(string policy, string signature, string kvp, string url, string decryptionKey, @@ -41,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, Messages.Medium? messageMedia, Messages.FromUser? fromUser, + string? filenameFormat, List? messageInfo, 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, Messages.Medium? messageMedia, + IProgressReporter progressReporter, string? filenameFormat, List? messageInfo, Medium? messageMedia, Messages.FromUser? fromUser, Dictionary users); Task DownloadPostMedia(string url, string folder, long media_id, string api_type, @@ -58,35 +58,35 @@ public interface IDownloadService Task DownloadPurchasedMedia(string url, string folder, long media_id, string api_type, IProgressReporter progressReporter, string? filenameFormat, Purchased.List? messageInfo, - Messages.Medium? messageMedia, + 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, - Messages.Medium? messageMedia, + 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, - Messages.Medium? messageMedia, + 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, - Messages.Medium? messageMedia, + 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, - Messages.Medium? postMedia, + 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, - Messages.Medium? messageMedia, + Medium? messageMedia, Purchased.FromUser? fromUser, Dictionary users); Task DownloadStoryMedia(string url, string folder, long media_id, string api_type, @@ -104,12 +104,12 @@ 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, - Messages.Medium? messageMedia, + Medium? messageMedia, FromUser? fromUser, Dictionary users); Task DownloadMessagePreviewMedia(string url, string folder, long media_id, string api_type, IProgressReporter progressReporter, string? filenameFormat, SingleMessage? messageInfo, - Messages.Medium? messageMedia, + Medium? messageMedia, FromUser? fromUser, Dictionary users); Task DownloadHighlights(string username, long userId, string path, HashSet paidPostIds, @@ -119,7 +119,7 @@ public interface IDownloadService IProgressReporter progressReporter); Task DownloadArchived(string username, long userId, string path, Dictionary users, - bool clientIdBlobMissing, bool devicePrivateKeyMissing, ArchivedCollection archived, + bool clientIdBlobMissing, bool devicePrivateKeyMissing, ArchivedModels.ArchivedCollection archived, IProgressReporter progressReporter); Task DownloadMessages(string username, long userId, string path, Dictionary users,