Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using SimpleWebServer;
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading;
- using System.Threading.Tasks;
- namespace ServerControl
- {
- class Program
- {
- static void Main(string[] args)
- {
- WebServer ws = new WebServer("http://*:8080/");
- ws.AddPage("/", rootPage);
- ws.AddPage("/list", list);
- ws.AddPage("/set", set);
- ws.AddPage("/skip", skipCurrent);
- ws.AddPage("/current", getCurrent);
- ws.Run();
- Console.WriteLine("A simple webserver. Press a key to quit.");
- while (true)
- {
- Thread.Sleep(1000);
- }
- ws.Stop();
- }
- public static string rootPage(HttpListenerRequest request) {
- return File.ReadAllText("index.html");
- }
- public static string list(HttpListenerRequest request)
- {
- return executeProcess("find ./content/music/* | sort -V | grep mp4");
- }
- public static string set(HttpListenerRequest request)
- {
- var p = request.QueryString["number"];
- if (p != null && p.All(Char.IsDigit) && p.Length<5) {
- File.WriteAllText("counter.cfg", p);
- }
- executeProcess("killall ffmpeg_stream");
- return "done";
- }
- private static string skipCurrent(HttpListenerRequest request)
- {
- return executeProcess("killall ffmpeg_stream");
- }
- private static string getCurrent(HttpListenerRequest request)
- {
- return File.ReadAllText("counter.cfg");
- }
- private static string executeProcess(string proc)
- {
- Process process = new Process();
- var startInfo = new ProcessStartInfo
- {
- FileName = "/bin/bash",
- Arguments = $"-c \"{proc}\""
- };
- startInfo.UseShellExecute = false;
- startInfo.RedirectStandardOutput = true;
- process.StartInfo = startInfo;
- process.Start();
- string output = process.StandardOutput.ReadToEnd();
- return output;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment