Fix downloader bug, use plink and add icon to plugin template

This commit is contained in:
2025-12-28 15:23:12 -06:00
parent d3d04bb971
commit 5106c5dc6b
9 changed files with 35 additions and 18 deletions

View File

@@ -24,7 +24,6 @@ func Components.AddVideo(id)
<button name="action" value="add"><i>add</i></button> <button name="action" value="add"><i>add</i></button>
<button name="action" value="download"><i>download</i></button> <button name="action" value="download"><i>download</i></button>
<button name="action" value="play"><i>play_arrow</i></button>
</div> </div>
</form>; </form>;
} }

View File

@@ -27,7 +27,6 @@ func Components.Add()
<button name="action" value="add"><i>add</i></button> <button name="action" value="add"><i>add</i></button>
<button name="action" value="info"><i>info</i></button> <button name="action" value="info"><i>info</i></button>
<button name="action" value="download"><i>download</i></button> <button name="action" value="download"><i>download</i></button>
<button name="action" value="play"><i>play_arrow</i></button>
</div> </div>
</form>; </form>;
} }

View File

@@ -11,7 +11,7 @@ func Components.DiscoverEntry(item)
<div class="max"> <div class="max">
<div class="col"> <div class="col">
<div class="min"> <div class="min">
<a target="_blank" href={$"./video?v={Net.Http.UrlEncode(item.id)}"}>{item.title}</a> <a target="_blank" href={$"./watch?v={Net.Http.UrlEncode(item.id)}"}>{item.title}</a>
</div> </div>
<div class="min"> <div class="min">
<span>{item.views} • {item.uploaded}</span> <span>{item.views} • {item.uploaded}</span>

View File

@@ -8,7 +8,7 @@ func Components.DownloadedVideo(item)
<div class="max"> <div class="max">
<div class="col"> <div class="col">
<div class="min"> <div class="min">
<a hx-get={$"./video?v={Net.Http.UrlEncode(item.videoId)}"} hx-target="body" hx-push-url="true" href={$"./video?v={Net.Http.UrlEncode(item.videoId)}"}>{item.title}</a> <a hx-get={$"./watch?v={Net.Http.UrlEncode(item.videoId)}"} hx-target="body" hx-push-url="true" href={$"./watch?v={Net.Http.UrlEncode(item.videoId)}"}>{item.title}</a>
</div> </div>
<div class="min"> <div class="min">
<span>{item.viewCountStr} (when downloaded)</span> <span>{item.viewCountStr} (when downloaded)</span>
@@ -34,7 +34,7 @@ func Components.DownloadedPlaylist(item)
<div class="max"> <div class="max">
<div class="col"> <div class="col">
<div class="min"> <div class="min">
<a hx-get={$"./playlist?id={Net.Http.UrlEncode(item.playlistId)}"} href={$"./playlist?id={Net.Http.UrlEncode(item.playlistId)}"} hx-target="body" hx-push-url="true">{item.title}</a> <a hx-get={$"./playlist?list={Net.Http.UrlEncode(item.playlistId)}"} href={$"./playlist?list={Net.Http.UrlEncode(item.playlistId)}"} hx-target="body" hx-push-url="true">{item.title}</a>
</div> </div>
<div class="min"> <div class="min">
<a hx-get={$"./channel?id={Net.Http.UrlEncode(item.channelId)}"} href={$"./channel?id={Net.Http.UrlEncode(item.channelId)}"} hx-target="body" hx-push-url="true">{item.channelTitle}</a> <a hx-get={$"./channel?id={Net.Http.UrlEncode(item.channelId)}"} href={$"./channel?id={Net.Http.UrlEncode(item.channelId)}"} hx-target="body" hx-push-url="true">{item.channelTitle}</a>

View File

@@ -4,9 +4,9 @@ func Components.Progress(tytd)
var vid = tytd.CurrentVideo; var vid = tytd.CurrentVideo;
var html = <div hx-trigger="every 1500ms" hx-indicator="none" hx-get="./progress" hx-swap="outerHTML"> var html = <div hx-trigger="every 1500ms" hx-indicator="none" hx-get="./progress" hx-swap="outerHTML">
<h2>{vid.Title}</h2> <h2><a hx-target="body" hx-push-url="true" hx-get={$"./watch?v={Net.Http.UrlEncode(vid.VideoId)}"} href={$"./watch?v={Net.Http.UrlEncode(vid.VideoId)}"}>{vid.Title}</a></h2>
<h4>{vid.Channel}</h4> <h4><a hx-target="body" hx-push-url="true" hx-get={$"./channel?id={Net.Http.UrlEncode(vid.ChannelId)}"} href={$"./channel?id={Net.Http.UrlEncode(vid.ChannelId)}"}>{vid.Channel}</a></h4>
<progress value={tytd.CurrentVideoProgress * 100.0} max="100" min="0"></progress> <progress class="wavy light-green-text" value={tytd.CurrentVideoProgress * 100.0} max="100" min="0"></progress>
</div>; </div>;
progress++; progress++;
return html; return html;

View File

