using System; using Tesses.YouTubeDownloader.ExtensionLoader; using Tesses.WebServer; using Newtonsoft.Json; using System.Threading.Tasks; namespace Tesses.YouTubeDownloader.ExampleExtension { public class ExampleExtensionClass : Extension { string efn; public bool Enabled {get {return Storage.FileExists(efn);} set{ if(value) { if(!Storage.FileExists(efn)) { Storage.WriteAllTextAsync(efn,"enabled").Wait(); } }else{ if(Storage.FileExists(efn)) { Storage.DeleteFile(efn); } } }} public bool FirstLoad() { string init=this.ExtensionStorage("init"); bool first = !this.Storage.FileExists(init); if(first) { this.Storage.WriteAllTextAsync(init,"loaded").Wait(); } return first; } public override void OnStart() { if(FirstLoad()) { Enabled=true; } this.Storage.BeforeSaveInfo += BeforeSaveInfo; efn=this.ExtensionStorage("enabled"); RouteServer svr=new RouteServer(); svr.Add("/",Index); svr.Add("/setting.cgi",Setting); } public async Task Index(ServerContext ctx) { string enabledStr = Enabled ? " checked" : ""; string index=$" Return YouTube Dislikes Addon for TYTD

Return YouTube Dislikes Addon for TYTD


This extension uses Return YouTube Dislikes"; await ctx.SendTextAsync(index); } public async Task Setting(ServerContext ctx) { Enabled=ctx.QueryParams.ContainsKey("enabled"); await ctx.SendTextAsync( $"

You Will Be Redirected in 5 Sec

\n" ); } public override string Name => "returnyoutubedislike.com"; private async void BeforeSaveInfo(object sender, BeforeSaveInfoEventArgs e) { if(Enabled) e.VideoInfo.Dislikes=JsonConvert.DeserializeObject(await this.Storage.HttpClient.GetStringAsync($"https://returnyoutubedislikeapi.com/votes?videoId={e.VideoInfo.Id}")).dislikes; } } public class Dislike { public long dislikes {get;set;} } }