Fix TYTDClient for blazor

This commit is contained in:
Mike Nolan 2023-02-16 11:43:41 -06:00
parent 26c9960003
commit e1046c33b5
4 changed files with 35 additions and 10 deletions

View File

@ -64,7 +64,7 @@ namespace Tesses.YouTubeDownloader
//Console.WriteLine("IN FUNC");
//Console.WriteLine("DIR");
if(storage.BestStreamInfoExists(id))
if(await storage.BestStreamInfoExistsAsync(id))
{
//Console.WriteLine("STREAMS");
BestStreamsSerialized serialization=await storage.GetBestStreamInfoAsync(id);
@ -83,7 +83,7 @@ namespace Tesses.YouTubeDownloader
{
if(storage.BestStreamInfoExists(id))
if(await storage.BestStreamInfoExistsAsync(id))
{
BestStreamsSerialized serialization=await storage.GetBestStreamInfoAsync(id);
if(DateTime.Now < serialization.Expires || !expire_check)
@ -99,7 +99,7 @@ namespace Tesses.YouTubeDownloader
DateTime expires=DateTime.Now.AddHours(6);
try{
if(storage.VideoInfoExists(id))
if(await storage.VideoInfoExistsAsync(id))
{
var video = await storage.GetVideoInfoAsync(id);
if(video.VideoFrozen)

View File

@ -128,7 +128,7 @@ namespace Tesses.YouTubeDownloader
{
string file = info.DownloadFrom.StartsWith("NormalDownload,Length=") ? $"DownloadsInfo/{HashDownloadUrl(info.Id)}.json" : $"Info/{info.Id}.json";
if(!FileExists(file))
if(!await FileExistsAsync(file))
{
await WriteAllTextAsync(file,JsonConvert.SerializeObject(info));
}
@ -144,7 +144,7 @@ namespace Tesses.YouTubeDownloader
public virtual async Task WriteChannelInfoAsync(SavedChannel info)
{
string file = $"Channel/{info.Id}.json";
if(!FileExists(file))
if(!await FileExistsAsync(file))
{
await WriteAllTextAsync(file,JsonConvert.SerializeObject(info));
}

View File

@ -552,11 +552,13 @@ internal class SegmentedHttpStream : Stream
_error.Invoke(this,new TYTDErrorEventArgs("jNQXAC9IVRw",ex));
}
}
public IBlazorContext BlazorContext {get;set;} = null;
public void ResetEvents()
{
if(src != null) {
src.Cancel();
src.Dispose();
}
if(hadBeenListeningToEvents)
@ -711,8 +713,17 @@ internal class SegmentedHttpStream : Stream
}
private void _startEventStream()
{
Task.Run(_startEventStreamAsync).Wait(0);
if(BlazorContext != null)
{
BlazorContext.StartEvents((evt)=>{
sse_Event(this,new SSEEvent(evt));
});
src=new CancellationTokenSource();
hadBeenListeningToEvents=true;
src.Token.Register(BlazorContext.StopEvents);
}else{
Task.Run(_startEventStreamAsync).Wait(0);
}
}
public ExtraData GetExtraDataOnce()
{
@ -724,6 +735,20 @@ internal class SegmentedHttpStream : Stream
}
return data;
}
public async Task<ExtraData> GetExtraDataOnceAsync()
{
if(data ==null)
{
string text= await client.GetStringAsync($"{url}api/v2/extra_data.json");
data = JsonConvert.DeserializeObject<ExtraData>(text);
}
return data;
}
public async Task<ExtraData> GetExtraDataAsync()
{
string text= await client.GetStringAsync($"{url}api/v2/extra_data.json");
return JsonConvert.DeserializeObject<ExtraData>(text);
}
public override ExtraData GetExtraData()
{
return Task.Run<ExtraData>(async()=>{

View File

@ -7,9 +7,9 @@
<PackageId>Tesses.YouTubeDownloader</PackageId>
<Author>Mike Nolan</Author>
<Company>Tesses</Company>
<Version>2.0.2.1</Version>
<AssemblyVersion>2.0.2.1</AssemblyVersion>
<FileVersion>2.0.2.1</FileVersion>
<Version>2.0.2.2</Version>
<AssemblyVersion>2.0.2.2</AssemblyVersion>
<FileVersion>2.0.2.2</FileVersion>
<Description>A YouTube Downloader</Description>
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>