tytd-server/Server/Models/InfoType.cs

56 lines
1.8 KiB
C#

using YoutubeExplode.Channels;
using YoutubeExplode.Playlists;
using YoutubeExplode.Videos;
namespace youtube_downloader.Server.Models
{
public enum InfoType
{
Video=0,
Playlist=1,
Channel=2,
User=3,
ClosedCaptions=4
}
public class IDResolutionTypeTriplet
{
public string Id { get; set; }
public InfoType Type { get; set; }
public TessesYoutubeDownloader.Server.Models.Resolution Resolution { get; set; }
public InfomationQueueItem ToInfomationQueueItem(bool download=true)
{
switch(Type)
{
case InfoType.Video:
VideoId? vid = VideoId.TryParse(Id);
if (vid.HasValue)
{
return new InfomationQueueItem(vid.Value, Resolution, download);
}
break;
case InfoType.Playlist:
PlaylistId? pid = PlaylistId.TryParse(Id);
if (pid.HasValue)
{
return new InfomationQueueItem(pid.Value, Resolution, download);
}
break;
case InfoType.Channel:
ChannelId? cid = ChannelId.TryParse(Id);
if (cid.HasValue)
{
return new InfomationQueueItem(cid.Value, Resolution, download);
}
break;
case InfoType.User:
UserName? user = UserName.TryParse(Id);
if (user.HasValue)
{
return new InfomationQueueItem(user.Value, Resolution, download);
}
break;
}
return null;
}
}
}