From 03408687a8c0d973472b0abb996cf7e77a1931fa Mon Sep 17 00:00:00 2001 From: Mike Nolan Date: Thu, 23 Feb 2023 20:59:09 -0600 Subject: [PATCH] Fix some stuff --- Tesses.YouTubeDownloader/SavedVideo.cs | 5 +++-- Tesses.YouTubeDownloader/TYTD.cs | 3 ++- Tesses.YouTubeDownloader/TYTDBase.cs | 15 ++++++--------- Tesses.YouTubeDownloader/TYTDClient.cs | 8 +++++--- 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/Tesses.YouTubeDownloader/SavedVideo.cs b/Tesses.YouTubeDownloader/SavedVideo.cs index ad60f47..b917b63 100644 --- a/Tesses.YouTubeDownloader/SavedVideo.cs +++ b/Tesses.YouTubeDownloader/SavedVideo.cs @@ -310,7 +310,8 @@ namespace Tesses.YouTubeDownloader { foreach(var item in Videos) { - if(await baseCls.FileExistsAsync($"Info/{item}.json")) + VideoId? id = VideoId.TryParse(item); + if(id.HasValue && await baseCls.VideoExistsAsync(id.Value)) { yield return await baseCls.GetVideoInfoAsync(item); } @@ -366,4 +367,4 @@ namespace Tesses.YouTubeDownloader public string Title { get; set; } public string TYTDTag {get;set;} } -} \ No newline at end of file +} diff --git a/Tesses.YouTubeDownloader/TYTD.cs b/Tesses.YouTubeDownloader/TYTD.cs index f422e66..ab9ab65 100644 --- a/Tesses.YouTubeDownloader/TYTD.cs +++ b/Tesses.YouTubeDownloader/TYTD.cs @@ -89,9 +89,10 @@ namespace Tesses.YouTubeDownloader } public async Task WriteAllBytesAsync(string path,byte[] data,CancellationToken token=default(CancellationToken)) { + MemoryStream ms = new MemoryStream(data); using(var s=await CreateAsync(path)) { - await s.WriteAsync(data,0,data.Length,token); + await ms.CopyToAsync(s,4096,token); } } public EventHandler ConsoleWrite; diff --git a/Tesses.YouTubeDownloader/TYTDBase.cs b/Tesses.YouTubeDownloader/TYTDBase.cs index fde6ec2..39b9148 100644 --- a/Tesses.YouTubeDownloader/TYTDBase.cs +++ b/Tesses.YouTubeDownloader/TYTDBase.cs @@ -141,17 +141,14 @@ namespace Tesses.YouTubeDownloader } public async Task ReadAllBytesAsync(string path,CancellationToken token=default(CancellationToken)) - {using(var strm = await OpenReadAsync(path)) + { + MemoryStream memoryStream=new MemoryStream(); + using(var strm = await OpenReadAsync(path)) { - byte[] data=new byte[strm.Length]; - - await strm.ReadAsync(data,0,data.Length,token); - if(token.IsCancellationRequested) - { - return new byte[0]; - } - return data; + await strm.CopyToAsync(memoryStream,4096,token); + } + return memoryStream.ToArray(); } public virtual async IAsyncEnumerable GetPlaylistIdsAsync() diff --git a/Tesses.YouTubeDownloader/TYTDClient.cs b/Tesses.YouTubeDownloader/TYTDClient.cs index 9e8684f..36cdc4e 100644 --- a/Tesses.YouTubeDownloader/TYTDClient.cs +++ b/Tesses.YouTubeDownloader/TYTDClient.cs @@ -482,8 +482,10 @@ internal class SegmentedHttpStream : Stream public async Task ReplacePersonalPlaylistAsync(string name, IEnumerable items) { - DeletePersonalPlaylist(name); - await AddToPersonalPlaylistAsync(name,items); + var content = new MultipartFormDataContent(); + content.Add(new StringContent(name), "name"); + content.Add(new StringContent(JsonConvert.SerializeObject(items.ToList())), "data"); + await client.PostAsync($"{url}api/v2/ReplaceList",content); } public async Task RemoveItemFromPersonalPlaylistAsync(string name, VideoId id) @@ -516,7 +518,7 @@ internal class SegmentedHttpStream : Stream try{ - client.GetStringAsync($"{url}api/v2/DeleteList?name={WebUtility.UrlEncode(name)}").GetAwaiter().GetResult(); + Task.Run(()=>client.GetStringAsync($"{url}api/v2/DeleteList?name={WebUtility.UrlEncode(name)}")).GetAwaiter().GetResult(); }catch(Exception ex) {