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..50516389 100644 --- a/TMDbLibTests/UtilityTests/TaggedImageConverterTest.cs +++ b/TMDbLibTests/UtilityTests/TaggedImageConverterTest.cs @@ -57,8 +57,9 @@ 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) { // 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}"); });