diff --git a/OF DL/Models/Dtos/Stories/MediumDto.cs b/OF DL/Models/Dtos/Stories/MediumDto.cs new file mode 100644 index 0000000..6971f50 --- /dev/null +++ b/OF DL/Models/Dtos/Stories/MediumDto.cs @@ -0,0 +1,21 @@ +using Newtonsoft.Json; +using OF_DL.Models.Dtos.Common; + +namespace OF_DL.Models.Dtos.Stories; + +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/Stories/StoryDto.cs b/OF DL/Models/Dtos/Stories/StoryDto.cs new file mode 100644 index 0000000..1a11fa5 --- /dev/null +++ b/OF DL/Models/Dtos/Stories/StoryDto.cs @@ -0,0 +1,24 @@ +using Newtonsoft.Json; + +namespace OF_DL.Models.Dtos.Stories; + +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/Stories/Medium.cs b/OF DL/Models/Entities/Stories/Medium.cs new file mode 100644 index 0000000..20e3f83 --- /dev/null +++ b/OF DL/Models/Entities/Stories/Medium.cs @@ -0,0 +1,16 @@ +using OF_DL.Models.Entities.Common; + +namespace OF_DL.Models.Entities.Stories; + +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; } = new(); +} diff --git a/OF DL/Models/Entities/Stories/Stories.cs b/OF DL/Models/Entities/Stories/Stories.cs new file mode 100644 index 0000000..65d06d5 --- /dev/null +++ b/OF DL/Models/Entities/Stories/Stories.cs @@ -0,0 +1,10 @@ +namespace OF_DL.Models.Entities.Stories; + +public class Stories +{ + public long Id { get; set; } + + public DateTime? CreatedAt { get; set; } + + public List Media { get; set; } = []; +} diff --git a/OF DL/Models/Mappers/StoriesMapper.cs b/OF DL/Models/Mappers/StoriesMapper.cs new file mode 100644 index 0000000..4ccdd03 --- /dev/null +++ b/OF DL/Models/Mappers/StoriesMapper.cs @@ -0,0 +1,32 @@ +using OF_DL.Models.Dtos.Common; +using OF_DL.Models.Dtos.Stories; +using OF_DL.Models.Entities.Common; +using OF_DL.Models.Entities.Stories; + +namespace OF_DL.Models.Mappers; + +public static class StoriesMapper +{ + public static List FromDto(List? dto) => + dto == null ? [] : dto.Select(MapStory).ToList(); + + private static Stories MapStory(StoryDto dto) => + new() { Id = dto.Id, CreatedAt = dto.CreatedAt, Media = MapMedia(dto.Media) }; + + private static List MapMedia(List? media) => + media == null ? [] : 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) => new() { Full = MapFull(dto?.Full) }; + + private static Full MapFull(FullDto? dto) => new() { Url = dto?.Url }; +} diff --git a/OF DL/Models/Stories/Stories.cs b/OF DL/Models/Stories/Stories.cs deleted file mode 100644 index 9aede74..0000000 --- a/OF DL/Models/Stories/Stories.cs +++ /dev/null @@ -1,90 +0,0 @@ -using Newtonsoft.Json; - -namespace OF_DL.Models.Stories; - -public class Stories -{ - 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 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 object _720 { get; set; } - - [JsonProperty("240")] public object _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 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/Services/APIService.cs b/OF DL/Services/APIService.cs index 069929c..93983f5 100644 --- a/OF DL/Services/APIService.cs +++ b/OF DL/Services/APIService.cs @@ -6,21 +6,22 @@ using System.Xml.Linq; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using OF_DL.Models; -using OF_DL.Models.Stories; using OF_DL.Models.Streams; using OF_DL.Enumerations; using ArchivedDtos = OF_DL.Models.Dtos.Archived; -using PostDtos = OF_DL.Models.Dtos.Posts; -using MessageDtos = OF_DL.Models.Dtos.Messages; -using PurchasedDtos = OF_DL.Models.Dtos.Purchased; -using ListDtos = OF_DL.Models.Dtos.Lists; using HighlightDtos = OF_DL.Models.Dtos.Highlights; +using ListDtos = OF_DL.Models.Dtos.Lists; +using MessageDtos = OF_DL.Models.Dtos.Messages; +using PostDtos = OF_DL.Models.Dtos.Posts; +using PurchasedDtos = OF_DL.Models.Dtos.Purchased; +using StoriesDtos = OF_DL.Models.Dtos.Stories; using ArchivedEntities = OF_DL.Models.Entities.Archived; using HighlightEntities = OF_DL.Models.Entities.Highlights; using ListEntities = OF_DL.Models.Entities.Lists; using MessageEntities = OF_DL.Models.Entities.Messages; using PostEntities = OF_DL.Models.Entities.Posts; using PurchasedEntities = OF_DL.Models.Entities.Purchased; +using StoriesEntities = OF_DL.Models.Entities.Stories; using OF_DL.Models.Mappers; using OF_DL.Widevine; using Serilog; @@ -393,60 +394,61 @@ public class APIService(IAuthService authService, IConfigService configService, { Log.Debug("Media Stories - " + endpoint); - List stories = JsonConvert.DeserializeObject>(body, m_JsonSerializerSettings) ?? - new List(); + List? storiesDto = + JsonConvert.DeserializeObject>(body, m_JsonSerializerSettings); + List stories = StoriesMapper.FromDto(storiesDto); - foreach (Stories story in stories) + foreach (StoriesEntities.Stories story in stories) { - if (story.media[0].createdAt.HasValue) + if (story.Media[0].CreatedAt.HasValue) { - await dbService.AddStory(folder, story.id, string.Empty, "0", false, false, - story.media[0].createdAt.Value); + await dbService.AddStory(folder, story.Id, string.Empty, "0", false, false, + story.Media[0].CreatedAt.Value); } - else if (story.createdAt.HasValue) + else if (story.CreatedAt.HasValue) { - await dbService.AddStory(folder, story.id, string.Empty, "0", false, false, - story.createdAt.Value); + await dbService.AddStory(folder, story.Id, string.Empty, "0", false, false, + story.CreatedAt.Value); } else { - await dbService.AddStory(folder, story.id, string.Empty, "0", false, false, DateTime.Now); + await dbService.AddStory(folder, story.Id, string.Empty, "0", false, false, DateTime.Now); } - if (story.media != null && story.media.Count > 0) + if (story.Media != null && story.Media.Count > 0) { - foreach (Stories.Medium medium in story.media) + foreach (StoriesEntities.Medium medium in story.Media) { - await dbService.AddMedia(folder, medium.id, story.id, medium.files.full.url, null, null, + await dbService.AddMedia(folder, medium.Id, story.Id, medium.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) + 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; } - 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) + if (medium.CanView) { - if (!return_urls.ContainsKey(medium.id)) + if (!return_urls.ContainsKey(medium.Id)) { - return_urls.Add(medium.id, medium.files.full.url); + return_urls.Add(medium.Id, medium.Files.Full.Url); } } }