Skip to content

Commit

Permalink
Fix #505 - Add support for media type 'Collection' in SearchMultiAsync
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
DineshSolanki committed Jul 30, 2024
1 parent 7a6477f commit fdeaf69
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 8 deletions.
5 changes: 4 additions & 1 deletion TMDbLib/Objects/General/MediaType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public enum MediaType
Season = 6,

[EnumValue("tv_season")]
TvSeason = 7
TvSeason = 7,

[EnumValue("collection")]
Collection = 8
}
}
47 changes: 40 additions & 7 deletions TMDbLib/Objects/Search/SearchCollection.cs
Original file line number Diff line number Diff line change
@@ -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<string, JToken> _additionalData;

Check warning on line 11 in TMDbLib/Objects/Search/SearchCollection.cs

View workflow job for this annotation

GitHub Actions / build

Field 'SearchCollection._additionalData' is never assigned to, and will always have its default value null

Check warning on line 11 in TMDbLib/Objects/Search/SearchCollection.cs

View workflow job for this annotation

GitHub Actions / build

Field 'SearchCollection._additionalData' is never assigned to, and will always have its default value null

Check warning on line 11 in TMDbLib/Objects/Search/SearchCollection.cs

View workflow job for this annotation

GitHub Actions / build

Field 'SearchCollection._additionalData' is never assigned to, and will always have its default value null

Check warning on line 11 in TMDbLib/Objects/Search/SearchCollection.cs

View workflow job for this annotation

GitHub Actions / build

Field 'SearchCollection._additionalData' is never assigned to, and will always have its default value null

[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; }
Expand Down
1 change: 1 addition & 0 deletions TMDbLib/Utilities/Converters/SearchBaseConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
};
}
Expand Down

0 comments on commit fdeaf69

Please sign in to comment.