93 lines
2.6 KiB
C#
93 lines
2.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Net.Http.Headers;
|
|
using System.Net.Http;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace AnimeCon.Vlc.Starter
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void btnAdd_Click(object sender, EventArgs e)
|
|
{
|
|
lbHosts.Items.Add(txtHostname.Text);
|
|
}
|
|
|
|
private void btnRemove_Click(object sender, EventArgs e)
|
|
{
|
|
lbHosts.Items.Remove(lbHosts.SelectedItems[lbHosts.SelectedIndex]);
|
|
}
|
|
|
|
private void btnPause_Click(object sender, EventArgs e)
|
|
{
|
|
foreach (var item in lbHosts.Items)
|
|
{
|
|
DoWebRequestAsync(item.ToString(), "pl_pause");
|
|
}
|
|
}
|
|
|
|
private void btnStop_Click(object sender, EventArgs e)
|
|
{
|
|
foreach (var item in lbHosts.Items)
|
|
{
|
|
DoWebRequestAsync(item.ToString(), "pl_stop");
|
|
}
|
|
}
|
|
|
|
private void btnPrevious_Click(object sender, EventArgs e)
|
|
{
|
|
foreach (var item in lbHosts.Items)
|
|
{
|
|
DoWebRequestAsync(item.ToString(), "pl_previous");
|
|
}
|
|
}
|
|
|
|
private void btnNext_Click(object sender, EventArgs e)
|
|
{
|
|
foreach (var item in lbHosts.Items)
|
|
{
|
|
DoWebRequestAsync(item.ToString(), "pl_next");
|
|
}
|
|
}
|
|
|
|
private async Task DoWebRequestAsync(string hostname, string command)
|
|
{
|
|
using (HttpClient httpClient = new HttpClient())
|
|
{
|
|
// Convert the credentials to Base64
|
|
string base64Credentials = Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes($":{txtPassword.Text}"));
|
|
|
|
// Add Authorization header with Basic Authentication
|
|
httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", base64Credentials);
|
|
|
|
try
|
|
{
|
|
// Make a GET request to the remote XML file
|
|
HttpResponseMessage response = await httpClient.GetAsync($"http://{hostname}/requests/status.xml?command={command}");
|
|
|
|
// Ensure the request was successful
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
return;
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
// Handle exception
|
|
Console.WriteLine($"Error: {ex.Message}");
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|