API getSongURLbyid working

This commit is contained in:
Yorick Rommers
2015-10-29 20:37:36 +01:00
parent 2de025edf7
commit 415e87b787
5 changed files with 32 additions and 14 deletions
+15 -2
View File
@@ -4,16 +4,29 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MusicPlayer;
using Newtonsoft.Json.Linq;
namespace MusicPlayer
{
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();
}
public List<Artist> GetArtists()
{
return null;
-1
View File
@@ -18,7 +18,6 @@ namespace MusicPlayer
public MainForm()
{
InitializeComponent();
// nw.SendString("GET / HTTP/1.1");
}
+8 -3
View File
@@ -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">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
@@ -33,6 +33,10 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<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.Core" />
<Reference Include="System.Xml.Linq" />
@@ -46,7 +50,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainForm.cs" >
<Compile Include="MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="Album.cs" />
@@ -74,6 +78,7 @@
<AutoGen>True</AutoGen>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<None Include="packages.config" />
<None Include="Properties\Settings.settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
@@ -95,4 +100,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
+6 -5
View File
@@ -4,6 +4,8 @@ using System.Net.Sockets;
using System.Threading;
using System.Net;
using System.IO;
using Newtonsoft.Json.Linq;
namespace MusicPlayer
{
@@ -11,15 +13,13 @@ namespace MusicPlayer
{
private int port = 8585;
private string ip;
private APIHandler api;
public NetworkHandler(string ip, APIHandler apihandler)
public NetworkHandler(string 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);
server.KeepAlive = false;
@@ -35,10 +35,11 @@ namespace MusicPlayer
data +=outputData;
count = streamRead.Read(readBuff, 0, 256);
}
System.Console.WriteLine(data);
JObject o = JObject.Parse(data);
respond.Close();
streamResponse.Close();
streamRead.Close();
return o;
}
}
}
+3 -3
View File
@@ -14,9 +14,9 @@ namespace MusicPlayer
[STAThread]
static void Main()
{
APIHandler api = new APIHandler();
NetworkHandler nw = new NetworkHandler("http://www.imegumii.nl", api);
nw.SendString("getsongbyid?id=102");
NetworkHandler nw = new NetworkHandler("http://www.imegumii.nl");
APIHandler api = new APIHandler(nw);
Console.WriteLine(api.GetSongURLByID("102"));
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());