Move TA DTOs to specific category folders and add Player field to Video

This commit is contained in:
DarkFighterLuke
2024-09-06 09:48:32 +02:00
parent 8edb8c9202
commit 44d00af16f
4 changed files with 61 additions and 1 deletions
@@ -0,0 +1,51 @@
using System;
using Newtonsoft.Json;
namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist
{
/// <summary>
/// A class representing TubeArchivist API video player data.
/// </summary>
public class Player
{
/// <summary>
/// Initializes a new instance of the <see cref="Player"/> class.
/// </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)
{
Duration = duration;
IsWatched = isWatched;
WatchedUnixTime = watchedUnixTime;
}
/// <summary>
/// Gets the duration of the video.
/// </summary>
[JsonProperty(PropertyName = "duration")]
public long Duration { get; }
/// <summary>
/// Gets a value indicating whether the video is marked as watched.
/// </summary>
[JsonProperty(PropertyName = "watched")]
public bool IsWatched { get; }
/// <summary>
/// Gets the Unix date and time when the video has been marked as watched.
/// </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;
}
}
}
@@ -0,0 +1,54 @@
using Newtonsoft.Json;
namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist
{
/// <summary>
/// A class representing TubeArchivist API video progress data.
/// </summary>
public class Progress
{
/// <summary>
/// Initializes a new instance of the <see cref="Progress"/> class.
/// </summary>
/// <param name="position">Playback progress in seconds.</param>
/// <param name="youtubeId">Video YouTube id.</param>
/// <param name="userId">Playback progress user id.</param>
[JsonConstructor]
public Progress(
long position,
string? youtubeId,
long? userId)
{
YoutubeId = youtubeId;
UserId = userId;
Position = position;
}
/// <summary>
/// Initializes a new instance of the <see cref="Progress"/> class.
/// </summary>
/// <param name="position">Playback progress in seconds.</param>
public Progress(long position)
{
Position = position;
}
/// <summary>
/// Gets or sets the video YouTube id.
/// </summary>
[JsonProperty(PropertyName = "youtube_id")]
public string? YoutubeId { get; set; }
/// <summary>
/// Gets or sets playback progress user id.
/// </summary>
[JsonProperty(PropertyName = "user_id")]
public long? UserId { get; set; }
/// <summary>
/// Gets or sets video playback progress (in seconds).
/// </summary>
[JsonProperty(PropertyName = "position")]
public long Position { get; set; }
}
}
@@ -0,0 +1,151 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using Jellyfin.Plugin.TubeArchivistMetadata.Utilities;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using Newtonsoft.Json;
namespace Jellyfin.Plugin.TubeArchivistMetadata.TubeArchivist
{
/// <summary>
/// A class representing TubeArchivist API video data.
/// </summary>
public class Video
{
/// <summary>
/// Initializes a new instance of the <see cref="Video"/> class.
/// </summary>
/// <param name="channel">Channel the video belongs to.</param>
/// <param name="tags">Video tags.</param>
/// <param name="title">Video title.</param>
/// <param name="description">Video description.</param>
/// <param name="published">Video published date.</param>
/// <param name="vidThumbUrl">Video thuumb image URL.</param>
/// <param name="youtubeId">Video YouTube id.</param>
/// <param name="player">Player info.</param>
public Video(
Channel channel,
Collection<string> tags,
string title,
string description,
DateTime published,
string vidThumbUrl,
string youtubeId,
Player player)
{
this.Channel = channel;
this.Tags = tags;
this.Title = title;
this.Description = description;
this.Published = published;
this.VidThumbUrl = vidThumbUrl;
this.YoutubeId = youtubeId;
Player = player;
}
/// <summary>
/// Gets or sets the channel info.
/// </summary>
[JsonProperty(PropertyName = "channel")]
public Channel Channel { get; set; }
/// <summary>
/// Gets video tags.
/// </summary>
[JsonProperty(PropertyName = "tags")]
[JsonConverter(typeof(TagsJsonConverter))]
public Collection<string> Tags { get; }
/// <summary>
/// Gets or sets video title.
/// </summary>
[JsonProperty(PropertyName = "title")]
public string Title { get; set; }
/// <summary>
/// Gets or sets video description.
/// </summary>
[JsonProperty(PropertyName = "description")]
public string Description { get; set; }
/// <summary>
/// Gets or sets video published date.
/// </summary>
[JsonProperty(PropertyName = "published")]
public DateTime Published { get; set; }
/// <summary>
/// Gets or sets video thumb image URL.
/// </summary>
[JsonProperty(PropertyName = "vid_thumb_url")]
public string VidThumbUrl { get; set; }
/// <summary>
/// Gets or sets video YouTube id.
/// </summary>
[JsonProperty(PropertyName = "youtube_id")]
public string YoutubeId { get; set; }
/// <summary>
/// Getsthe player related info.
/// </summary>
[JsonProperty(PropertyName = "player")]
public Player Player { get; }
/// <summary>
/// Converts the TubeArchivist API video to a Jellyfin <see cref="RemoteSearchResult"/> object.
/// </summary>
/// <returns>The video equivalent Jellyfin <see cref="RemoteSearchResult"/> object.</returns>
public RemoteSearchResult ToSearchResult()
{
return new RemoteSearchResult
{
Name = Title,
SearchProviderName = Constants.ProviderName,
ProductionYear = Published.Year,
ImageUrl = VidThumbUrl,
PremiereDate = Published,
ProviderIds = new Dictionary<string, string>() { { Constants.ProviderName, YoutubeId } }
};
}
/// <summary>
/// Converts the TubeArchivist API video to a Jellyfin <see cref="Episode"/> object.
/// </summary>
/// <returns>The video equivalent Jellyfin <see cref="Episode"/> object.</returns>
public Episode ToEpisode()
{
return new Episode
{
Name = Title,
Overview = Utils.FormatDescription(Description),
SeasonName = Published.Year.ToString(CultureInfo.CurrentCulture),
ParentIndexNumber = Published.Year,
SeriesName = Channel.Name,
ProductionYear = Published.Year,
PremiereDate = Published,
Studios = new[] { Channel.Name },
ProviderIds = new Dictionary<string, string>()
{
{
Constants.ProviderName, YoutubeId
}
},
ImageInfos = new[]
{
new ItemImageInfo
{
Path = VidThumbUrl,
Type = ImageType.Primary
}
},
Tags = this.Tags.ToArray<string>()
};
}
}
}