using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Globalization;
using System.Linq;
using Jellyfin.Plugin.TubeArchivistMetadata.Configuration;
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
{
///
/// A class representing TubeArchivist API video data.
///
public class Video
{
///
/// Initializes a new instance of the class.
///
/// Channel the video belongs to.
/// Video tags.
/// Video title.
/// Video description.
/// Video published date.
/// Video thuumb image URL.
/// Video YouTube id.
/// Player info.
public Video(
Channel channel,
Collection 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;
}
///
/// Gets or sets the channel info.
///
[JsonProperty(PropertyName = "channel")]
public Channel Channel { get; set; }
///
/// Gets video tags.
///
[JsonProperty(PropertyName = "tags")]
[JsonConverter(typeof(TagsJsonConverter))]
public Collection Tags { get; }
///
/// Gets or sets video title.
///
[JsonProperty(PropertyName = "title")]
public string Title { get; set; }
///
/// Gets or sets video description.
///
[JsonProperty(PropertyName = "description")]
public string Description { get; set; }
///
/// Gets or sets video published date.
///
[JsonProperty(PropertyName = "published")]
public DateTime Published { get; set; }
///
/// Gets or sets video thumb image URL.
///
[JsonProperty(PropertyName = "vid_thumb_url")]
public string VidThumbUrl { get; set; }
///
/// Gets or sets video YouTube id.
///
[JsonProperty(PropertyName = "youtube_id")]
public string YoutubeId { get; set; }
///
/// Getsthe player related info.
///
[JsonProperty(PropertyName = "player")]
public Player Player { get; }
///
/// Converts the TubeArchivist API video to a Jellyfin object.
///
/// The video equivalent Jellyfin object.
public RemoteSearchResult ToSearchResult()
{
return new RemoteSearchResult
{
Name = Title,
SearchProviderName = Constants.ProviderName,
ProductionYear = Published.Year,
ImageUrl = VidThumbUrl,
PremiereDate = Published,
ProviderIds = new Dictionary() { { Constants.ProviderName, YoutubeId } }
};
}
///
/// Converts the TubeArchivist API video to a Jellyfin object.
///
/// The video equivalent Jellyfin object.
public Episode ToEpisode()
{
return new Episode
{
Name = Title,
Overview = Utils.FormatDescription(Description),
SeasonName = Published.Year.ToString(CultureInfo.CurrentCulture),
ParentIndexNumber = Published.Year,
IndexNumber = Plugin.Instance?.Configuration?.EpisodeNumberingScheme switch
{
NumberingScheme.YYYYMMDD => (Published.Year * 10000) + (Published.Month * 100) + Published.Day,
_ => null
},
SeriesName = Channel.Name,
ProductionYear = Published.Year,
PremiereDate = Published,
Studios = new[] { Channel.Name },
ProviderIds = new Dictionary()
{
{
Constants.ProviderName, YoutubeId
}
},
ImageInfos = new[]
{
new ItemImageInfo
{
Path = VidThumbUrl,
Type = ImageType.Primary
}
},
Tags = this.Tags.ToArray()
};
}
}
}