From fdeaf691e8fecf8664ba562165dc9b8dcc1fe224 Mon Sep 17 00:00:00 2001 From: Dinesh Solanki <15937452+DineshSolanki@users.noreply.github.com> Date: Wed, 31 Jul 2024 00:21:27 +0530 Subject: [PATCH 1/2] Fix #505 - Add support for media type 'Collection' in SearchMultiAsync This commit introduces the new media type 'Collection' to the MediaType enum and updates the relevant converters and data models to handle it. The SearchCollection class is enhanced to manage additional data and dynamically retrieve 'title' and 'original_title' fields from JSON if they are not directly set. This ensures better data consistency and expands the functionality to include collections as the returned result from searchMulti for collection has no name or original name property. --- TMDbLib/Objects/General/MediaType.cs | 5 +- TMDbLib/Objects/Search/SearchCollection.cs | 47 ++++++++++++++++--- .../Converters/SearchBaseConverter.cs | 1 + 3 files changed, 45 insertions(+), 8 deletions(-) diff --git a/TMDbLib/Objects/General/MediaType.cs b/TMDbLib/Objects/General/MediaType.cs index b113d3d3..420e5c27 100644 --- a/TMDbLib/Objects/General/MediaType.cs +++ b/TMDbLib/Objects/General/MediaType.cs @@ -28,6 +28,9 @@ public enum MediaType Season = 6, [EnumValue("tv_season")] - TvSeason = 7 + TvSeason = 7, + + [EnumValue("collection")] + Collection = 8 } } \ No newline at end of file diff --git a/TMDbLib/Objects/Search/SearchCollection.cs b/TMDbLib/Objects/Search/SearchCollection.cs index 691f1db6..105134a6 100644 --- a/TMDbLib/Objects/Search/SearchCollection.cs +++ b/TMDbLib/Objects/Search/SearchCollection.cs @@ -1,26 +1,59 @@ +using System.Collections.Generic; using Newtonsoft.Json; +using Newtonsoft.Json.Linq; namespace TMDbLib.Objects.Search { - public class SearchCollection + public class SearchCollection : SearchBase { + // Property to hold additional data from the JSON + [JsonExtensionData] + private IDictionary _additionalData; + [JsonProperty("adult")] public bool Adult { get; set; } [JsonProperty("backdrop_path")] public string BackdropPath { get; set; } - - [JsonProperty("id")] - public int Id { get; set; } + + private string _name; + private string _originalName; [JsonProperty("name")] - public string Name { get; set; } + public string Name + { + get + { + // If _name is not set, attempt to retrieve the "title" property from additional data + if (_name == null && _additionalData != null && _additionalData.TryGetValue("title", out var nameToken)) + { + return nameToken.ToString(); + } + + return _name; + } + set => _name = value; + } [JsonProperty("original_language")] public string OriginalLanguage { get; set; } - + [JsonProperty("original_name")] - public string OriginalName { get; set; } + public string OriginalName + { + get + { + // If _originalName is not set, attempt to retrieve the "original_title" property from additional data + if (_originalName == null && _additionalData != null && + _additionalData.TryGetValue("original_title", out var originalNameToken)) + { + return originalNameToken.ToString(); + } + + return _originalName; + } + set => _originalName = value; + } [JsonProperty("overview")] public string Overview { get; set; } diff --git a/TMDbLib/Utilities/Converters/SearchBaseConverter.cs b/TMDbLib/Utilities/Converters/SearchBaseConverter.cs index f659e5db..1e2f2c5c 100644 --- a/TMDbLib/Utilities/Converters/SearchBaseConverter.cs +++ b/TMDbLib/Utilities/Converters/SearchBaseConverter.cs @@ -37,6 +37,7 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist MediaType.TvEpisode => new SearchTvEpisode(), MediaType.Season => new SearchTvSeason(), MediaType.TvSeason => new SearchTvSeason(), + MediaType.Collection => new SearchCollection(), _ => throw new ArgumentOutOfRangeException(), }; } From 92a7e9182d86daf21fa25e4096f9b9a158ed7b83 Mon Sep 17 00:00:00 2001 From: Dinesh Solanki <15937452+DineshSolanki@users.noreply.github.com> Date: Tue, 3 Sep 2024 23:46:29 +0530 Subject: [PATCH 2/2] Update TMDbLib/Objects/Search/SearchCollection.cs Co-authored-by: Tim Eisele --- TMDbLib/Objects/Search/SearchCollection.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/TMDbLib/Objects/Search/SearchCollection.cs b/TMDbLib/Objects/Search/SearchCollection.cs index 105134a6..8911d45c 100644 --- a/TMDbLib/Objects/Search/SearchCollection.cs +++ b/TMDbLib/Objects/Search/SearchCollection.cs @@ -15,7 +15,6 @@ public class SearchCollection : SearchBase [JsonProperty("backdrop_path")] public string BackdropPath { get; set; } - private string _name; private string _originalName;