Implemented more API functions

This commit is contained in:
Yorick Rommers
2015-10-29 22:51:45 +01:00
parent 6d9af7c614
commit 6dc28511b1
3 changed files with 53 additions and 2 deletions
+36 -1
View File
@@ -24,7 +24,42 @@ namespace MusicPlayer
return o["songurl"].ToString();
}
return o["errormsg"].ToString();
}
}
public List<Song> GetSongsByAlbum(string albumname)
{
return GetSongsByArgs("album=" + albumname);
}
public List<Song> GetSongsByArtist(string artistname)
{
return GetSongsByArgs("artist=" + artistname);
}
public List<Song> GetSongsByGenre(string genre)
{
return GetSongsByArgs("genre=" + genre);
}
public List<Song> GetSongsByYear(string year)
{
return GetSongsByArgs("album=" + year);
}
public List<Song> GetSongsByArgs(string args)
{
List<Song> songslist = new List<Song>();
JObject o = nw.SendString("getsongs?"+args);
if (o["result"].ToString() == "OK")
{
dynamic songs = o["songs"];
for (int i = 0; i < songs.Count; i++)
{
songslist.Add(new Song(songs[i][0].ToString(), songs[i][3].ToString(), songs[i][5].ToString(), songs[i][4].ToString(), this));
}
}
return songslist;
}
public List<Artist> GetArtists()
{
+16
View File
@@ -19,6 +19,22 @@ namespace MusicPlayer
NetworkHandler nw = new NetworkHandler("http://www.imegumii.nl");
APIHandler api = new APIHandler(nw);
// api.GetSongsByArtist("Amon Amarth").ForEach(s =>
// {
// Console.WriteLine(s.SongID);
// });
// api.GetSongsByYear("2009").ForEach(s =>
// {
// Console.WriteLine(s.Name);
// });
api.GetSongsByGenre("Melodic Death Metal").ForEach(s =>
{
Console.WriteLine(s.Name);
});
// api.GetSongsByAlbum("Stronger").ForEach(s =>
// {
// Console.WriteLine(s.Name);
// });
MainForm form = new MainForm();
new Main(nw, api, form);
+1 -1
View File
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace MusicPlayer
{
class Song
public class Song
{
public string SongID { get; set; }
public string Name { get; set; }