From 6b7e38ddd1b49b4815719b714daa70d0c2310cb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20=C3=81ngy=C3=A1n?= Date: Sun, 19 Mar 2023 13:13:38 +0100 Subject: [PATCH 1/2] extend media type --- TMDbLib/Objects/General/MediaType.cs | 11 +++++++- TMDbLib/Objects/Search/SearchTvSeason.cs | 11 +++++--- .../Converters/SearchBaseConverter.cs | 26 +++++++------------ .../Converters/TaggedImageConverter.cs | 21 +++++---------- TMDbLibTests/Helpers/IdHelper.cs | 1 + .../UtilityTests/TaggedImageConverterTest.cs | 3 +++ 6 files changed, 38 insertions(+), 35 deletions(-) diff --git a/TMDbLib/Objects/General/MediaType.cs b/TMDbLib/Objects/General/MediaType.cs index 17d9056c..b113d3d3 100644 --- a/TMDbLib/Objects/General/MediaType.cs +++ b/TMDbLib/Objects/General/MediaType.cs @@ -19,6 +19,15 @@ public enum MediaType Person = 3, [EnumValue("episode")] - Episode = 4 + Episode = 4, + + [EnumValue("tv_episode")] + TvEpisode = 5, + + [EnumValue("season")] + Season = 6, + + [EnumValue("tv_season")] + TvSeason = 7 } } \ No newline at end of file diff --git a/TMDbLib/Objects/Search/SearchTvSeason.cs b/TMDbLib/Objects/Search/SearchTvSeason.cs index 2a5ee8cf..7cafb02f 100644 --- a/TMDbLib/Objects/Search/SearchTvSeason.cs +++ b/TMDbLib/Objects/Search/SearchTvSeason.cs @@ -1,19 +1,22 @@ using System; using Newtonsoft.Json; +using TMDbLib.Objects.General; namespace TMDbLib.Objects.Search { - public class SearchTvSeason + public class SearchTvSeason : SearchBase { + public SearchTvSeason() + { + MediaType = MediaType.Season; + } + [JsonProperty("air_date")] public DateTime? AirDate { get; set; } [JsonProperty("episode_count")] public int EpisodeCount { get; set; } - [JsonProperty("id")] - public int Id { get; set; } - [JsonProperty("name")] public string Name { get; set; } diff --git a/TMDbLib/Utilities/Converters/SearchBaseConverter.cs b/TMDbLib/Utilities/Converters/SearchBaseConverter.cs index 84d0bd7a..f659e5db 100644 --- a/TMDbLib/Utilities/Converters/SearchBaseConverter.cs +++ b/TMDbLib/Utilities/Converters/SearchBaseConverter.cs @@ -28,23 +28,17 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist // Determine the type based on the media_type MediaType mediaType = jObject["media_type"].ToObject(); - switch (mediaType) + result = mediaType switch { - case MediaType.Movie: - result = new SearchMovie(); - break; - case MediaType.Tv: - result = new SearchTv(); - break; - case MediaType.Person: - result = new SearchPerson(); - break; - case MediaType.Episode: - result = new SearchTvEpisode(); - break; - default: - throw new ArgumentOutOfRangeException(); - } + MediaType.Movie => new SearchMovie(), + MediaType.Tv => new SearchTv(), + MediaType.Person => new SearchPerson(), + MediaType.Episode => new SearchTvEpisode(), + MediaType.TvEpisode => new SearchTvEpisode(), + MediaType.Season => new SearchTvSeason(), + MediaType.TvSeason => new SearchTvSeason(), + _ => throw new ArgumentOutOfRangeException(), + }; } // Populate the result diff --git a/TMDbLib/Utilities/Converters/TaggedImageConverter.cs b/TMDbLib/Utilities/Converters/TaggedImageConverter.cs index d57103bd..c792b8df 100644 --- a/TMDbLib/Utilities/Converters/TaggedImageConverter.cs +++ b/TMDbLib/Utilities/Converters/TaggedImageConverter.cs @@ -24,21 +24,14 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist serializer.Populate(jsonReader, result); JToken mediaJson = jObject["media"]; - switch (result.MediaType) + result.Media = result.MediaType switch { - case MediaType.Movie: - result.Media = mediaJson.ToObject(); - break; - case MediaType.Tv: - result.Media = mediaJson.ToObject(); - break; - case MediaType.Episode: - result.Media = mediaJson.ToObject(); - break; - default: - throw new ArgumentOutOfRangeException(); - } - + MediaType.Movie => mediaJson.ToObject(), + MediaType.Tv => mediaJson.ToObject(), + MediaType.Episode => mediaJson.ToObject(), + MediaType.Season => mediaJson.ToObject(), + _ => throw new ArgumentOutOfRangeException(), + }; return result; } diff --git a/TMDbLibTests/Helpers/IdHelper.cs b/TMDbLibTests/Helpers/IdHelper.cs index b269f3a7..edcb892b 100644 --- a/TMDbLibTests/Helpers/IdHelper.cs +++ b/TMDbLibTests/Helpers/IdHelper.cs @@ -51,6 +51,7 @@ public static class IdHelper public const int TomHanks = 31; public const string ImdbBruceWillis = "nm0000246"; public const int JoshACagan = 129305; + public const int AnnaTorv = 30084; // Collections public const int JamesBondCollection = 645; diff --git a/TMDbLibTests/UtilityTests/TaggedImageConverterTest.cs b/TMDbLibTests/UtilityTests/TaggedImageConverterTest.cs index 9f25c3d7..1fecacd1 100644 --- a/TMDbLibTests/UtilityTests/TaggedImageConverterTest.cs +++ b/TMDbLibTests/UtilityTests/TaggedImageConverterTest.cs @@ -59,6 +59,7 @@ await Verify(new [Theory] [InlineData(IdHelper.HughLaurie)] // Has Movie media [InlineData(IdHelper.TomHanks)] // Has Episode media + [InlineData(IdHelper.AnnaTorv)] // Has Tv, Season media public async Task TestJsonTaggedImageConverter(int personId) { // Get images @@ -77,6 +78,8 @@ public async Task TestJsonTaggedImageConverter(int personId) Assert.IsType(item.Media); else if (item.MediaType == MediaType.Episode) Assert.IsType(item.Media); + else if (item.MediaType == MediaType.Season) + Assert.IsType(item.Media); else Assert.False(true, $"Unexpected type {item.GetType().Name}"); }); From 9fb6275352fa4fda0a85c651400e78ea5633a060 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rk=20=C3=81ngy=C3=A1n?= Date: Sun, 19 Mar 2023 13:39:58 +0100 Subject: [PATCH 2/2] remove spaces --- TMDbLibTests/UtilityTests/TaggedImageConverterTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TMDbLibTests/UtilityTests/TaggedImageConverterTest.cs b/TMDbLibTests/UtilityTests/TaggedImageConverterTest.cs index 1fecacd1..50516389 100644 --- a/TMDbLibTests/UtilityTests/TaggedImageConverterTest.cs +++ b/TMDbLibTests/UtilityTests/TaggedImageConverterTest.cs @@ -57,7 +57,7 @@ await Verify(new /// Tests the TaggedImageConverter /// [Theory] - [InlineData(IdHelper.HughLaurie)] // Has Movie media + [InlineData(IdHelper.HughLaurie)] // Has Movie media [InlineData(IdHelper.TomHanks)] // Has Episode media [InlineData(IdHelper.AnnaTorv)] // Has Tv, Season media public async Task TestJsonTaggedImageConverter(int personId)