@@ -9,7 +9,9 @@ var TYTDResources = [
{path="/favicon.ico",value=embed("favicon.ico")}, {path="/favicon.ico",value=embed("favicon.ico")},
{path="/tytd.svg",value=embed("tytd.svg")}, {path="/tytd.svg",value=embed("tytd.svg")},
{path="/loading-indicator.svg",value=embed("loading-indicator.svg")}, {path="/loading-indicator.svg",value=embed("loading-indicator.svg")},
{path="/theme.css",value=embed("theme.css")} {path="/theme.css",value=embed("theme.css")},
{path="/video.min.js",value=embed("video.min.js")},
{path="/video-js.css",value=embed("video-js.css")},
]; ];
var times=1; var times=1;
@@ -41,6 +43,20 @@ class TYTDApp {
ctx.WithMimeType("text/html").SendText(Pages.ApiV1()); ctx.WithMimeType("text/html").SendText(Pages.ApiV1());
return true; return true;
} }
else if(ctx.Path == "/embed")
{
var v = ctx.QueryParams.TryGetFirst("v");
if(TypeIsString(v))
{
const video = this.TYTD.GetVideo(id);
if(TypeIsDefined(video))
{
ctx.WithMimeType("text/html").SendText(Pages.VideoEmbed(v, video.title));
return true;
}
}
return false;
}
else if(ctx.Path == "/api/v1/download") else if(ctx.Path == "/api/v1/download")
{ {
var v = ctx.QueryParams.TryGetFirst("v"); var v = ctx.QueryParams.TryGetFirst("v");
@@ -51,14 +67,16 @@ class TYTDApp {
var path = this.TYTD.GetVideoPath(v,res); var path = this.TYTD.GetVideoPath(v,res);
if(path != null) if(path != null && this.TYTD.Storage.FileExists(path))
{ {
var info = this.TYTD.GetVideo(v); var info = this.TYTD.GetVideo(v);
var filename = $"{info.title}-{info.videoId}-{res}{path.GetExtension()}"; var filename = $"{info.title}-{info.videoId}-{res}{path.GetExtension()}";
var strm = this.TYTD.Storage.OpenFile(path,"rb"); var strm = this.TYTD.Storage.OpenFile(path,"rb");
ctx.WithMimeType(Net.Http.MimeType(path.ToString())).WithContentDisposition(filename,inline).SendStream(strm); ctx.WithMimeType(Net.Http.MimeType(path.ToString())).WithContentDisposition(filename,inline).SendStream(strm);
strm.Close(); strm.Close();
return true;
} }
return false;
} }
else if(ctx.Path == "/api/v1/progress.json") else if(ctx.Path == "/api/v1/progress.json")
{ {
@@ -308,7 +326,7 @@ class TYTDApp {
ctx.WithMimeType("text/html").SendText(Pages.Settings(this.TYTD,ctx)); ctx.WithMimeType("text/html").SendText(Pages.Settings(this.TYTD,ctx));
return true; return true;
} }
else if(ctx.Path == "/video") else if(ctx.Path == "/watch" || ctx.Path == "/video")
{ {
ctx.WithMimeType("text/html").SendText(Pages.VideoInfo(this.TYTD,ctx)); ctx.WithMimeType("text/html").SendText(Pages.VideoInfo(this.TYTD,ctx));
return true; return true;

View File

@@ -1,6 +1,6 @@
func Pages.PlaylistInfo(tytd,ctx) func Pages.PlaylistInfo(tytd,ctx)
{ {
var id = ctx.QueryParams.TryGetFirst("id"); var id = ctx.QueryParams.TryGetFirst("list") ?? ctx.QueryParams.TryGetFirst("id");
var page = ctx.QueryParams.TryGetFirstInt("page"); var page = ctx.QueryParams.TryGetFirstInt("page");
if(TypeOf(page) != "Long") page = 1; if(TypeOf(page) != "Long") page = 1;
page--; page--;
@@ -27,7 +27,7 @@ func Pages.PlaylistInfo(tytd,ctx)
</each> </each>
<footer class="row center-align"> <footer class="row center-align">
<button hx-get={$"./playlist?id={Net.Http.UrlEncode(id)}&page={page}"} hx-target="body" hx-push-url="true" >Prev</button>{page+1}<button hx-get={$"./playlist?id={Net.Http.UrlEncode(id)}&type=videos&page={page+2}"} hx-target="body" hx-push-url="true" >Next</button> <button hx-get={$"./playlist?list={Net.Http.UrlEncode(id)}&page={page}"} hx-target="body" hx-push-url="true" >Prev</button>{page+1}<button hx-get={$"./playlist?list={Net.Http.UrlEncode(id)}&type=videos&page={page+2}"} hx-target="body" hx-push-url="true" >Next</button>
</footer> </footer>
</null>; </null>;

View File

@@ -9,10 +9,11 @@ func Pages.VideoInfo(tytd,ctx)
{ {
html = <div class="col"> html = <div class="col">
<div class="min"> <div class="min">
<img src={$"./api/v1/video-thumbnail?v={Net.Http.UrlEncode(vi.videoId)}"}> <iframe src={$"./embed?v={Net.Http.UrlEncode(vi.videoId)}"} style="overflow: hidden;" width="640"
height="360" scrolling="no"></iframe>
</div> </div>
<div class="min"> <div class="min">
<raw(Components.AddVideo($"https://www.youtube.com/watch?v={vi.videoId}"))> <raw(Components.AddVideo($"https://www.youtube.com/watch?v={Net.Http.UrlEncode(vi.videoId)}"))>
</div> </div>
<div class="min"> <div class="min">
<raw(Components.AddToPersonalList(tytd,vi.videoId))> <raw(Components.AddToPersonalList(tytd,vi.videoId))>

View File

@@ -167,15 +167,15 @@ class TYTD.Downloader {
if(vid != null) if(vid != null)
{ {
return $"./video?v={Net.Http.UrlEncode(vid)}"; return $"./watch?v={Net.Http.UrlEncode(vid)}";
} }
else if(pid != null) else if(pid != null)
{ {
return $"./playlist?id={Net.Http.UrlEncode(pid)}"; return $"./playlist?list={Net.Http.UrlEncode(pid)}";
} }
else if(cid != null) else if(cid != null)
{ {
return $"./playlist?id={Net.Http.UrlEncode(cid)}"; return $"./channel?id={Net.Http.UrlEncode(cid)}";
} }
return "./"; return "./";
} }