Add support for downloading from this
This commit is contained in:
parent
f8deea2c78
commit
47731071fe
7
Creds.cs
7
Creds.cs
|
@ -1,3 +1,5 @@
|
|||
using YoutubeExplode.Videos;
|
||||
|
||||
public static partial class Creds
|
||||
{
|
||||
public static string IP => _ip;
|
||||
|
@ -10,4 +12,9 @@ public static partial class Creds
|
|||
public static int Port => _port;
|
||||
|
||||
public static string AlreadyExistsUrl=> _alreadyExists;
|
||||
|
||||
public static string GetRedirectUrl(VideoId id)
|
||||
{
|
||||
return _redir.Replace("%ID%",id.Value);
|
||||
}
|
||||
}
|
30
Program.cs
30
Program.cs
|
@ -142,9 +142,35 @@ routeServer.Add("/queue.json", async(ctx)=>{
|
|||
await ctx.SendJsonAsync(items);
|
||||
});
|
||||
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("/");
|
||||
});
|
||||
|
|
|
@ -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 _dir = "YOUR_SSH_PATH";
|
||||
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
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<div>
|
||||
<i class="extra">download</i>
|
||||
<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>
|
||||
<form action="./add">
|
||||
|
@ -20,9 +21,10 @@
|
|||
<nav class="no-space">
|
||||
|
||||
<div class="max field border left-round">
|
||||
<input type="url" name="v">
|
||||
<input type="text" name="v">
|
||||
</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>
|
||||
</form>
|
||||
|
|
Loading…
Reference in New Issue