Added Subscriptions
This commit is contained in:
parent
728ea65613
commit
1cd7375fe5
|
@ -335,7 +335,23 @@ namespace Tesses.YouTubeDownloader.Server
|
|||
Add("/QueueList",QueueList);
|
||||
Add("/subscribe",Subscribe);
|
||||
Add("/resubscribe",Resubscribe);
|
||||
Add("/unsubscribe",Unsubscribe);
|
||||
Add("/subscriptions",Subscriptions);
|
||||
|
||||
}
|
||||
public async Task Subscriptions(ServerContext ctx)
|
||||
{
|
||||
TYTDStorage storage = Downloader as TYTDStorage;
|
||||
if(storage != null)
|
||||
{
|
||||
|
||||
|
||||
var sub=storage.GetLoadedSubscriptions();
|
||||
await ctx.SendJsonAsync(sub);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
public async Task Resubscribe(ServerContext ctx)
|
||||
{
|
||||
|
@ -362,12 +378,7 @@ namespace Tesses.YouTubeDownloader.Server
|
|||
if(cid.HasValue)
|
||||
{
|
||||
|
||||
var sub=storage.GetSubscription(cid.Value);
|
||||
if(sub != null)
|
||||
{
|
||||
sub.BellInfo = conf;
|
||||
await storage.SaveSubscription(sub);
|
||||
}
|
||||
await storage.ResubscribeAsync(cid.Value,conf);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -375,6 +386,33 @@ namespace Tesses.YouTubeDownloader.Server
|
|||
$"<html><head><title>You Will Be Redirected in 5 Sec</title><meta http-equiv=\"Refresh\" content=\"5; url='../../'\" /></head><body><h1>You Will Be Redirected in 5 Sec</h1></body></html>\n"
|
||||
);
|
||||
}
|
||||
|
||||
public async Task Unsubscribe(ServerContext ctx)
|
||||
{
|
||||
TYTDStorage storage = Downloader as TYTDStorage;
|
||||
if(storage != null)
|
||||
{
|
||||
string id;
|
||||
|
||||
if(ctx.QueryParams.TryGetFirst("id",out id))
|
||||
{
|
||||
|
||||
|
||||
|
||||
ChannelId? cid=ChannelId.TryParse(WebUtility.UrlDecode(id));
|
||||
|
||||
if(cid.HasValue)
|
||||
{
|
||||
|
||||
storage.Unsubscribe(cid.Value);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
await ctx.SendTextAsync(
|
||||
$"<html><head><title>You Will Be Redirected in 5 Sec</title><meta http-equiv=\"Refresh\" content=\"5; url='../../'\" /></head><body><h1>You Will Be Redirected in 5 Sec</h1></body></html>\n"
|
||||
);
|
||||
}
|
||||
public async Task Subscribe(ServerContext ctx)
|
||||
{
|
||||
TYTDStorage storage = Downloader as TYTDStorage;
|
||||
|
@ -408,10 +446,10 @@ namespace Tesses.YouTubeDownloader.Server
|
|||
if(cid.HasValue)
|
||||
{
|
||||
|
||||
await storage.Subscribe(cid.Value,getinfo,conf);
|
||||
await storage.SubscribeAsync(cid.Value,getinfo,conf);
|
||||
}else{
|
||||
UserName? uname=UserName.TryParse(WebUtility.UrlDecode(id));
|
||||
await storage.Subscribe(uname.Value,conf);
|
||||
await storage.SubscribeAsync(uname.Value,conf);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,9 +15,9 @@
|
|||
<PackageId>Tesses.YouTubeDownloader.Server</PackageId>
|
||||
<Author>Mike Nolan</Author>
|
||||
<Company>Tesses</Company>
|
||||
<Version>1.0.2.0</Version>
|
||||
<AssemblyVersion>1.0.2.0</AssemblyVersion>
|
||||
<FileVersion>1.0.2.0</FileVersion>
|
||||
<Version>1.0.2.1</Version>
|
||||
<AssemblyVersion>1.0.2.1</AssemblyVersion>
|
||||
<FileVersion>1.0.2.1</FileVersion>
|
||||
<Description>Adds WebServer to TYTD</Description>
|
||||
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
|
|
|
@ -20,5 +20,10 @@ namespace Tesses.YouTubeDownloader
|
|||
|
||||
IReadOnlyList<(SavedVideo Video,Resolution Resolution)> GetQueueList();
|
||||
SavedVideoProgress GetProgress();
|
||||
IAsyncEnumerable<Subscription> GetSubscriptionsAsync();
|
||||
Task UnsubscribeAsync(ChannelId id);
|
||||
Task SubscribeAsync(ChannelId id,bool downloadChannelInfo=false,ChannelBellInfo bellInfo = ChannelBellInfo.NotifyAndDownload);
|
||||
Task SubscribeAsync(UserName name,ChannelBellInfo info=ChannelBellInfo.NotifyAndDownload);
|
||||
Task ResubscribeAsync(ChannelId id,ChannelBellInfo info=ChannelBellInfo.NotifyAndDownload);
|
||||
}
|
||||
}
|
|
@ -66,7 +66,22 @@ namespace Tesses.YouTubeDownloader
|
|||
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async Task UnsubscribeAsync(ChannelId id)
|
||||
{
|
||||
await Task.Run(()=>{Unsubscribe(id);});
|
||||
}
|
||||
|
||||
public async Task ResubscribeAsync(ChannelId id,ChannelBellInfo info=ChannelBellInfo.NotifyAndDownload)
|
||||
{
|
||||
var sub=GetSubscription(id);
|
||||
if(sub != null)
|
||||
{
|
||||
sub.BellInfo = info;
|
||||
await SaveSubscription(sub);
|
||||
}
|
||||
}
|
||||
|
||||
public DateTime LastSubscriptionTime = DateTime.MinValue;
|
||||
public async Task HandleSubscriptions()
|
||||
{
|
||||
|
@ -99,7 +114,7 @@ namespace Tesses.YouTubeDownloader
|
|||
/// <summary>
|
||||
/// Subscribe to creator
|
||||
/// </summary>
|
||||
public async Task Subscribe(ChannelId id, bool downloadChannelInfo=false,ChannelBellInfo bellInfo = ChannelBellInfo.NotifyAndDownload)
|
||||
public async Task SubscribeAsync(ChannelId id, bool downloadChannelInfo=false,ChannelBellInfo bellInfo = ChannelBellInfo.NotifyAndDownload)
|
||||
{
|
||||
if(downloadChannelInfo)
|
||||
{
|
||||
|
@ -117,11 +132,15 @@ namespace Tesses.YouTubeDownloader
|
|||
{
|
||||
await WriteAllTextAsync($"Subscriptions/{sub.Id}",JsonConvert.SerializeObject(sub));
|
||||
}
|
||||
public async Task Subscribe(UserName name,ChannelBellInfo bellInfo=ChannelBellInfo.NotifyAndDownload)
|
||||
public async Task SubscribeAsync(UserName name,ChannelBellInfo bellInfo=ChannelBellInfo.NotifyAndDownload)
|
||||
{
|
||||
ChannelMediaContext context=new ChannelMediaContext(name,Resolution.NoDownload);
|
||||
var c=await context.GetChannel(this);
|
||||
await Subscribe(ChannelId.Parse(c.Id),false,bellInfo);
|
||||
await SubscribeAsync(ChannelId.Parse(c.Id),false,bellInfo);
|
||||
}
|
||||
public IReadOnlyList<Subscription> GetLoadedSubscriptions()
|
||||
{
|
||||
return Subscriptions;
|
||||
}
|
||||
public void Unsubscribe(ChannelId id)
|
||||
{
|
||||
|
|
|
@ -11,6 +11,7 @@ using System.IO;
|
|||
using YoutubeExplode.Channels;
|
||||
using YoutubeExplode.Playlists;
|
||||
using System.Net.Http;
|
||||
using System.Net;
|
||||
|
||||
namespace Tesses.YouTubeDownloader
|
||||
{
|
||||
|
@ -111,7 +112,67 @@ namespace Tesses.YouTubeDownloader
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
public async IAsyncEnumerable<Subscription> GetSubscriptionsAsync()
|
||||
{
|
||||
string v="[]";
|
||||
try{
|
||||
v=await client.GetStringAsync("/api/v2/subscriptions");
|
||||
}catch(Exception ex)
|
||||
{
|
||||
_=ex;
|
||||
}
|
||||
foreach(var item in JsonConvert.DeserializeObject<List<Subscription>>(v))
|
||||
{
|
||||
yield return await Task.FromResult(item);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public async Task UnsubscribeAsync(ChannelId id)
|
||||
{
|
||||
try{
|
||||
string v=await client.GetStringAsync($"/api/v2/unsubscribe?id={id.Value}");
|
||||
|
||||
}catch(Exception ex)
|
||||
{
|
||||
_=ex;
|
||||
}
|
||||
}
|
||||
public async Task SubscribeAsync(ChannelId id,bool downloadChannelInfo=false,ChannelBellInfo bellInfo = ChannelBellInfo.NotifyAndDownload)
|
||||
{
|
||||
try{
|
||||
string dlcid=downloadChannelInfo ? "true" : "false";
|
||||
string v=await client.GetStringAsync($"/api/v2/subscribe?id={id.Value}&conf={bellInfo.ToString()}&getinfo={dlcid}");
|
||||
|
||||
}catch(Exception ex)
|
||||
{
|
||||
_=ex;
|
||||
}
|
||||
}
|
||||
public async Task SubscribeAsync(UserName name,ChannelBellInfo info=ChannelBellInfo.NotifyAndDownload)
|
||||
{
|
||||
try{
|
||||
|
||||
|
||||
string v=await client.GetStringAsync($"/api/v2/subscribe?id={ WebUtility.UrlEncode(name.Value)}&conf={info.ToString()}");
|
||||
|
||||
}catch(Exception ex)
|
||||
{
|
||||
_=ex;
|
||||
}
|
||||
}
|
||||
public async Task ResubscribeAsync(ChannelId id,ChannelBellInfo info=ChannelBellInfo.NotifyAndDownload)
|
||||
{
|
||||
try{
|
||||
|
||||
|
||||
string v=await client.GetStringAsync($"/api/v2/resubscribe?id={id.Value}&conf={info.ToString()}");
|
||||
|
||||
}catch(Exception ex)
|
||||
{
|
||||
_=ex;
|
||||
}
|
||||
}
|
||||
public async override IAsyncEnumerable<string> EnumerateFilesAsync(string path)
|
||||
{
|
||||
List<string> items=null;
|
||||
|
@ -208,6 +269,6 @@ namespace Tesses.YouTubeDownloader
|
|||
return Stream.Null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
|
@ -7,9 +7,9 @@
|
|||
<PackageId>Tesses.YouTubeDownloader</PackageId>
|
||||
<Author>Mike Nolan</Author>
|
||||
<Company>Tesses</Company>
|
||||
<Version>1.0.3.0</Version>
|
||||
<AssemblyVersion>1.0.3.0</AssemblyVersion>
|
||||
<FileVersion>1.0.3.0</FileVersion>
|
||||
<Version>1.0.3.1</Version>
|
||||
<AssemblyVersion>1.0.3.1</AssemblyVersion>
|
||||
<FileVersion>1.0.3.1</FileVersion>
|
||||
<Description>A YouTube Downloader</Description>
|
||||
<PackageLicenseExpression>LGPL-3.0-only</PackageLicenseExpression>
|
||||
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>
|
||||
|
|
Loading…
Reference in New Issue