Add support for downloading from this

This commit is contained in:
Mike Nolan 2024-12-08 16:33:13 -06:00
parent f8deea2c78
commit 47731071fe
4 changed files with 40 additions and 4 deletions

View File

@ -1,3 +1,5 @@
using YoutubeExplode.Videos;
public static partial class Creds public static partial class Creds
{ {
public static string IP => _ip; public static string IP => _ip;
@ -10,4 +12,9 @@ public static partial class Creds
public static int Port => _port; public static int Port => _port;
public static string AlreadyExistsUrl=> _alreadyExists; public static string AlreadyExistsUrl=> _alreadyExists;
public static string GetRedirectUrl(VideoId id)
{
return _redir.Replace("%ID%",id.Value);
}
} }

View File

@ -142,9 +142,35 @@ routeServer.Add("/queue.json", async(ctx)=>{
await ctx.SendJsonAsync(items); await ctx.SendJsonAsync(items);
}); });
routeServer.Add("/add",async(ctx)=>{ routeServer.Add("/add",async(ctx)=>{
if(ctx.QueryParams.TryGetFirst("v",out var v))
if(ctx.QueryParams.TryGetFirst("v",out var v) && ctx.QueryParams.TryGetFirst("mode",out var mode))
{ {
await AddItem(v); if(mode == "add")
await AddItem(v);
else
{
var id = VideoId.TryParse(v);
if(id.HasValue)
{
using(SftpClient sftpClient=new SftpClient(IP,Port,Username,Password))
{
await sftpClient.ConnectAsync(default);
await foreach(var item in sftpClient.ListDirectoryAsync(DirectoryOnServer,default))
{
if(item.Name.EndsWith($"-{id.Value.Value}.mp4"))
{
await ctx.WithFileName(item.Name,false).SendStreamAsync(sftpClient.OpenRead(item.FullName));
sftpClient.Disconnect();
return;
}
}
sftpClient.Disconnect();
}
await ctx.SendRedirectAsync(GetRedirectUrl(id.Value));
return;
}
}
} }
await ctx.SendRedirectAsync("/"); await ctx.SendRedirectAsync("/");
}); });

View File

@ -15,6 +15,7 @@ To Configure you must add a file called Creds.priv.cs with the following content
static string _password = "YOUR_SSH_PASSWORD"; static string _password = "YOUR_SSH_PASSWORD";
static string _dir = "YOUR_SSH_PATH"; static string _dir = "YOUR_SSH_PATH";
static int _port = 22; //if ssh is on different port change it here static int _port = 22; //if ssh is on different port change it here
static string _redir = "/not_found?v=%ID%"; //if a video does not exist redirect here
static string _alreadyExists=""; //must be http(s) url such as https://tytdarchive.site.tesses.net/have.php?v= that the response must return "true" if it already exists or "false" if not static string _alreadyExists=""; //must be http(s) url such as https://tytdarchive.site.tesses.net/have.php?v= that the response must return "true" if it already exists or "false" if not
} }

View File

@ -13,6 +13,7 @@
<div> <div>
<i class="extra">download</i> <i class="extra">download</i>
<h5>Add a video, playlist or channel to my TYTD</h5> <h5>Add a video, playlist or channel to my TYTD</h5>
<p>Use <i class="extra">add</i> to add video to queue, or <i class="extra">download</i> to download a video from my TYTD to your device</p>
<div class="space"></div> <div class="space"></div>
<form action="./add"> <form action="./add">
@ -20,9 +21,10 @@
<nav class="no-space"> <nav class="no-space">
<div class="max field border left-round"> <div class="max field border left-round">
<input type="url" name="v"> <input type="text" name="v">
</div> </div>
<button type="submit" class="large right-round">Add</button> <button type="submit" name="mode" value="download" class="large square"><i class="extra">download</i></button>
<button type="submit" name="mode" value="add" class="large right-round"><i class="extra">add</i></button>
</nav> </nav>
</form> </form>