Skip to content

Commit

Permalink
Merge pull request #507 from DineshSolanki/#505-Add-collection-suppor…
Browse files Browse the repository at this point in the history
…t-to-searchMulti

Co-authored-by: Tim Eisele <Shadowghost@users.noreply.github.com>
  • Loading branch information
crobibero and Shadowghost authored Sep 3, 2024
2 parents c5ccadf + 92a7e91 commit aa9f0b3
Show file tree
Hide file tree
Showing 3 changed files with 44 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
}
}
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

0 comments on commit aa9f0b3

Please sign in to comment.