mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2025-12-30 19:29:49 -06:00
FF-1981: TV Show Lookup using cache
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Text.Json;
|
||||
using System.Text.RegularExpressions;
|
||||
using DM.MovieApi;
|
||||
using DM.MovieApi.ApiResponse;
|
||||
using DM.MovieApi.MovieDb.Movies;
|
||||
@@ -78,25 +79,13 @@ public class TVShowLookup : Node
|
||||
args.Logger?.ILog("Lookup TV Show: " + lookupName);
|
||||
|
||||
string tvShowInfoCacheKey = $"TVShowInfo: {lookupName} ({year})";
|
||||
TVShowInfo result = null;
|
||||
var showInfoJson = args.Cache.GetJson(tvShowInfoCacheKey);
|
||||
if(string.IsNullOrWhiteSpace(showInfoJson) == false)
|
||||
TVShowInfo result =args.Cache.GetObject<TVShowInfo>(tvShowInfoCacheKey);
|
||||
if (result != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
result = System.Text.Json.JsonSerializer.Deserialize<TVShowInfo>(showInfoJson);
|
||||
if (result != null)
|
||||
{
|
||||
args.Logger?.ILog("Got TV show info from cache: " + result.Name + "\n" + System.Text.Json.JsonSerializer.Serialize(result));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
args.Logger?.WLog("Failed to deserialize TV SHow Info Json: " + ex.Message + "\n" + showInfoJson);
|
||||
}
|
||||
args.Logger?.ILog("Got TV show info from cache: " + result.Name + "\n" +
|
||||
System.Text.Json.JsonSerializer.Serialize(result));
|
||||
}
|
||||
|
||||
if (result == null)
|
||||
else
|
||||
{
|
||||
result = LookupShow(lookupName, year);
|
||||
|
||||
|
||||
@@ -1,56 +1,123 @@
|
||||
// ReSharper disable UnusedAutoPropertyAccessor.Local
|
||||
|
||||
using System.Runtime.Serialization;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text.Json.Serialization;
|
||||
using DM.MovieApi.MovieDb.Genres;
|
||||
|
||||
namespace DM.MovieApi.MovieDb.TV;
|
||||
|
||||
/// <summary>
|
||||
/// Represents TV show information, including metadata such as name, popularity, and genre details.
|
||||
/// </summary>
|
||||
[DataContract]
|
||||
public class TVShowInfo
|
||||
{
|
||||
[DataMember( Name = "id" )]
|
||||
/// <summary>
|
||||
/// Gets or sets the unique identifier for the TV show.
|
||||
/// </summary>
|
||||
[DataMember(Name = "id")]
|
||||
[JsonPropertyName("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[DataMember( Name = "name" )]
|
||||
/// <summary>
|
||||
/// Gets or sets the name of the TV show.
|
||||
/// </summary>
|
||||
[DataMember(Name = "name")]
|
||||
[JsonPropertyName("name")]
|
||||
public string Name { get; set; }
|
||||
|
||||
[DataMember( Name = "original_name" )]
|
||||
/// <summary>
|
||||
/// Gets or sets the original name of the TV show.
|
||||
/// </summary>
|
||||
[DataMember(Name = "original_name")]
|
||||
[JsonPropertyName("original_name")]
|
||||
public string OriginalName { get; set; }
|
||||
|
||||
[DataMember( Name = "poster_path" )]
|
||||
/// <summary>
|
||||
/// Gets or sets the URL path to the poster image.
|
||||
/// </summary>
|
||||
[DataMember(Name = "poster_path")]
|
||||
[JsonPropertyName("poster_path")]
|
||||
public string PosterPath { get; set; }
|
||||
|
||||
[DataMember( Name = "backdrop_path" )]
|
||||
/// <summary>
|
||||
/// Gets or sets the URL path to the backdrop image.
|
||||
/// </summary>
|
||||
[DataMember(Name = "backdrop_path")]
|
||||
[JsonPropertyName("backdrop_path")]
|
||||
public string BackdropPath { get; set; }
|
||||
|
||||
[DataMember( Name = "popularity" )]
|
||||
/// <summary>
|
||||
/// Gets or sets the popularity score of the TV show.
|
||||
/// </summary>
|
||||
[DataMember(Name = "popularity")]
|
||||
[JsonPropertyName("popularity")]
|
||||
public double Popularity { get; set; }
|
||||
|
||||
[DataMember( Name = "vote_average" )]
|
||||
/// <summary>
|
||||
/// Gets or sets the average vote rating of the TV show.
|
||||
/// </summary>
|
||||
[DataMember(Name = "vote_average")]
|
||||
[JsonPropertyName("vote_average")]
|
||||
public double VoteAverage { get; set; }
|
||||
|
||||
[DataMember( Name = "vote_count" )]
|
||||
/// <summary>
|
||||
/// Gets or sets the total number of votes received.
|
||||
/// </summary>
|
||||
[DataMember(Name = "vote_count")]
|
||||
[JsonPropertyName("vote_count")]
|
||||
public int VoteCount { get; set; }
|
||||
|
||||
[DataMember( Name = "overview" )]
|
||||
/// <summary>
|
||||
/// Gets or sets the overview or summary of the TV show.
|
||||
/// </summary>
|
||||
[DataMember(Name = "overview")]
|
||||
[JsonPropertyName("overview")]
|
||||
public string Overview { get; set; }
|
||||
|
||||
[DataMember( Name = "first_air_date" )]
|
||||
/// <summary>
|
||||
/// Gets or sets the first air date of the TV show.
|
||||
/// </summary>
|
||||
[DataMember(Name = "first_air_date")]
|
||||
[JsonPropertyName("first_air_date")]
|
||||
public DateTime FirstAirDate { get; set; }
|
||||
|
||||
[DataMember( Name = "origin_country" )]
|
||||
/// <summary>
|
||||
/// Gets or sets the origin countries of the TV show.
|
||||
/// </summary>
|
||||
[DataMember(Name = "origin_country")]
|
||||
[JsonPropertyName("origin_country")]
|
||||
public List<string> OriginCountry { get; set; }
|
||||
|
||||
[DataMember(Name = "genre_ids")] public List<int> GenreIds { get; set; } = [];
|
||||
/// <summary>
|
||||
/// Gets or sets the list of genre IDs associated with the TV show.
|
||||
/// </summary>
|
||||
[DataMember(Name = "genre_ids")]
|
||||
[JsonPropertyName("genre_ids")]
|
||||
public List<int> GenreIds { get; set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the list of genres associated with the TV show.
|
||||
/// This property is not serialized to JSON.
|
||||
/// </summary>
|
||||
public List<Genre> Genres { get; internal set; } = [];
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the original language of the TV show.
|
||||
/// </summary>
|
||||
[DataMember(Name = "original_language")]
|
||||
[JsonPropertyName("original_language")]
|
||||
public string OriginalLanguage { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TVShowInfo"/> class.
|
||||
/// </summary>
|
||||
public TVShowInfo()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns a string representation of the TV show.
|
||||
/// </summary>
|
||||
/// <returns>A formatted string containing the name, ID, and first air date.</returns>
|
||||
public override string ToString()
|
||||
=> $"{Name} ({Id} - {FirstAirDate:yyyy-MM-dd})";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user