Added Broadcast listening

This commit is contained in:
Mike Nolan 2022-03-03 23:03:34 -06:00
parent 3122652145
commit 2fe0a11f2e
9 changed files with 92 additions and 11 deletions

View File

@ -1,21 +1,22 @@
<Properties StartupConfiguration="{E26F8159-6B4B-4660-A7A4-D0333DFEF0DD}|Default" NuGet.AddPackagesDialog.IncludePrerelease="True">
<MonoDevelop.Ide.Workbench ActiveDocument="Program.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="Broadcast.cs">
<Files>
<File FileName="TYTD.Api/Server/Models/InfoType.cs" Line="155" Column="47" />
<File FileName="TYTD.Api/Server/Functions/Downloader.cs" Line="18" Column="1" />
<File FileName="TYTD.Api/Server/Functions/Downloader.cs" Line="69" Column="28" />
<File FileName="TYTD.Api/Server/Models/SavedMedia.cs" Line="1" Column="1" />
<File FileName="TYTD.Api/Server/Models/SavedVideo.cs" Line="8" Column="1" />
<File FileName="TYTD.Api/Server/Models/InfomationQueueItem.cs" Line="280" Column="42" />
<File FileName="TYTD.Api/Server/Functions/ffmpeg.cs" Line="5" Column="15" />
<File FileName="Program.cs" Line="1060" Column="23" />
<File FileName="TYTD.Api/MyClass.cs" Line="80" Column="14" />
<File FileName="Program.cs" Line="61" Column="13" />
<File FileName="TYTD.Api/MyClass.cs" Line="225" Column="46" />
<File FileName="TYTD.Api/Server/Models/SavedChannel.cs" Line="6" Column="10" />
<File FileName="TYTD.Api/Server/Models/SavedPlaylist.cs" Line="7" Column="1" />
<File FileName="TYTD.Api/Server/Models/VideoDownloadProgress.cs" Line="13" Column="1" />
<File FileName="youtube-downloader.csproj" Line="1" Column="1" />
<File FileName="../../../usr/lib/mono/msbuild/15.0/bin/Microsoft.Common.CurrentVersion.targets" Line="2101" Column="5" />
<File FileName="TYTD.Api/Server/Models/IEnumerator.cs" Line="1" Column="1" />
<File FileName="TYTD.Api/SimpleHttpExtensions.cs" Line="432" Column="1" />
<File FileName="TYTD.Api/SimpleHttpExtensions.cs" Line="17" Column="19" />
<File FileName="Broadcast.cs" Line="11" Column="9" />
</Files>
<Pads>
<Pad Id="ProjectPad">
@ -23,12 +24,13 @@
<Node name="youtube-downloader" expanded="True">
<Node name="TYTD.Api" expanded="True">
<Node name="Server" expanded="True">
<Node name="Functions" expanded="True" />
<Node name="Models" expanded="True" />
</Node>
</Node>
<Node name="youtube-downloader" expanded="True">
<Node name="Properties" expanded="True" />
<Node name="Program.cs" selected="True" />
<Node name="Broadcast.cs" selected="True" />
</Node>
</Node>
</State>

29
Broadcast.cs Normal file
View File

@ -0,0 +1,29 @@
using System;
using System.Net;
namespace TYTD
{
public class Broadcast
{
public Broadcast(ushort port,string name)
{
this.port = port;
this.name = name;
}
public string name { get; set; }
public ushort port { get; set; }
}
public class BroadcastSettings
{
public BroadcastSettings()
{
name = Dns.GetHostName();
broadcast = true;
}
public bool broadcast { get; set; }
public string name { get; set; }
}
}

View File

@ -25,6 +25,7 @@ using YoutubeExplode.Playlists;
using Dasync.Collections;
using YoutubeExplode.Search;
using Hyperlinq;
using System.Net.Sockets;
namespace TYTD
{
@ -53,8 +54,56 @@ namespace TYTD
}));
t2.Start();
string file = Path.Combine("config","discover_info.json");
BroadcastSettings settings = new BroadcastSettings();
//http://+:3250/
if(File.Exists(file))
{
settings=JsonConvert.DeserializeObject<BroadcastSettings>(file);
}
if(settings.broadcast)
{
ushort port = 3250;
if(arg.Length > 0)
{
string url0 = arg[0];
Uri uri = new Uri(url0.Replace("+", "domain"));
port = (ushort)uri.Port;
}
UdpClient cl;
Thread t3 = new Thread(() => {
IPEndPoint end = new IPEndPoint(0, 0);
ushort _port = port;
UdpClient c = new UdpClient(new IPEndPoint(IPAddress.Any, 32501));
while (true)
{
var data= c.Receive(ref end);
string text=Encoding.UTF8.GetString(data);
if(text.Equals("TYTD_BROADCAST", StringComparison.Ordinal))
{
byte[] json = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(new Broadcast(_port,settings.name)));
c.Send(json,json.Length, end);
}
}
});
t3.Start();
}
// we need to get our app name so that
// we can create unique names for our mutex and our pipe
@ -158,7 +207,7 @@ namespace TYTD
/* Other */
Downloader.RouteAdd("/","Other","Home page", (HttpAction)Index);
Downloader.RouteAdd("/", "Other", "Home page", (HttpAction)Index, "GET");
Downloader.RouteAdd("/extensions.html","Other","Extensions URL", (HttpAction)Extensions);
Downloader.RouteAdd("/{Path}","Other","Website Files", (HttpAction)RootPath);
Downloader.RouteAdd("/{Path}","Other","Upload file over put",(HttpAction)UploadFilePut,"PUT");

Binary file not shown.

View File

@ -1 +1 @@
8f38b4bfd3e4101cea207f521c4ab951a53995e7
511bd001c80deda115b5110ee10fd30363c84ec1

View File

@ -122,6 +122,7 @@
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Broadcast.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />