API getSongURLbyid working
This commit is contained in:
@@ -4,13 +4,26 @@ using System.Linq;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MusicPlayer;
|
using MusicPlayer;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
namespace MusicPlayer
|
namespace MusicPlayer
|
||||||
{
|
{
|
||||||
internal class APIHandler
|
internal class APIHandler
|
||||||
{
|
{
|
||||||
public APIHandler()
|
private NetworkHandler nw;
|
||||||
|
|
||||||
|
public APIHandler(NetworkHandler nw)
|
||||||
{
|
{
|
||||||
|
this.nw = nw;
|
||||||
|
}
|
||||||
|
|
||||||
|
public string GetSongURLByID(string id)
|
||||||
|
{
|
||||||
|
JObject o = nw.SendString("getsongbyid?id=" + id);
|
||||||
|
if (o["result"].ToString() == "OK") {
|
||||||
|
return o["songurl"].ToString();
|
||||||
|
}
|
||||||
|
return o["errormsg"].ToString();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,6 @@ namespace MusicPlayer
|
|||||||
public MainForm()
|
public MainForm()
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
// nw.SendString("GET / HTTP/1.1");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
@@ -33,6 +33,10 @@
|
|||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Reference Include="Newtonsoft.Json, Version=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||||
|
<HintPath>..\packages\Newtonsoft.Json.7.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
|
||||||
|
<Private>True</Private>
|
||||||
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
@@ -74,6 +78,7 @@
|
|||||||
<AutoGen>True</AutoGen>
|
<AutoGen>True</AutoGen>
|
||||||
<DependentUpon>Resources.resx</DependentUpon>
|
<DependentUpon>Resources.resx</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
<None Include="packages.config" />
|
||||||
<None Include="Properties\Settings.settings">
|
<None Include="Properties\Settings.settings">
|
||||||
<Generator>SettingsSingleFileGenerator</Generator>
|
<Generator>SettingsSingleFileGenerator</Generator>
|
||||||
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ using System.Net.Sockets;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
|
||||||
|
|
||||||
namespace MusicPlayer
|
namespace MusicPlayer
|
||||||
{
|
{
|
||||||
@@ -11,15 +13,13 @@ namespace MusicPlayer
|
|||||||
{
|
{
|
||||||
private int port = 8585;
|
private int port = 8585;
|
||||||
private string ip;
|
private string ip;
|
||||||
private APIHandler api;
|
|
||||||
|
|
||||||
public NetworkHandler(string ip, APIHandler apihandler)
|
public NetworkHandler(string ip)
|
||||||
{
|
{
|
||||||
this.ip = ip;
|
this.ip = ip;
|
||||||
this.api = apihandler;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendString(string m)
|
public JObject SendString(string m)
|
||||||
{
|
{
|
||||||
HttpWebRequest server = (HttpWebRequest)WebRequest.Create(ip+":"+port+"/"+m);
|
HttpWebRequest server = (HttpWebRequest)WebRequest.Create(ip+":"+port+"/"+m);
|
||||||
server.KeepAlive = false;
|
server.KeepAlive = false;
|
||||||
@@ -35,10 +35,11 @@ namespace MusicPlayer
|
|||||||
data +=outputData;
|
data +=outputData;
|
||||||
count = streamRead.Read(readBuff, 0, 256);
|
count = streamRead.Read(readBuff, 0, 256);
|
||||||
}
|
}
|
||||||
System.Console.WriteLine(data);
|
JObject o = JObject.Parse(data);
|
||||||
respond.Close();
|
respond.Close();
|
||||||
streamResponse.Close();
|
streamResponse.Close();
|
||||||
streamRead.Close();
|
streamRead.Close();
|
||||||
|
return o;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,9 +14,9 @@ namespace MusicPlayer
|
|||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
APIHandler api = new APIHandler();
|
NetworkHandler nw = new NetworkHandler("http://www.imegumii.nl");
|
||||||
NetworkHandler nw = new NetworkHandler("http://www.imegumii.nl", api);
|
APIHandler api = new APIHandler(nw);
|
||||||
nw.SendString("getsongbyid?id=102");
|
Console.WriteLine(api.GetSongURLByID("102"));
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
Application.SetCompatibleTextRenderingDefault(false);
|
Application.SetCompatibleTextRenderingDefault(false);
|
||||||
Application.Run(new MainForm());
|
Application.Run(new MainForm());
|
||||||
|
|||||||
Reference in New Issue
Block a user