tytd-server/Server/Models/SavedVideo.cs

70 lines
2.3 KiB
C#
Raw Normal View History

2021-06-24 01:10:20 +00:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2021-06-27 17:22:18 +00:00
using youtube_downloader.Server.Functions;
2021-06-24 01:10:20 +00:00
namespace TessesYoutubeDownloader.Server.Models
{
public enum Resolution
{
Convert=0,
NoConvert=1,
Audio=2
}
public class SavedVideoObject
{
public SavedVideo Video { get; set; }
public Resolution Resolution { get; set; }
}
public class SavedVideo
{
public static SavedVideoObject CreateFrom(Resolution res,YoutubeExplode.Videos.Video v,Action<int,int,string,string> downloadThumbnail)
{
2021-08-03 19:39:03 +00:00
2021-06-24 01:10:20 +00:00
SavedVideo sv = new SavedVideo();
2021-08-03 19:39:03 +00:00
sv.Thumbnails = new List<Tuple<int, int, string>>();
2021-06-24 01:10:20 +00:00
sv.Title = v.Title;
sv.UploadDate = v.UploadDate.ToString();
sv.Id = v.Id;
sv.AuthorChannelId = v.Author.ChannelId;
sv.AuthorTitle = v.Author.Title;
sv.Description = v.Description;
sv.Dislikes = v.Engagement.DislikeCount;
sv.Duration = v.Duration.GetValueOrDefault().TotalSeconds;
sv.Keywords = v.Keywords.ToArray();
sv.Likes = v.Engagement.LikeCount;
sv.Views = v.Engagement.ViewCount;
2021-08-03 19:39:03 +00:00
sv.Thumbnails = v.Thumbnails.Select<YoutubeExplode.Common.Thumbnail,Tuple<int,int,string>>((e) => { return new Tuple<int, int, string>(e.Resolution.Width, e.Resolution.Height, e.Url); }).ToList();
2021-06-24 01:10:20 +00:00
foreach(var thumb in v.Thumbnails)
{
downloadThumbnail(thumb.Resolution.Width, thumb.Resolution.Height,v.Id, thumb.Url);
}
SavedVideoObject obj = new SavedVideoObject();
obj.Video = sv;
obj.Resolution = res;
return obj;
}
public string Title { get; set; }
public string UploadDate { get; set; }
public string[] Keywords { get; set; }
public string Id { get; set; }
public string AuthorTitle { get; set; }
public string AuthorChannelId { get; set; }
public string Description { get; set; }
public double Duration { get; set; }
public long Views { get; set; }
public long Likes { get; set; }
public long Dislikes { get; set; }
2021-08-03 19:39:03 +00:00
public List<Tuple<int,int,string>> Thumbnails { get; set; }
2021-06-24 01:10:20 +00:00
}
}