added /api/AddItem

This commit is contained in:
Michael Nolan 2021-09-25 01:18:12 -05:00
parent 6e19a22178
commit 792e566ea2
9 changed files with 246 additions and 36 deletions

View File

@ -1,7 +1,11 @@
<Properties StartupConfiguration="{E26F8159-6B4B-4660-A7A4-D0333DFEF0DD}|Default" NuGet.AddPackagesDialog.IncludePrerelease="True">
<MonoDevelop.Ide.Workbench ActiveDocument="Program.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="Server/Models/InfoType.cs">
<Files>
<File FileName="Program.cs" Line="22" Column="13" />
<File FileName="Program.cs" Line="251" Column="50" />
<File FileName="Server/Models/InfoType.cs" Line="16" Column="6" />
<File FileName="Server/Models/YoutubeDownloaderResponse.cs" Line="1" Column="1" />
<File FileName="Server/Functions/Downloader.cs" Line="210" Column="44" />
<File FileName="Server/Functions/SavedMedia.cs" Line="1" Column="1" />
</Files>
<Pads>
<Pad Id="ProjectPad">
@ -11,9 +15,10 @@
<Node name="Properties" expanded="True" />
<Node name="Server" expanded="True">
<Node name="Functions" expanded="True" />
<Node name="Models" expanded="True" />
<Node name="Models" expanded="True">
<Node name="InfoType.cs" selected="True" />
</Node>
</Node>
<Node name="Program.cs" selected="True" />
</Node>
</Node>
</State>

View File

@ -11,6 +11,9 @@ using System.Threading;
using TessesYoutubeDownloader.Server.Models;
using Newtonsoft.Json;
using Makaretu.Dns;
using System.Net;
using System.Threading.Tasks;
using youtube_downloader.Server.Models;
namespace youtube_downloader
{
@ -30,22 +33,7 @@ namespace youtube_downloader
}));
t2.Start();
Thread t3 = new Thread(new ThreadStart(() =>
{
int port = 3250;
if(arg.Length > 0)
{
Uri uri;
if(Uri.TryCreate(arg[0], UriKind.Absolute, out uri))
{
port = uri.Port;
}
}
var service = new ServiceProfile("tytd", "_tesses-services._tcp", (ushort)port);
var sd = new ServiceDiscovery();
sd.Advertise(service);
}));
// we need to get our app name so that
// we can create unique names for our mutex and our pipe
string webSitePath = Server.Functions.Downloader.DL.GetPath(true, "WebSite");
@ -62,7 +50,7 @@ namespace youtube_downloader
f.Save(Path.Combine(webSitePath,f.FileName));
rp.AsText("uploaded", "text/plain");
},"POST");
Route.Add("/api/AddItems", (HttpActionAsync)AddItems,"POST");
Route.Add("/", (rq, rp, args) =>
{
rp.AsFile(rq, Path.Combine(webSitePath, "index.html"));
@ -242,7 +230,7 @@ namespace youtube_downloader
rp.AsFile(rq, path);
});
Console.WriteLine("Almost Ready To Listen");
t3.Start();
if (arg.Length > 0)
{
@ -254,17 +242,28 @@ namespace youtube_downloader
HttpServer.ListenAsync(3250, CancellationToken.None, Route.OnHttpRequestAsync).Wait();
}
}
/*
private static string HandleRequest(Stream inputStream, Encoding currentEncoding)
{
using (var streamReader = new StreamReader(inputStream, currentEncoding))
{
return Newtonsoft.Json.JsonConvert.SerializeObject(HandleRequest(Newtonsoft.Json.JsonConvert.DeserializeObject<YoutubeDownloaderRequest>(streamReader.ReadToEnd()));
}
}
private static YoutubeDownloaderResponse HandleRequest(YoutubeDownloaderRequest data)
{
}*/
private static async Task AddItems(HttpListenerRequest request, HttpListenerResponse response, Dictionary<string, string> arguments)
{
using (var req = new StreamReader(request.InputStream,request.ContentEncoding))
{
List<IDResolutionTypeTriplet> tripletlst = JsonConvert.DeserializeObject<List<IDResolutionTypeTriplet>>(await req.ReadToEndAsync());
Server.Functions.Downloader.DownloadItems(tripletlst);
response.Redirect("/");
}
}
/*
private static string HandleRequest(Stream inputStream, Encoding currentEncoding)
{
using (var streamReader = new StreamReader(inputStream, currentEncoding))
{
return Newtonsoft.Json.JsonConvert.SerializeObject(HandleRequest(Newtonsoft.Json.JsonConvert.DeserializeObject<YoutubeDownloaderRequest>(streamReader.ReadToEnd()));
}
}
private static YoutubeDownloaderResponse HandleRequest(YoutubeDownloaderRequest data)
{
}*/
}
}

