Archived
1
0
This repository has been archived on 2026-04-22. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
FoxTube/FoxTube.Core/Models/VideoItem.cs
T
2020-05-09 23:16:19 +03:00

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";
}
}
}