Skip to content

Commit

Permalink
refactor: switch original language from enum to string value in APIv3
Browse files Browse the repository at this point in the history
Switched the `OriginalLanguage` property on the TMDB movies and shows from type `TitleLanguage` to it's stringified version for ease of use in clients using APIv3, so we don't have to do the mapping in every client.
  • Loading branch information
revam committed Nov 23, 2024
1 parent c573bb9 commit 5c286d4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 16 deletions.
6 changes: 3 additions & 3 deletions Shoko.Server/API/v3/Models/TMDB/Movie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Newtonsoft.Json.Converters;
using Shoko.Models.Enums;
using Shoko.Plugin.Abstractions.DataModels;
using Shoko.Plugin.Abstractions.Extensions;
using Shoko.Server.API.v3.Helpers;
using Shoko.Server.API.v3.Models.Common;
using Shoko.Server.API.v3.Models.Shoko;
Expand Down Expand Up @@ -59,8 +60,7 @@ public class Movie
/// <summary>
/// Original language the movie was shot in.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public TitleLanguage OriginalLanguage { get; init; }
public string OriginalLanguage { get; init; }

/// <summary>
/// Indicates the movie is restricted to an age group above the legal age,
Expand Down Expand Up @@ -176,7 +176,7 @@ public Movie(TMDB_Movie movie, IncludeDetails? includeDetails = null, IReadOnlyS
if (include.HasFlag(IncludeDetails.Overviews))
Overviews = movie.GetAllOverviews()
.ToDto(movie.EnglishOverview, preferredOverview, language);
OriginalLanguage = movie.OriginalLanguage;
OriginalLanguage = movie.OriginalLanguageCode;
IsRestricted = movie.IsRestricted;
IsVideo = movie.IsVideo;
UserRating = new()
Expand Down
18 changes: 8 additions & 10 deletions Shoko.Server/API/v3/Models/TMDB/Search.cs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ public class RemoteSearchMovie
/// <summary>
/// Original language the movie was shot in.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public TitleLanguage OriginalLanguage { get; init; }
public string OriginalLanguage { get; init; }

/// <summary>
/// Preferred overview based upon description preference.
Expand Down Expand Up @@ -175,7 +174,7 @@ public RemoteSearchMovie(TMDB_Movie movie)
ID = movie.Id;
Title = movie.EnglishTitle;
OriginalTitle = movie.OriginalTitle;
OriginalLanguage = movie.OriginalLanguage;
OriginalLanguage = movie.OriginalLanguageCode;
Overview = movie.EnglishOverview ?? string.Empty;
IsRestricted = movie.IsRestricted;
IsVideo = movie.IsVideo;
Expand All @@ -202,7 +201,7 @@ public RemoteSearchMovie(RemoteMovie movie)
ID = movie.Id;
Title = movie.Title;
OriginalTitle = movie.OriginalTitle;
OriginalLanguage = movie.OriginalLanguage.GetTitleLanguage();
OriginalLanguage = movie.OriginalLanguage;
Overview = movie.Overview ?? string.Empty;
IsRestricted = movie.Adult;
IsVideo = movie.Video;
Expand All @@ -229,7 +228,7 @@ public RemoteSearchMovie(SearchMovie movie)
ID = movie.Id;
Title = movie.Title;
OriginalTitle = movie.OriginalTitle;
OriginalLanguage = movie.OriginalLanguage.GetTitleLanguage();
OriginalLanguage = movie.OriginalLanguage;
Overview = movie.Overview ?? string.Empty;
IsRestricted = movie.Adult;
IsVideo = movie.Video;
Expand Down Expand Up @@ -275,8 +274,7 @@ public class RemoteSearchShow
/// <summary>
/// Original language the show was shot in.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public TitleLanguage OriginalLanguage { get; init; }
public string OriginalLanguage { get; init; }

/// <summary>
/// Preferred overview based upon description preference.
Expand Down Expand Up @@ -313,7 +311,7 @@ public RemoteSearchShow(TMDB_Show show)
ID = show.Id;
Title = show.EnglishTitle;
OriginalTitle = show.OriginalTitle;
OriginalLanguage = show.OriginalLanguage;
OriginalLanguage = show.OriginalLanguageCode;
Overview = show.EnglishOverview ?? string.Empty;
FirstAiredAt = show.FirstAiredAt;
Poster = !string.IsNullOrEmpty(show.PosterPath) && !string.IsNullOrEmpty(TmdbMetadataService.ImageServerUrl)
Expand All @@ -338,7 +336,7 @@ public RemoteSearchShow(RemoteShow show)
ID = show.Id;
Title = show.Name;
OriginalTitle = show.OriginalName;
OriginalLanguage = show.OriginalLanguage.GetTitleLanguage();
OriginalLanguage = show.OriginalLanguage;
Overview = show.Overview ?? string.Empty;
FirstAiredAt = show.FirstAirDate.HasValue ? DateOnly.FromDateTime(show.FirstAirDate.Value) : null;
Poster = !string.IsNullOrEmpty(show.PosterPath) && !string.IsNullOrEmpty(TmdbMetadataService.ImageServerUrl)
Expand All @@ -363,7 +361,7 @@ public RemoteSearchShow(SearchTv show)
ID = show.Id;
Title = show.Name;
OriginalTitle = show.OriginalName;
OriginalLanguage = show.OriginalLanguage.GetTitleLanguage();
OriginalLanguage = show.OriginalLanguage;
Overview = show.Overview ?? string.Empty;
FirstAiredAt = show.FirstAirDate.HasValue ? DateOnly.FromDateTime(show.FirstAirDate.Value) : null;
Poster = !string.IsNullOrEmpty(show.PosterPath) && !string.IsNullOrEmpty(TmdbMetadataService.ImageServerUrl)
Expand Down
6 changes: 3 additions & 3 deletions Shoko.Server/API/v3/Models/TMDB/Show.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Newtonsoft.Json.Converters;
using Shoko.Models.Enums;
using Shoko.Plugin.Abstractions.DataModels;
using Shoko.Plugin.Abstractions.Extensions;
using Shoko.Server.API.v3.Helpers;
using Shoko.Server.API.v3.Models.Common;
using Shoko.Server.Models.CrossReference;
Expand Down Expand Up @@ -54,8 +55,7 @@ public class Show
/// <summary>
/// Original language the show was shot in.
/// </summary>
[JsonConverter(typeof(StringEnumConverter))]
public TitleLanguage OriginalLanguage { get; init; }
public string OriginalLanguage { get; init; }

/// <summary>
/// Indicates the show is restricted to an age group above the legal age,
Expand Down Expand Up @@ -178,7 +178,7 @@ public Show(TMDB_Show show, TMDB_AlternateOrdering? alternateOrdering, IncludeDe
if (include.HasFlag(IncludeDetails.Overviews))
Overviews = show.GetAllOverviews()
.ToDto(show.EnglishTitle, preferredOverview, language);
OriginalLanguage = show.OriginalLanguage;
OriginalLanguage = show.OriginalLanguageCode;
IsRestricted = show.IsRestricted;
UserRating = new()
{
Expand Down

0 comments on commit 5c286d4

Please sign in to comment.