From 0ee1e22b4f9be33c06ba95122ec62de0541c496b Mon Sep 17 00:00:00 2001 From: Mike Nolan Date: Wed, 15 Jun 2022 07:59:36 -0500 Subject: [PATCH] Fix Client --- Tesses.YouTubeDownloader.Server/Class1.cs | 3 +- Tesses.YouTubeDownloader/TYTDClient.cs | 43 ++++++++++--------- .../Tesses.YouTubeDownloader.csproj | 6 +-- 3 files changed, 27 insertions(+), 25 deletions(-) diff --git a/Tesses.YouTubeDownloader.Server/Class1.cs b/Tesses.YouTubeDownloader.Server/Class1.cs index 77cf3fa..1e6a3ce 100644 --- a/Tesses.YouTubeDownloader.Server/Class1.cs +++ b/Tesses.YouTubeDownloader.Server/Class1.cs @@ -483,7 +483,8 @@ namespace Tesses.YouTubeDownloader.Server } VideoId? id1=VideoId.TryParse(id); if(id1.HasValue) - { + { + await Downloader.AddVideoAsync(id1.Value,resolution); } } diff --git a/Tesses.YouTubeDownloader/TYTDClient.cs b/Tesses.YouTubeDownloader/TYTDClient.cs index 93b66bd..c42b027 100644 --- a/Tesses.YouTubeDownloader/TYTDClient.cs +++ b/Tesses.YouTubeDownloader/TYTDClient.cs @@ -17,32 +17,33 @@ namespace Tesses.YouTubeDownloader { public class TYTDClient : TYTDBase,IDownloader { + string url; public TYTDClient(string url) { client=new HttpClient(); - client.BaseAddress=new Uri(url); + this.url = url.TrimEnd('/') + '/'; } public TYTDClient(HttpClient clt,string url) { client = clt; - client.BaseAddress=new Uri(url); + this.url = url.TrimEnd('/') + '/'; } public TYTDClient(HttpClient clt, Uri uri) { client=clt; - client.BaseAddress=uri; + this.url = url.ToString().TrimEnd('/') + '/'; } public TYTDClient(Uri uri) { client=new HttpClient(); - client.BaseAddress=uri; + this.url = url.ToString().TrimEnd('/') + '/'; } HttpClient client; public async Task AddChannelAsync(ChannelId id, Resolution resolution = Resolution.PreMuxed) { try{ - await client.GetAsync($"/api/v2/AddChannel?v={id.Value}&res={resolution.ToString()}"); + await client.GetAsync($"{url}api/v2/AddChannel?v={id.Value}&res={resolution.ToString()}"); }catch(Exception ex) { _=ex; @@ -52,7 +53,7 @@ namespace Tesses.YouTubeDownloader public async Task AddPlaylistAsync(PlaylistId id, Resolution resolution = Resolution.PreMuxed) { try{ - await client.GetAsync($"/api/v2/AddPlaylist?v={id.Value}&res={resolution.ToString()}"); + await client.GetAsync($"{url}api/v2/AddPlaylist?v={id.Value}&res={resolution.ToString()}"); }catch(Exception ex) { _=ex; @@ -62,7 +63,7 @@ namespace Tesses.YouTubeDownloader public async Task AddUserAsync(UserName userName, Resolution resolution = Resolution.PreMuxed) { try{ - await client.GetAsync($"/api/v2/AddUser?v={userName.Value}&res={resolution.ToString()}"); + await client.GetAsync($"{url}api/v2/AddUser?v={userName.Value}&res={resolution.ToString()}"); }catch(Exception ex) { _=ex; @@ -72,7 +73,7 @@ namespace Tesses.YouTubeDownloader public async Task AddVideoAsync(VideoId id, Resolution resolution = Resolution.PreMuxed) { try{ - await client.GetAsync($"/api/v2/AddVideo?v={id.Value}&res={resolution.ToString()}"); + await client.GetAsync($"{url}api/v2/AddVideo?v={id.Value}&res={resolution.ToString()}"); }catch(Exception ex) { _=ex; @@ -82,7 +83,7 @@ namespace Tesses.YouTubeDownloader public override async Task DirectoryExistsAsync(string path) { try{ - string v=await client.GetStringAsync($"/api/Storage/DirectoryExists/{path}"); + string v=await client.GetStringAsync($"{url}api/Storage/DirectoryExists/{path}"); return v=="true"; }catch(Exception ex) { @@ -95,7 +96,7 @@ namespace Tesses.YouTubeDownloader { List items=null; try{ - string v=await client.GetStringAsync($"/api/Storage/GetDirectory/{path}"); + string v=await client.GetStringAsync($"{url}api/Storage/GetDirectory/{path}"); items=JsonConvert.DeserializeObject>(v); }catch(Exception ex) { @@ -116,7 +117,7 @@ namespace Tesses.YouTubeDownloader { string v="[]"; try{ - v=await client.GetStringAsync("/api/v2/subscriptions"); + v=await client.GetStringAsync("{url}api/v2/subscriptions"); }catch(Exception ex) { _=ex; @@ -131,7 +132,7 @@ namespace Tesses.YouTubeDownloader public async Task UnsubscribeAsync(ChannelId id) { try{ - string v=await client.GetStringAsync($"/api/v2/unsubscribe?id={id.Value}"); + string v=await client.GetStringAsync($"{url}api/v2/unsubscribe?id={id.Value}"); }catch(Exception ex) { @@ -142,7 +143,7 @@ namespace Tesses.YouTubeDownloader { try{ string dlcid=downloadChannelInfo ? "true" : "false"; - string v=await client.GetStringAsync($"/api/v2/subscribe?id={id.Value}&conf={bellInfo.ToString()}&getinfo={dlcid}"); + string v=await client.GetStringAsync($"{url}api/v2/subscribe?id={id.Value}&conf={bellInfo.ToString()}&getinfo={dlcid}"); }catch(Exception ex) { @@ -154,7 +155,7 @@ namespace Tesses.YouTubeDownloader try{ - string v=await client.GetStringAsync($"/api/v2/subscribe?id={ WebUtility.UrlEncode(name.Value)}&conf={info.ToString()}"); + string v=await client.GetStringAsync($"{url}api/v2/subscribe?id={ WebUtility.UrlEncode(name.Value)}&conf={info.ToString()}"); }catch(Exception ex) { @@ -166,7 +167,7 @@ namespace Tesses.YouTubeDownloader try{ - string v=await client.GetStringAsync($"/api/v2/resubscribe?id={id.Value}&conf={info.ToString()}"); + string v=await client.GetStringAsync($"{url}api/v2/resubscribe?id={id.Value}&conf={info.ToString()}"); }catch(Exception ex) { @@ -177,7 +178,7 @@ namespace Tesses.YouTubeDownloader { List items=null; try{ - string v=await client.GetStringAsync($"/api/Storage/GetFiles/{path}"); + string v=await client.GetStringAsync($"{url}api/Storage/GetFiles/{path}"); items=JsonConvert.DeserializeObject>(v); }catch(Exception ex) { @@ -198,7 +199,7 @@ namespace Tesses.YouTubeDownloader public async override Task FileExistsAsync(string path) { try{ - string v=await client.GetStringAsync($"/api/Storage/FileExists/{path}"); + string v=await client.GetStringAsync($"{url}api/Storage/FileExists/{path}"); return v=="true"; }catch(Exception ex) { @@ -210,7 +211,7 @@ namespace Tesses.YouTubeDownloader { try{ - string v=await client.GetStringAsync("/api/v2/QueueList"); + string v=await client.GetStringAsync($"{url}api/v2/QueueList"); return JsonConvert.DeserializeObject>(v); }catch(Exception ex) { @@ -223,7 +224,7 @@ namespace Tesses.YouTubeDownloader { try{ - string v=await client.GetStringAsync("/api/v2/Progress"); + string v=await client.GetStringAsync($"{url}api/v2/Progress"); return JsonConvert.DeserializeObject(v); }catch(Exception ex) { @@ -245,7 +246,7 @@ namespace Tesses.YouTubeDownloader public override async Task GetLengthAsync(string path) { try{ - var item=await client.GetAsync($"/api/Storage/File/{path}"); + var item=await client.GetAsync($"{url}api/Storage/File/{path}"); return item.Content.Headers.ContentLength.GetValueOrDefault(); }catch(Exception ex) { @@ -259,7 +260,7 @@ namespace Tesses.YouTubeDownloader { try{ - Stream v=await client.GetStreamAsync($"/api/Storage/File/{path}"); + Stream v=await client.GetStreamAsync($"{url}api/Storage/File/{path}"); return v; }catch(Exception ex) { diff --git a/Tesses.YouTubeDownloader/Tesses.YouTubeDownloader.csproj b/Tesses.YouTubeDownloader/Tesses.YouTubeDownloader.csproj index ad6540e..1eab5f1 100644 --- a/Tesses.YouTubeDownloader/Tesses.YouTubeDownloader.csproj +++ b/Tesses.YouTubeDownloader/Tesses.YouTubeDownloader.csproj @@ -7,9 +7,9 @@ Tesses.YouTubeDownloader Mike Nolan Tesses - 1.1.1 - 1.1.1 - 1.1.1 + 1.1.2 + 1.1.2 + 1.1.2 A YouTube Downloader LGPL-3.0-only true