diff --git a/Tesses.YouTubeDownloader/BestStreams.cs b/Tesses.YouTubeDownloader/BestStreams.cs index bdb67f2..bc223ec 100644 --- a/Tesses.YouTubeDownloader/BestStreams.cs +++ b/Tesses.YouTubeDownloader/BestStreams.cs @@ -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) diff --git a/Tesses.YouTubeDownloader/TYTD.cs b/Tesses.YouTubeDownloader/TYTD.cs index c6499d8..f422e66 100644 --- a/Tesses.YouTubeDownloader/TYTD.cs +++ b/Tesses.YouTubeDownloader/TYTD.cs @@ -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)); } diff --git a/Tesses.YouTubeDownloader/TYTDClient.cs b/Tesses.YouTubeDownloader/TYTDClient.cs index 7ea2fb7..622b346 100644 --- a/Tesses.YouTubeDownloader/TYTDClient.cs +++ b/Tesses.YouTubeDownloader/TYTDClient.cs @@ -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 GetExtraDataOnceAsync() + { + if(data ==null) + { + string text= await client.GetStringAsync($"{url}api/v2/extra_data.json"); + data = JsonConvert.DeserializeObject(text); + } + return data; + } + public async Task GetExtraDataAsync() + { + string text= await client.GetStringAsync($"{url}api/v2/extra_data.json"); + return JsonConvert.DeserializeObject(text); + } public override ExtraData GetExtraData() { return Task.Run(async()=>{ diff --git a/Tesses.YouTubeDownloader/Tesses.YouTubeDownloader.csproj b/Tesses.YouTubeDownloader/Tesses.YouTubeDownloader.csproj index 5780ea4..4e30f3d 100644 --- a/Tesses.YouTubeDownloader/Tesses.YouTubeDownloader.csproj +++ b/Tesses.YouTubeDownloader/Tesses.YouTubeDownloader.csproj @@ -7,9 +7,9 @@ Tesses.YouTubeDownloader Mike Nolan Tesses - 2.0.2.1 - 2.0.2.1 - 2.0.2.1 + 2.0.2.2 + 2.0.2.2 + 2.0.2.2 A YouTube Downloader GPL-3.0-only true