Adapt to the new TA API changes

This commit is contained in:
DarkFighterLuke
2025-02-21 17:42:58 +01:00
parent 98472b5aa6
commit 16598bb86e
2 changed files with 17 additions and 30 deletions
@@ -65,7 +65,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist
/// <returns>A task.</returns>
public async Task<Channel?> GetChannel(string channelId)
{
ResponseContainer<Channel>? channel = null;
Channel? channel = null;
var channelsEndpoint = "/api/channel/";
var url = new Uri(Utils.SanitizeUrl(Plugin.Instance?.Configuration.TubeArchivistUrl + channelsEndpoint + channelId));
@@ -82,10 +82,10 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist
if (response.IsSuccessStatusCode)
{
string rawData = await response.Content.ReadAsStringAsync().ConfigureAwait(true);
channel = JsonConvert.DeserializeObject<ResponseContainer<Channel>>(rawData);
channel = JsonConvert.DeserializeObject<Channel>(rawData);
}
return channel?.Data;
return channel;
}
/// <summary>
@@ -95,7 +95,7 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist
/// <returns>A task.</returns>
public async Task<Video?> GetVideo(string videoId)
{
ResponseContainer<Video>? video = null;
Video? video = null;
var videosEndpoint = "/api/video/";
var url = new Uri(Utils.SanitizeUrl(Plugin.Instance?.Configuration.TubeArchivistUrl + videosEndpoint + videoId));
@@ -112,10 +112,11 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist
if (response.IsSuccessStatusCode)
{
string rawData = await response.Content.ReadAsStringAsync().ConfigureAwait(true);
video = JsonConvert.DeserializeObject<ResponseContainer<Video>>(rawData);
_logger.LogInformation("{Message}", rawData);
video = JsonConvert.DeserializeObject<Video>(rawData);
}
return video?.Data;
return video;
}
/// <summary>
@@ -174,15 +175,11 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist
{
Progress? progress = null;
var progressEndpoint = $"/api/video/{videoId}/progress/";
var url = new Uri(Utils.SanitizeUrl(Plugin.Instance!.Configuration.TubeArchivistUrl + progressEndpoint));
var response = await client.GetAsync(url).ConfigureAwait(true);
if (response.IsSuccessStatusCode)
var video = await GetVideo(videoId).ConfigureAwait(true);
if (video != null)
{
string rawData = await response.Content.ReadAsStringAsync().ConfigureAwait(true);
progress = JsonConvert.DeserializeObject<Progress>(rawData);
progress = new Progress((long)video.Player.Position);
_logger.LogInformation("{Message}", $"Retrieved progress {video.Player.Position}");
}
return progress;
@@ -1,4 +1,3 @@
using System;
using Newtonsoft.Json;
namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist
@@ -13,12 +12,12 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist
/// </summary>
/// <param name="duration">Duration of the video.</param>
/// <param name="isWatched">Whether the video is marked as watched.</param>
/// <param name="watchedUnixTime">Unix time of when the video has been marked watched.</param>
public Player(long duration, bool isWatched, long watchedUnixTime)
/// <param name="position">Video watched seconds.</param>
public Player(long duration, bool isWatched, double position)
{
Duration = duration;
IsWatched = isWatched;
WatchedUnixTime = watchedUnixTime;
Position = position;
}
/// <summary>
@@ -34,18 +33,9 @@ namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist
public bool IsWatched { get; }
/// <summary>
/// Gets the Unix date and time when the video has been marked as watched.
/// Gets the video watched seconds.
/// </summary>
[JsonProperty(PropertyName = "watched_date")]
public long WatchedUnixTime { get; }
/// <summary>
/// Gets the date and time when the video has been marked as watched.
/// </summary>
[JsonIgnore]
public DateTime WatchedTime
{
get => DateTimeOffset.FromUnixTimeSeconds(WatchedUnixTime).DateTime;
}
[JsonProperty(PropertyName = "position")]
public double Position { get; }
}
}