View File

@ -201,8 +201,27 @@ namespace youtube_downloader.Server.Functions
}
}
}
public static void DownloadItems(List<IDResolutionTypeTriplet> id)
{
List<InfomationQueueItem> items = new List<InfomationQueueItem>();
foreach(var item in id)
{
var iqi = item.ToInfomationQueueItem();
if(iqi != null)
{
items.Add(iqi);
}
}
if (items.Count > 0)
{
lock (DL.infoQueue)
{
internal static void DownloadUserOnly(string id)
DL.infoQueue.InsertRange(0,items);
}
}
}
internal static void DownloadUserOnly(string id)
{
UserName? v = UserName.TryParse(id);
if (v.HasValue)

View File

@ -1,4 +1,8 @@
namespace youtube_downloader.Server.Models
using YoutubeExplode.Channels;
using YoutubeExplode.Playlists;
using YoutubeExplode.Videos;
namespace youtube_downloader.Server.Models
{
public enum InfoType
{
@ -8,4 +12,45 @@
User=3,
ClosedCaptions=4
}
public class IDResolutionTypeTriplet
{
public string Id { get; set; }
public InfoType Type { get; set; }
public TessesYoutubeDownloader.Server.Models.Resolution Resolution { get; set; }
public InfomationQueueItem ToInfomationQueueItem(bool download=true)
{
switch(Type)
{
case InfoType.Video:
VideoId? vid = VideoId.TryParse(Id);
if (vid.HasValue)
{
return new InfomationQueueItem(vid.Value, Resolution, download);
}
break;
case InfoType.Playlist:
PlaylistId? pid = PlaylistId.TryParse(Id);
if (pid.HasValue)
{
return new InfomationQueueItem(pid.Value, Resolution, download);
}
break;
case InfoType.Channel:
ChannelId? cid = ChannelId.TryParse(Id);
if (cid.HasValue)
{
return new InfomationQueueItem(cid.Value, Resolution, download);
}
break;
case InfoType.User:
UserName? user = UserName.TryParse(Id);
if (user.HasValue)
{
return new InfomationQueueItem(user.Value, Resolution, download);
}
break;
}
return null;
}
}
}

Binary file not shown.

View File

@ -1 +1 @@
d607a7342c320f7511cae09413e5de7e2242b37f
191b06d8a6f86332255c3af5c32e3875798ab34e

View File

@ -140,3 +140,145 @@
/home/tom/site/bin/Release/Makaretu.Dns.pdb
/home/tom/site/bin/Release/Makaretu.Dns.xml
/home/tom/site/bin/Release/Makaretu.Dns.Multicast.xml
/home/ddlovato/site/obj/x86/Release/youtube-downloader.csprojAssemblyReference.cache
/home/ddlovato/site/obj/x86/Release/youtube-downloader.csproj.CoreCompileInputs.cache
/home/ddlovato/site/obj/x86/Release/youtube-downloader.exe
/home/ddlovato/site/bin/Release/youtube-downloader.exe
/home/ddlovato/site/bin/Release/System.Runtime.InteropServices.RuntimeInformation.dll
/home/ddlovato/site/bin/Release/System.Security.Cryptography.Algorithms.dll
/home/ddlovato/site/bin/Release/System.ValueTuple.dll
/home/ddlovato/site/bin/Release/Microsoft.Win32.Primitives.dll
/home/ddlovato/site/bin/Release/netstandard.dll
/home/ddlovato/site/bin/Release/System.AppContext.dll
/home/ddlovato/site/bin/Release/System.Collections.Concurrent.dll
/home/ddlovato/site/bin/Release/System.Collections.dll
/home/ddlovato/site/bin/Release/System.Collections.NonGeneric.dll
/home/ddlovato/site/bin/Release/System.Collections.Specialized.dll
/home/ddlovato/site/bin/Release/System.ComponentModel.dll
/home/ddlovato/site/bin/Release/System.ComponentModel.EventBasedAsync.dll
/home/ddlovato/site/bin/Release/System.ComponentModel.Primitives.dll
/home/ddlovato/site/bin/Release/System.ComponentModel.TypeConverter.dll
/home/ddlovato/site/bin/Release/System.Console.dll
/home/ddlovato/site/bin/Release/System.Data.Common.dll
/home/ddlovato/site/bin/Release/System.Diagnostics.Contracts.dll
/home/ddlovato/site/bin/Release/System.Diagnostics.Debug.dll
/home/ddlovato/site/bin/Release/System.Diagnostics.FileVersionInfo.dll
/home/ddlovato/site/bin/Release/System.Diagnostics.Process.dll
/home/ddlovato/site/bin/Release/System.Diagnostics.StackTrace.dll
/home/ddlovato/site/bin/Release/System.Diagnostics.TextWriterTraceListener.dll
/home/ddlovato/site/bin/Release/System.Diagnostics.Tools.dll
/home/ddlovato/site/bin/Release/System.Diagnostics.TraceSource.dll
/home/ddlovato/site/bin/Release/System.Diagnostics.Tracing.dll
/home/ddlovato/site/bin/Release/System.Drawing.Primitives.dll
/home/ddlovato/site/bin/Release/System.Dynamic.Runtime.dll
/home/ddlovato/site/bin/Release/System.Globalization.Calendars.dll
/home/ddlovato/site/bin/Release/System.Globalization.dll
/home/ddlovato/site/bin/Release/System.Globalization.Extensions.dll
/home/ddlovato/site/bin/Release/System.IO.Compression.dll
/home/ddlovato/site/bin/Release/System.IO.Compression.ZipFile.dll
/home/ddlovato/site/bin/Release/System.IO.dll
/home/ddlovato/site/bin/Release/System.IO.FileSystem.dll
/home/ddlovato/site/bin/Release/System.IO.FileSystem.DriveInfo.dll
/home/ddlovato/site/bin/Release/System.IO.FileSystem.Primitives.dll
/home/ddlovato/site/bin/Release/System.IO.FileSystem.Watcher.dll
/home/ddlovato/site/bin/Release/System.IO.IsolatedStorage.dll
/home/ddlovato/site/bin/Release/System.IO.MemoryMappedFiles.dll
/home/ddlovato/site/bin/Release/System.IO.Pipes.dll
/home/ddlovato/site/bin/Release/System.IO.UnmanagedMemoryStream.dll
/home/ddlovato/site/bin/Release/System.Linq.dll
/home/ddlovato/site/bin/Release/System.Linq.Expressions.dll
/home/ddlovato/site/bin/Release/System.Linq.Parallel.dll
/home/ddlovato/site/bin/Release/System.Linq.Queryable.dll
/home/ddlovato/site/bin/Release/System.Net.Http.dll
/home/ddlovato/site/bin/Release/System.Net.NameResolution.dll
/home/ddlovato/site/bin/Release/System.Net.NetworkInformation.dll
/home/ddlovato/site/bin/Release/System.Net.Ping.dll
/home/ddlovato/site/bin/Release/System.Net.Primitives.dll
/home/ddlovato/site/bin/Release/System.Net.Requests.dll
/home/ddlovato/site/bin/Release/System.Net.Security.dll
/home/ddlovato/site/bin/Release/System.Net.Sockets.dll
/home/ddlovato/site/bin/Release/System.Net.WebHeaderCollection.dll
/home/ddlovato/site/bin/Release/System.Net.WebSockets.Client.dll
/home/ddlovato/site/bin/Release/System.Net.WebSockets.dll
/home/ddlovato/site/bin/Release/System.ObjectModel.dll
/home/ddlovato/site/bin/Release/System.Reflection.dll
/home/ddlovato/site/bin/Release/System.Reflection.Extensions.dll
/home/ddlovato/site/bin/Release/System.Reflection.Primitives.dll
/home/ddlovato/site/bin/Release/System.Resources.Reader.dll
/home/ddlovato/site/bin/Release/System.Resources.ResourceManager.dll
/home/ddlovato/site/bin/Release/System.Resources.Writer.dll
/home/ddlovato/site/bin/Release/System.Runtime.CompilerServices.VisualC.dll
/home/ddlovato/site/bin/Release/System.Runtime.dll
/home/ddlovato/site/bin/Release/System.Runtime.Extensions.dll
/home/ddlovato/site/bin/Release/System.Runtime.Handles.dll
/home/ddlovato/site/bin/Release/System.Runtime.InteropServices.dll
/home/ddlovato/site/bin/Release/System.Runtime.Numerics.dll
/home/ddlovato/site/bin/Release/System.Runtime.Serialization.Formatters.dll
/home/ddlovato/site/bin/Release/System.Runtime.Serialization.Json.dll
/home/ddlovato/site/bin/Release/System.Runtime.Serialization.Primitives.dll
/home/ddlovato/site/bin/Release/System.Runtime.Serialization.Xml.dll
/home/ddlovato/site/bin/Release/System.Security.Claims.dll
/home/ddlovato/site/bin/Release/System.Security.Cryptography.Csp.dll
/home/ddlovato/site/bin/Release/System.Security.Cryptography.Encoding.dll
/home/ddlovato/site/bin/Release/System.Security.Cryptography.Primitives.dll
/home/ddlovato/site/bin/Release/System.Security.Cryptography.X509Certificates.dll
/home/ddlovato/site/bin/Release/System.Security.Principal.dll
/home/ddlovato/site/bin/Release/System.Security.SecureString.dll
/home/ddlovato/site/bin/Release/System.Text.Encoding.dll
/home/ddlovato/site/bin/Release/System.Text.Encoding.Extensions.dll
/home/ddlovato/site/bin/Release/System.Text.RegularExpressions.dll
/home/ddlovato/site/bin/Release/System.Threading.dll
/home/ddlovato/site/bin/Release/System.Threading.Overlapped.dll
/home/ddlovato/site/bin/Release/System.Threading.Tasks.dll
/home/ddlovato/site/bin/Release/System.Threading.Tasks.Parallel.dll
/home/ddlovato/site/bin/Release/System.Threading.Thread.dll
/home/ddlovato/site/bin/Release/System.Threading.ThreadPool.dll
/home/ddlovato/site/bin/Release/System.Threading.Timer.dll
/home/ddlovato/site/bin/Release/System.Xml.ReaderWriter.dll
/home/ddlovato/site/bin/Release/System.Xml.XDocument.dll
/home/ddlovato/site/bin/Release/System.Xml.XmlDocument.dll
/home/ddlovato/site/bin/Release/System.Xml.XmlSerializer.dll
/home/ddlovato/site/bin/Release/System.Xml.XPath.dll
/home/ddlovato/site/bin/Release/System.Xml.XPath.XDocument.dll
/home/ddlovato/site/bin/Release/AngleSharp.dll
/home/ddlovato/site/bin/Release/AsyncEnumerable.dll
/home/ddlovato/site/bin/Release/Common.Logging.Core.dll
/home/ddlovato/site/bin/Release/Common.Logging.dll
/home/ddlovato/site/bin/Release/Makaretu.Dns.dll
/home/ddlovato/site/bin/Release/Makaretu.Dns.Multicast.dll
/home/ddlovato/site/bin/Release/Microsoft.Bcl.AsyncInterfaces.dll
/home/ddlovato/site/bin/Release/MimeTypesMap.dll
/home/ddlovato/site/bin/Release/Newtonsoft.Json.dll
/home/ddlovato/site/bin/Release/SimpleBase.dll
/home/ddlovato/site/bin/Release/SimpleHTTP.dll
/home/ddlovato/site/bin/Release/System.Buffers.dll
/home/ddlovato/site/bin/Release/System.Memory.dll
/home/ddlovato/site/bin/Release/System.Net.IPNetwork.dll
/home/ddlovato/site/bin/Release/System.Numerics.Vectors.dll
/home/ddlovato/site/bin/Release/System.Runtime.CompilerServices.Unsafe.dll
/home/ddlovato/site/bin/Release/System.Text.Encoding.CodePages.dll
/home/ddlovato/site/bin/Release/System.Text.Encodings.Web.dll
/home/ddlovato/site/bin/Release/System.Text.Json.dll
/home/ddlovato/site/bin/Release/System.Threading.Tasks.Extensions.dll
/home/ddlovato/site/bin/Release/YoutubeExplode.dll
/home/ddlovato/site/bin/Release/Newtonsoft.Json.xml
/home/ddlovato/site/bin/Release/System.Buffers.xml
/home/ddlovato/site/bin/Release/System.Numerics.Vectors.xml
/home/ddlovato/site/bin/Release/System.Runtime.CompilerServices.Unsafe.xml
/home/ddlovato/site/bin/Release/System.Memory.xml
/home/ddlovato/site/bin/Release/AngleSharp.xml
/home/ddlovato/site/bin/Release/System.Text.Encodings.Web.xml
/home/ddlovato/site/bin/Release/System.Threading.Tasks.Extensions.xml
/home/ddlovato/site/bin/Release/Microsoft.Bcl.AsyncInterfaces.xml
/home/ddlovato/site/bin/Release/System.Text.Json.xml
/home/ddlovato/site/bin/Release/YoutubeExplode.xml
/home/ddlovato/site/bin/Release/SimpleHTTP.xml
/home/ddlovato/site/bin/Release/AsyncEnumerable.xml
/home/ddlovato/site/bin/Release/Common.Logging.Core.pdb
/home/ddlovato/site/bin/Release/Common.Logging.pdb
/home/ddlovato/site/bin/Release/Common.Logging.xml
/home/ddlovato/site/bin/Release/SimpleBase.pdb
/home/ddlovato/site/bin/Release/Makaretu.Dns.pdb
/home/ddlovato/site/bin/Release/Makaretu.Dns.xml
/home/ddlovato/site/bin/Release/Makaretu.Dns.Multicast.xml
/home/ddlovato/site/obj/x86/Release/youtube-downloader.csproj.CopyComplete