feat(repo): add request plugin with jellyfin catalog manifest
Ship the plugin sources, release zip, and SeerrFin-style manifest.json so Jellyfin can install from the Gitea raw repository URL. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
1 parent
3a1960d860
commit
bf6cd4540f
30 files changed
+3096
No files matched your search
@@ -0,0 +1,190 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Net.Http.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jellyfin.Plugin.Request.Tmdb;
|
||||
|
||||
/// <summary>
|
||||
/// Server-side TMDB API client.
|
||||
/// </summary>
|
||||
public sealed class TmdbClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Named HTTP client for TMDB.
|
||||
/// </summary>
|
||||
public const string HttpClientName = "Tmdb";
|
||||
|
||||
private readonly IHttpClientFactory _httpClientFactory;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="TmdbClient"/> class.
|
||||
/// </summary>
|
||||
/// <param name="httpClientFactory">HTTP client factory.</param>
|
||||
public TmdbClient(IHttpClientFactory httpClientFactory)
|
||||
{
|
||||
_httpClientFactory = httpClientFactory;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Searches TMDB for movies or TV shows.
|
||||
/// </summary>
|
||||
/// <param name="query">Search query.</param>
|
||||
/// <param name="mediaType">movie, tv, or multi.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>Search results.</returns>
|
||||
public async Task<IReadOnlyList<TmdbSearchItem>> SearchAsync(
|
||||
string query,
|
||||
string mediaType,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var apiKey = RequireApiKey();
|
||||
var path = mediaType switch
|
||||
{
|
||||
"movie" => "search/movie",
|
||||
"tv" => "search/tv",
|
||||
_ => "search/multi"
|
||||
};
|
||||
|
||||
var url = $"{path}?api_key={Uri.EscapeDataString(apiKey)}&query={Uri.EscapeDataString(query)}&include_adult=false";
|
||||
var client = _httpClientFactory.CreateClient(HttpClientName);
|
||||
var response = await client.GetFromJsonAsync<TmdbSearchResponse>(url, cancellationToken).ConfigureAwait(false);
|
||||
if (response?.Results is null)
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
return response.Results
|
||||
.Select(result => MapSearchResult(result, mediaType))
|
||||
.Where(item => item is not null)
|
||||
.Cast<TmdbSearchItem>()
|
||||
.Take(40)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads movie or TV details from TMDB.
|
||||
/// </summary>
|
||||
/// <param name="mediaType">movie or tv.</param>
|
||||
/// <param name="tmdbId">TMDB identifier.</param>
|
||||
/// <param name="cancellationToken">Cancellation token.</param>
|
||||
/// <returns>Media detail, or null when not found.</returns>
|
||||
public async Task<TmdbMediaDetail?> GetDetailsAsync(
|
||||
string mediaType,
|
||||
int tmdbId,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var apiKey = RequireApiKey();
|
||||
var client = _httpClientFactory.CreateClient(HttpClientName);
|
||||
|
||||
if (mediaType.Equals("movie", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var movie = await client.GetFromJsonAsync<TmdbMovieDetailResponse>(
|
||||
$"movie/{tmdbId}?api_key={Uri.EscapeDataString(apiKey)}",
|
||||
cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (movie is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new TmdbMediaDetail
|
||||
{
|
||||
TmdbId = movie.Id,
|
||||
MediaType = "movie",
|
||||
Title = movie.Title ?? string.Empty,
|
||||
Overview = movie.Overview,
|
||||
Year = ParseYear(movie.ReleaseDate),
|
||||
PosterPath = movie.PosterPath
|
||||
};
|
||||
}
|
||||
|
||||
if (mediaType.Equals("tv", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
var show = await client.GetFromJsonAsync<TmdbTvDetailResponse>(
|
||||
$"tv/{tmdbId}?api_key={Uri.EscapeDataString(apiKey)}",
|
||||
cancellationToken)
|
||||
.ConfigureAwait(false);
|
||||
if (show is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new TmdbMediaDetail
|
||||
{
|
||||
TmdbId = show.Id,
|
||||
MediaType = "tv",
|
||||
Title = show.Name ?? string.Empty,
|
||||
Overview = show.Overview,
|
||||
Year = ParseYear(show.FirstAirDate),
|
||||
PosterPath = show.PosterPath,
|
||||
Seasons = show.Seasons
|
||||
.Where(season => season.SeasonNumber > 0)
|
||||
.Select(season => new TmdbSeasonInfo
|
||||
{
|
||||
SeasonNumber = season.SeasonNumber,
|
||||
Name = season.Name ?? $"Season {season.SeasonNumber}",
|
||||
EpisodeCount = season.EpisodeCount
|
||||
})
|
||||
.ToList()
|
||||
};
|
||||
}
|
||||
|
||||
throw new ArgumentException("mediaType must be movie or tv.", nameof(mediaType));
|
||||
}
|
||||
|
||||
private static string RequireApiKey()
|
||||
{
|
||||
var apiKey = Plugin.Instance?.Configuration.TmdbApiKey?.Trim() ?? string.Empty;
|
||||
if (string.IsNullOrWhiteSpace(apiKey))
|
||||
{
|
||||
throw new InvalidOperationException("TMDB API key is not configured.");
|
||||
}
|
||||
|
||||
return apiKey;
|
||||
}
|
||||
|
||||
private static TmdbSearchItem? MapSearchResult(TmdbRawResult result, string requestedType)
|
||||
{
|
||||
var type = requestedType is "movie" or "tv"
|
||||
? requestedType
|
||||
: result.MediaType?.ToLowerInvariant();
|
||||
|
||||
if (type is not ("movie" or "tv"))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var title = type == "movie" ? result.Title : result.Name;
|
||||
if (string.IsNullOrWhiteSpace(title))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return new TmdbSearchItem
|
||||
{
|
||||
TmdbId = result.Id,
|
||||
MediaType = type,
|
||||
Title = title,
|
||||
Overview = result.Overview,
|
||||
Year = ParseYear(type == "movie" ? result.ReleaseDate : result.FirstAirDate),
|
||||
PosterPath = result.PosterPath
|
||||
};
|
||||
}
|
||||
|
||||
private static int? ParseYear(string? date)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(date) || date.Length < 4)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return int.TryParse(date.AsSpan(0, 4), NumberStyles.None, CultureInfo.InvariantCulture, out var year)
|
||||
? year
|
||||
: null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,200 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace Jellyfin.Plugin.Request.Tmdb;
|
||||
|
||||
/// <summary>
|
||||
/// Normalized search hit returned to clients.
|
||||
/// </summary>
|
||||
public sealed class TmdbSearchItem
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the TMDB identifier.
|
||||
/// </summary>
|
||||
public int TmdbId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the media type.
|
||||
/// </summary>
|
||||
public string MediaType { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title.
|
||||
/// </summary>
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the overview.
|
||||
/// </summary>
|
||||
public string? Overview { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the year.
|
||||
/// </summary>
|
||||
public int? Year { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the poster path.
|
||||
/// </summary>
|
||||
public string? PosterPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full poster URL when a path is present.
|
||||
/// </summary>
|
||||
public string? PosterUrl => string.IsNullOrEmpty(PosterPath)
|
||||
? null
|
||||
: $"https://image.tmdb.org/t/p/w342{PosterPath}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Normalized media detail returned to clients.
|
||||
/// </summary>
|
||||
public sealed class TmdbMediaDetail
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the TMDB identifier.
|
||||
/// </summary>
|
||||
public int TmdbId { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the media type.
|
||||
/// </summary>
|
||||
public string MediaType { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the title.
|
||||
/// </summary>
|
||||
public string Title { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the overview.
|
||||
/// </summary>
|
||||
public string? Overview { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the year.
|
||||
/// </summary>
|
||||
public int? Year { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the poster path.
|
||||
/// </summary>
|
||||
public string? PosterPath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the full poster URL when a path is present.
|
||||
/// </summary>
|
||||
public string? PosterUrl => string.IsNullOrEmpty(PosterPath)
|
||||
? null
|
||||
: $"https://image.tmdb.org/t/p/w500{PosterPath}";
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets TV seasons when applicable.
|
||||
/// </summary>
|
||||
public List<TmdbSeasonInfo> Seasons { get; set; } = [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Season summary for TV detail views.
|
||||
/// </summary>
|
||||
public sealed class TmdbSeasonInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets or sets the season number.
|
||||
/// </summary>
|
||||
public int SeasonNumber { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the season name.
|
||||
/// </summary>
|
||||
public string Name { get; set; } = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the episode count.
|
||||
/// </summary>
|
||||
public int EpisodeCount { get; set; }
|
||||
}
|
||||
|
||||
internal sealed class TmdbSearchResponse
|
||||
{
|
||||
[JsonPropertyName("results")]
|
||||
public List<TmdbRawResult> Results { get; set; } = [];
|
||||
}
|
||||
|
||||
internal sealed class TmdbRawResult
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonPropertyName("media_type")]
|
||||
public string? MediaType { get; set; }
|
||||
|
||||
[JsonPropertyName("title")]
|
||||
public string? Title { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("overview")]
|
||||
public string? Overview { get; set; }
|
||||
|
||||
[JsonPropertyName("poster_path")]
|
||||
public string? PosterPath { get; set; }
|
||||
|
||||
[JsonPropertyName("release_date")]
|
||||
public string? ReleaseDate { get; set; }
|
||||
|
||||
[JsonPropertyName("first_air_date")]
|
||||
public string? FirstAirDate { get; set; }
|
||||
}
|
||||
|
||||
internal sealed class TmdbMovieDetailResponse
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonPropertyName("title")]
|
||||
public string? Title { get; set; }
|
||||
|
||||
[JsonPropertyName("overview")]
|
||||
public string? Overview { get; set; }
|
||||
|
||||
[JsonPropertyName("poster_path")]
|
||||
public string? PosterPath { get; set; }
|
||||
|
||||
[JsonPropertyName("release_date")]
|
||||
public string? ReleaseDate { get; set; }
|
||||
}
|
||||
|
||||
internal sealed class TmdbTvDetailResponse
|
||||
{
|
||||
[JsonPropertyName("id")]
|
||||
public int Id { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("overview")]
|
||||
public string? Overview { get; set; }
|
||||
|
||||
[JsonPropertyName("poster_path")]
|
||||
public string? PosterPath { get; set; }
|
||||
|
||||
[JsonPropertyName("first_air_date")]
|
||||
public string? FirstAirDate { get; set; }
|
||||
|
||||
[JsonPropertyName("seasons")]
|
||||
public List<TmdbSeasonRaw> Seasons { get; set; } = [];
|
||||
}
|
||||
|
||||
internal sealed class TmdbSeasonRaw
|
||||
{
|
||||
[JsonPropertyName("season_number")]
|
||||
public int SeasonNumber { get; set; }
|
||||
|
||||
[JsonPropertyName("name")]
|
||||
public string? Name { get; set; }
|
||||
|
||||
[JsonPropertyName("episode_count")]
|
||||
public int EpisodeCount { get; set; }
|
||||
}
|
||||
Reference in new issue
Block a user