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
|
|
|
|
|
{
|
2021-06-27 17:22:18 +00:00
|
|
|
|
public class SavedPlaylist
|
2021-06-24 01:10:20 +00:00
|
|
|
|
{
|
2021-06-24 04:05:21 +00:00
|
|
|
|
public static async Task<SavedPlaylist> FromPlaylistId(Resolution res,YoutubeExplode.YoutubeClient ytc,YoutubeExplode.Playlists.PlaylistId id,Action<string,Resolution> addToQueue, Action<int, int, string,string> downloadThumbnail)
|
2021-06-24 01:10:20 +00:00
|
|
|
|
{
|
2021-06-24 07:47:40 +00:00
|
|
|
|
|
2021-06-24 01:10:20 +00:00
|
|
|
|
SavedPlaylist pl2 = new SavedPlaylist();
|
|
|
|
|
pl2.Videos = new List<string>();
|
2021-06-24 07:47:40 +00:00
|
|
|
|
try {
|
2021-06-24 01:10:20 +00:00
|
|
|
|
var pl=await ytc.Playlists.GetAsync(id);
|
|
|
|
|
var a = pl.Author;
|
|
|
|
|
pl2.AuthorChannelId = a.ChannelId;
|
|
|
|
|
pl2.AuthorTitle = a.Title;
|
|
|
|
|
pl2.Id= pl.Id;
|
|
|
|
|
pl2.Description = pl.Description;
|
|
|
|
|
pl2.Title = pl.Title;
|
|
|
|
|
|
|
|
|
|
foreach (var thumb in pl.Thumbnails)
|
|
|
|
|
{
|
|
|
|
|
downloadThumbnail(thumb.Resolution.Width, thumb.Resolution.Height,id, thumb.Url);
|
|
|
|
|
}
|
2021-06-24 07:47:40 +00:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await ytc.Playlists.GetVideosAsync(id).ForEachAsync((v) =>
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
addToQueue(v.Id, res);
|
|
|
|
|
pl2.Videos.Add(v.Id);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}catch(Exception ex)
|
|
|
|
|
{
|
2021-06-26 03:22:31 +00:00
|
|
|
|
Console.WriteLine(ex.Message);
|
|
|
|
|
|
2021-06-24 07:47:40 +00:00
|
|
|
|
_ = ex;
|
|
|
|
|
}
|
|
|
|
|
}catch(Exception ex2)
|
|
|
|
|
{
|
2021-06-26 03:22:31 +00:00
|
|
|
|
Console.WriteLine(ex2.Message);
|
|
|
|
|
|
2021-06-24 07:47:40 +00:00
|
|
|
|
_ = ex2;
|
2021-06-24 01:10:20 +00:00
|
|
|
|
}
|
|
|
|
|
return pl2;
|
|
|
|
|
}
|
|
|
|
|
public List<string> Videos { get; set; }
|
|
|
|
|
public string AuthorTitle { get; set; }
|
|
|
|
|
public string AuthorChannelId { get; set; }
|
|
|
|
|
public string Id { get; set; }
|
|
|
|
|
public string Description { get; set; }
|
|
|
|
|
public string Title { get; set; }
|
|
|
|
|
}
|
|
|
|
|
}
|