Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #505 - Add support for media type 'Collection' in SearchMultiAsync #507

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
}
46 changes: 39 additions & 7 deletions TMDbLib/Objects/Search/SearchCollection.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,58 @@
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
Loading