48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using Google.Apis.YouTube.v3.Data;
|
|
using System;
|
|
using YoutubeExplode;
|
|
|
|
namespace FoxTube.Models
|
|
{
|
|
public class VideoItem
|
|
{
|
|
public Video Meta { get; set; }
|
|
public YoutubeExplode.Videos.Video AdditionalMeta { get; set; }
|
|
public YoutubeExplode.Channels.Channel ChannelMeta { get; set; }
|
|
|
|
public string TimeLabel { get; set; }
|
|
public string ViewsLabel { get; set; }
|
|
public int LiveLabelOpacity => Meta?.LiveStreamingDetails == null ? 0 : 1;
|
|
public string LiveLabel
|
|
{
|
|
get
|
|
{
|
|
if (Meta?.LiveStreamingDetails == null)
|
|
return "";
|
|
else if (Meta.LiveStreamingDetails.ActualStartTime.HasValue)
|
|
return "LIVE";
|
|
else if (Meta.LiveStreamingDetails.ScheduledStartTime.HasValue)
|
|
return $"Live in {Meta.LiveStreamingDetails.ScheduledStartTime - DateTime.Now}";
|
|
else
|
|
return "Upcoming";
|
|
}
|
|
}
|
|
|
|
public VideoItem(Video meta)
|
|
{
|
|
Meta = meta;
|
|
LoadInfo();
|
|
}
|
|
|
|
private async void LoadInfo()
|
|
{
|
|
YoutubeClient client = new YoutubeClient(UserManagement.Service.HttpClient);
|
|
|
|
AdditionalMeta = await client.Videos.GetAsync(Meta.Id);
|
|
ChannelMeta = await client.Channels.GetByVideoAsync(Meta.Id);
|
|
|
|
TimeLabel = $"{AdditionalMeta?.Duration} • {AdditionalMeta.UploadDate.DateTime.GetFriendlyDate()}";
|
|
ViewsLabel = $"{AdditionalMeta?.Engagement.ViewCount} views";
|
|
}
|
|
}
|
|
} |