diff --git a/Program.cs b/Program.cs index 55094f7..7257428 100644 --- a/Program.cs +++ b/Program.cs @@ -98,6 +98,7 @@ namespace TYTD ApiLoader.Init(); /* Other */ Route.Add("/", (HttpAction)Index); + Route.Add("/", (HttpAction)Extensions); Route.Add("/{Path}", (HttpAction)RootPath); Console.CancelKeyPress += (sender, e) => { ApiLoader.Dispose();var date = DateTime.Now.ToString("yyyyMMdd_HHmmss");File.WriteAllText(Path.Combine("config","queues-close",$"{date}.json"), Downloader.GetQueue()); return; }; @@ -452,6 +453,10 @@ namespace TYTD { rp.AsFile(rq, Path.Combine(webSitePath, "index.html")); } + public static void Extensions(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary args) + { + rp.AsText(ApiLoader.Page); + } public static void RootPath(HttpListenerRequest rq, HttpListenerResponse rp, Dictionary args) { string path = Path.Combine(webSitePath, args["Path"].Split(new char[] { '?' }, StringSplitOptions.RemoveEmptyEntries)[0]); diff --git a/TYTD.Api/MyClass.cs b/TYTD.Api/MyClass.cs index 052ae79..4df5748 100644 --- a/TYTD.Api/MyClass.cs +++ b/TYTD.Api/MyClass.cs @@ -5,15 +5,14 @@ using System.Threading; using System.Collections.Generic; using System.IO; using System.Reflection; +using System.Linq; +using System.Text; +using SimpleHttp; namespace TYTD { public abstract class Api : IDisposable { - public Api() - { - - } public virtual void OnStart() { Console.WriteLine("Extension Loaded"); @@ -21,6 +20,7 @@ namespace TYTD internal string storage; protected string StorageLocation { get { return storage; } } + public virtual string Name { get { return Path.GetFileName(StorageLocation); } } private System.Timers.Timer t = null; protected void SetTimer(TimeSpan timespan) { @@ -37,6 +37,10 @@ namespace TYTD t.Start(); } public bool TimerEnabled { get { if (t != null) { return t.Enabled; } else { return false; } } set { if (t != null) { t.Enabled = value; } } } + public virtual IEnumerable> GetUrls() + { + yield return new KeyValuePair("Home",$"api/Extensions/{Name}"); + } protected virtual void TimerElapsed() { Console.WriteLine("Event Fired"); @@ -84,10 +88,11 @@ namespace TYTD public SavedVideo Video { get; set; } public bool Cancel { get; set; } } - + public static class ApiLoader { - internal static List apis = new List(); + public static string Page { get; private set; } + internal static List apis = new List(); internal static void DownloadStarted(object sender,DownloadStartEventArgs evt) { @@ -110,21 +115,47 @@ namespace TYTD api.Dispose(); } } - + public static void GenerateTr(Api api,StringBuilder b) + { + + string data = ""; + string root = Path.Combine(Environment.CurrentDirectory, "config"); + string fallbackIcon = Path.Combine(root, "default_icon.png"); + string icon = Path.Combine(root, "apiicons", api.Name + ".png"); + string icon2 = File.Exists(icon) ? icon : fallbackIcon; + if (File.Exists(icon2)) + { + + data = Convert.ToBase64String(File.ReadAllBytes(icon2)); + } + + + b.Append($"

{api.Name}

\"{api.Name}\""); + foreach (var link in api.GetUrls()) + { + b.Append($"{link.Key}
"); + } + b.Append(""); + Dictionary templating = new Dictionary(); + templating.Add("Items", b.ToString()); + Page= Templating.RenderFile(Path.Combine("WebSite", "extensions.html"),templating); + } internal static void Load(string dll,string confpath) { var asm=Assembly.LoadFrom(dll); - foreach(var item in asm.GetTypes()) + StringBuilder b = new StringBuilder(); + foreach (var item in asm.GetTypes()) { if(typeof(Api).IsAssignableFrom(item)) { Api api = (Api)Activator.CreateInstance(item); api.storage = confpath; apis.Add(api); - Thread thrd = new Thread(new ThreadStart(api.OnStart)); - thrd.Start(); + api.OnStart(); + GenerateTr(api, b); } } + } public static void Init() { diff --git a/TYTD.Api/TYTD.Api.csproj b/TYTD.Api/TYTD.Api.csproj index 25ae0b5..89d12b1 100644 --- a/TYTD.Api/TYTD.Api.csproj +++ b/TYTD.Api/TYTD.Api.csproj @@ -76,6 +76,34 @@ ..\packages\CookiesTxtParser.1.0.1\lib\netstandard2.0\CookiesTxtParser.dll + + ..\packages\MimeTypesMap.1.0.2\lib\net45\MimeTypesMap.dll + + + ..\packages\System.IO.4.3.0\lib\net462\System.IO.dll + + + ..\packages\System.Runtime.4.3.0\lib\net462\System.Runtime.dll + + + + ..\packages\System.Security.Cryptography.Encoding.4.3.0\lib\net46\System.Security.Cryptography.Encoding.dll + + + ..\packages\System.Security.Cryptography.Primitives.4.3.0\lib\net46\System.Security.Cryptography.Primitives.dll + + + ..\packages\System.Security.Cryptography.Algorithms.4.3.0\lib\net463\System.Security.Cryptography.Algorithms.dll + + + ..\packages\System.Security.Cryptography.X509Certificates.4.3.0\lib\net461\System.Security.Cryptography.X509Certificates.dll + + + ..\packages\System.Net.Http.4.3.3\lib\net46\System.Net.Http.dll + + + ..\packages\Simple-HTTP.1.0.6\lib\net47\SimpleHTTP.dll + diff --git a/TYTD.Api/bin/Release/TYTD.Api.dll b/TYTD.Api/bin/Release/TYTD.Api.dll index d3eba37..d60ddbe 100644 Binary files a/TYTD.Api/bin/Release/TYTD.Api.dll and b/TYTD.Api/bin/Release/TYTD.Api.dll differ diff --git a/TYTD.Api/obj/Release/TYTD.Api.csproj.CoreCompileInputs.cache b/TYTD.Api/obj/Release/TYTD.Api.csproj.CoreCompileInputs.cache index 8c07398..9173b6d 100644 --- a/TYTD.Api/obj/Release/TYTD.Api.csproj.CoreCompileInputs.cache +++ b/TYTD.Api/obj/Release/TYTD.Api.csproj.CoreCompileInputs.cache @@ -1 +1 @@ -3eb6dde99f6eaaac2f2eb82e830940474adc1a21 +43d1539c7b8a6555a9e7a98302a38acdd2e39a06 diff --git a/TYTD.Api/obj/Release/TYTD.Api.csproj.FileListAbsolute.txt b/TYTD.Api/obj/Release/TYTD.Api.csproj.FileListAbsolute.txt index 3c0d7b2..e2a055a 100644 --- a/TYTD.Api/obj/Release/TYTD.Api.csproj.FileListAbsolute.txt +++ b/TYTD.Api/obj/Release/TYTD.Api.csproj.FileListAbsolute.txt @@ -126,3 +126,6 @@ /home/ddlovato/tytd/site/TYTD.Api/obj/Release/TYTD.Api.csproj.CopyComplete /home/ddlovato/tytd/site/TYTD.Api/obj/Release/TYTD.Api.dll /home/ddlovato/tytd/site/TYTD.Api/bin/Release/System.Text.Encoding.CodePages.xml +/home/ddlovato/tytd/site/TYTD.Api/bin/Release/MimeTypesMap.dll +/home/ddlovato/tytd/site/TYTD.Api/bin/Release/SimpleHTTP.dll +/home/ddlovato/tytd/site/TYTD.Api/bin/Release/SimpleHTTP.xml diff --git a/TYTD.Api/obj/Release/TYTD.Api.csprojAssemblyReference.cache b/TYTD.Api/obj/Release/TYTD.Api.csprojAssemblyReference.cache index b379716..fdf4bdf 100644 Binary files a/TYTD.Api/obj/Release/TYTD.Api.csprojAssemblyReference.cache and b/TYTD.Api/obj/Release/TYTD.Api.csprojAssemblyReference.cache differ diff --git a/TYTD.Api/obj/Release/TYTD.Api.dll b/TYTD.Api/obj/Release/TYTD.Api.dll index d3eba37..d60ddbe 100644 Binary files a/TYTD.Api/obj/Release/TYTD.Api.dll and b/TYTD.Api/obj/Release/TYTD.Api.dll differ diff --git a/TYTD.Api/packages.config b/TYTD.Api/packages.config index 4fc1946..44bf833 100644 --- a/TYTD.Api/packages.config +++ b/TYTD.Api/packages.config @@ -4,11 +4,20 @@ + + + + + + + + + diff --git a/bin/Release/TYTD.Api.dll b/bin/Release/TYTD.Api.dll index d3eba37..d60ddbe 100644 Binary files a/bin/Release/TYTD.Api.dll and b/bin/Release/TYTD.Api.dll differ diff --git a/bin/Release/youtube-downloader.exe b/bin/Release/youtube-downloader.exe index cff6a9b..ce62281 100644 Binary files a/bin/Release/youtube-downloader.exe and b/bin/Release/youtube-downloader.exe differ diff --git a/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache b/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache index 8d556b4..021eefa 100644 Binary files a/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache and b/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache differ diff --git a/obj/x86/Release/youtube-downloader.exe b/obj/x86/Release/youtube-downloader.exe index cff6a9b..ce62281 100644 Binary files a/obj/x86/Release/youtube-downloader.exe and b/obj/x86/Release/youtube-downloader.exe differ