Merge remote-tracking branch 'origin/search' into developer

This commit is contained in:
Yorick Rommers
2015-11-02 21:38:32 +01:00
10 changed files with 1510 additions and 30 deletions
+66 -1
View File
@@ -20,6 +20,16 @@ namespace MusicPlayer
defaultCover = Image.FromStream(nw.downloadArtwork("default-cover.png"));
}
public JObject GetAllBySearch(string search, string album, string artist, string genre)
{
// Q artist genre album
JObject o = nw.SendString($"search?q={search}&album={album}&genre={genre}&artist={artist}");
Console.WriteLine(o.PropertyValues().ToString());
if (o["result"].ToString() == "OK") { return o; }
return null;
}
public string GetSongURLByID(string id)
{
JObject o = nw.SendString("getsongbyid?id=" + id);
@@ -54,6 +64,61 @@ namespace MusicPlayer
return GetSongsByArgs("search=" + search);
}
public List<Genre> Genrify(JObject o)
{
List<Genre> genreslist = new List<Genre>();
if (o["result"].ToString() == "OK")
{
for (int i = 0; i < o["genres"].Count(); i++)
{
genreslist.Add(new Genre(o["genres"][i][0].ToString()));
}
}
return genreslist;
}
public List<Artist> Artistify(JObject o)
{
List<Artist> artistlist = new List<Artist>();
if (o["result"].ToString() == "OK")
{
for (int i = 0; i < o["artists"].Count(); i++)
{
artistlist.Add(new Artist(o["artists"][i][0].ToString()));
}
}
return artistlist;
}
public List<Song> Songify(JObject o)
{
List<Song> allsongslist = new List<Song>();
if (o["result"].ToString() == "OK")
{
dynamic songs = o["songs"];
for (int i = 0; i < songs.Count; i++)
{
allsongslist.Add(new Song(songs[i][0].ToString(), songs[i][3].ToString(), songs[i][5].ToString(), songs[i][4].ToString(), songs[i][1].ToString(), (int)songs[i][9], this));
}
}
return allsongslist;
}
public List<Album> Albumify(JObject o)
{
List<Album> albumlist = new List<Album>();
if (o["result"].ToString() == "OK")
{
for (int i = 0; i < o["albums"].Count(); i++)
{
albumlist.Add(new Album(o["albums"][i][0].ToString()));
}
}
return albumlist;
}
public List<Song> GetAllSongs()
{
List<Song> allsongslist = new List<Song>();
@@ -90,7 +155,7 @@ namespace MusicPlayer
{
List<Artist> artistlist = new List<Artist>();
JObject o = nw.SendString("getartists?id=hallo");
JObject o = nw.SendString("getartists?");
if (o["result"].ToString() == "OK")
{
for (int i = 0; i < o["artists"].Count(); i++) {
+177
View File
@@ -0,0 +1,177 @@
using System.Windows.Forms;
namespace MusicPlayer
{
partial class AdvancedSearch
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(AdvancedSearch));
this.SearchTermTextBox = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.AlbumTextBox = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.ArtistTextBox = new System.Windows.Forms.TextBox();
this.GenreTextBox = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.SearchButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// SearchTermTextBox
//
this.SearchTermTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.SearchTermTextBox.Location = new System.Drawing.Point(12, 29);
this.SearchTermTextBox.Name = "SearchTermTextBox";
this.SearchTermTextBox.Size = new System.Drawing.Size(210, 20);
this.SearchTermTextBox.TabIndex = 0;
this.SearchTermTextBox.KeyDown += TextBox_KeyDown;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 13);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(68, 13);
this.label1.TabIndex = 1;
this.label1.Text = "Search Term";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(12, 70);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(36, 13);
this.label2.TabIndex = 2;
this.label2.Text = "Album";
//
// AlbumTextBox
//
this.AlbumTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.AlbumTextBox.Location = new System.Drawing.Point(12, 86);
this.AlbumTextBox.Name = "AlbumTextBox";
this.AlbumTextBox.Size = new System.Drawing.Size(210, 20);
this.AlbumTextBox.TabIndex = 3;
this.AlbumTextBox.KeyDown += TextBox_KeyDown;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(12, 119);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(30, 13);
this.label3.TabIndex = 4;
this.label3.Text = "Artist";
//
// ArtistTextBox
//
this.ArtistTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.ArtistTextBox.Location = new System.Drawing.Point(12, 135);
this.ArtistTextBox.Name = "ArtistTextBox";
this.ArtistTextBox.Size = new System.Drawing.Size(210, 20);
this.ArtistTextBox.TabIndex = 5;
this.ArtistTextBox.KeyDown += TextBox_KeyDown;
//
// GenreTextBox
//
this.GenreTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.GenreTextBox.Location = new System.Drawing.Point(12, 187);
this.GenreTextBox.Name = "GenreTextBox";
this.GenreTextBox.Size = new System.Drawing.Size(210, 20);
this.GenreTextBox.TabIndex = 6;
this.GenreTextBox.KeyDown += TextBox_KeyDown;
//
// label4
//
this.label4.AutoSize = true;
this.label4.Location = new System.Drawing.Point(13, 168);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(36, 13);
this.label4.TabIndex = 7;
this.label4.Text = "Genre";
//
// SearchButton
//
this.SearchButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.SearchButton.Location = new System.Drawing.Point(12, 226);
this.SearchButton.Name = "SearchButton";
this.SearchButton.Size = new System.Drawing.Size(210, 23);
this.SearchButton.TabIndex = 8;
this.SearchButton.Text = "Search";
this.SearchButton.UseVisualStyleBackColor = true;
this.SearchButton.Click += new System.EventHandler(this.SearchButton_Click);
//
// AdvancedSearch
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(234, 261);
this.Controls.Add(this.SearchButton);
this.Controls.Add(this.label4);
this.Controls.Add(this.GenreTextBox);
this.Controls.Add(this.ArtistTextBox);
this.Controls.Add(this.label3);
this.Controls.Add(this.AlbumTextBox);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.SearchTermTextBox);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximumSize = new System.Drawing.Size(450, 300);
this.MinimumSize = new System.Drawing.Size(250, 300);
this.Name = "AdvancedSearch";
this.Text = "Advanced Search";
this.ResumeLayout(false);
this.PerformLayout();
}
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Enter)
{
SearchButton_Click(sender, new System.EventArgs());
}
}
#endregion
private TextBox SearchTermTextBox;
private Label label1;
private Label label2;
private TextBox AlbumTextBox;
private Label label3;
private TextBox ArtistTextBox;
private TextBox GenreTextBox;
private Label label4;
private Button SearchButton;
}
}
+38
View File
@@ -0,0 +1,38 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace MusicPlayer
{
public partial class AdvancedSearch : Form
{
private Main main;
public AdvancedSearch(Main main)
{
this.main = main;
InitializeComponent();
}
private void SearchButton_Click(object sender, EventArgs e)
{
if(SearchTermTextBox.Text.Length > 1)
{
SearchTermTextBox.ForeColor = Color.Black;
main.AdvancedSearchFilter(SearchTermTextBox.Text, AlbumTextBox.Text, ArtistTextBox.Text, GenreTextBox.Text);
this.Close();
}
else
{
SearchTermTextBox.ForeColor = Color.Red;
}
}
}
}
File diff suppressed because it is too large Load Diff
+2 -4
View File
@@ -61,7 +61,7 @@ namespace MusicPlayer
CurrentSong = null;
Thread.Sleep(11);
Thread.Sleep(10);
ms = new MemoryStream();
@@ -127,7 +127,6 @@ namespace MusicPlayer
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace);
AState = AudioState.STOPPED;
main.form.SongFinished();
return;
@@ -230,7 +229,6 @@ namespace MusicPlayer
}
catch(Exception e)
{
Console.WriteLine(e.StackTrace);
BState = BufferState.EMPTY;
AState = AudioState.STOPPED;
main.form.SongFinished();
@@ -242,7 +240,7 @@ namespace MusicPlayer
LengthBuffer = response.ContentLength;
using (var stream = response.GetResponseStream())
{
byte[] buffer = new byte[65536]; // 32KB chunks
byte[] buffer = new byte[65536]; // 64KB chunks
int read;
BState = BufferState.BUFFERING;
+57 -1
View File
@@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
namespace MusicPlayer
{
@@ -85,7 +86,6 @@ namespace MusicPlayer
foreach (ListViewItem item in form.AlbumListView.Items)
{
templist.Add(item.Text);
Console.WriteLine(item.Text);
}
};
form.Invoke(action);
@@ -137,6 +137,62 @@ namespace MusicPlayer
});
}
public void AdvancedSearchFilter(string search, string album, string artist, string genre)
{
JObject o = api.GetAllBySearch(search, album, artist, genre);
if (o != null)
{
//q
form.AlbumListView.Items.Clear();
form.ArtistListBox.Items.Clear();
form.GenreListBox.Items.Clear();
form.PlaylistBox.Items.Clear();
table.Clear();
api.Songify(o).ForEach(s => table.Add(s));
//albums
api.Albumify(o).ForEach(a => form.AlbumListView.Items.Add(a.albumnaam));
//artists
api.Artistify(o).ForEach(a => form.ArtistListBox.Items.Add(a.naam));
//genres
api.Genrify(o).ForEach(g => form.GenreListBox.Items.Add(g.name));
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += new DoWorkEventHandler(
delegate (object x, DoWorkEventArgs args)
{
BackgroundWorker b = x as BackgroundWorker;
ImageList imagelist = new ImageList();
List<string> templist = new List<string>();
Action action = () =>
{
foreach (ListViewItem item in form.AlbumListView.Items)
{
templist.Add(item.Text);
}
};
form.Invoke(action);
foreach (string item in templist)
{
imagelist.Images.Add(item, api.getAlbumCover(item));
}
action = () => {
form.AlbumListView.LargeImageList = imagelist;
foreach (ListViewItem item in form.AlbumListView.Items)
{
item.ImageKey = item.Text;
}
};
form.Invoke(action);
});
bw.RunWorkerAsync();
}
}
public void FilterCurrentPlaying()
{
table.Clear();
+40 -22
View File
@@ -68,6 +68,9 @@ namespace MusicPlayer
this.SearchArtistToolStripLabel = new System.Windows.Forms.ToolStripMenuItem();
this.SearchArtistsTextBox = new System.Windows.Forms.ToolStripTextBox();
this.ClearArtistSearchButton = new System.Windows.Forms.ToolStripMenuItem();
this.songsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SearchSongsTextBox = new System.Windows.Forms.ToolStripTextBox();
this.SearchSongsButton = new System.Windows.Forms.ToolStripMenuItem();
this.serverToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SelectServerJancoButton = new System.Windows.Forms.ToolStripMenuItem();
this.SelectServerYorickButton = new System.Windows.Forms.ToolStripMenuItem();
@@ -104,9 +107,8 @@ namespace MusicPlayer
this.toolStripSeparator3 = new System.Windows.Forms.ToolStripSeparator();
this.NotifyMenuStripNextButton = new System.Windows.Forms.ToolStripMenuItem();
this.NotifyMenuStripPreviousButton = new System.Windows.Forms.ToolStripMenuItem();
this.songsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.SearchSongsTextBox = new System.Windows.Forms.ToolStripTextBox();
this.SearchSongsButton = new System.Windows.Forms.ToolStripMenuItem();
this.AdvancedSearchButton = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripSeparator7 = new System.Windows.Forms.ToolStripSeparator();
((System.ComponentModel.ISupportInitialize)(this.SongsTableView)).BeginInit();
this.MainPanel.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.SplitContainer)).BeginInit();
@@ -427,7 +429,9 @@ namespace MusicPlayer
this.searchToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SearchGenresToolStripLabel,
this.SearchArtistToolStripLabel,
this.songsToolStripMenuItem});
this.songsToolStripMenuItem,
this.toolStripSeparator7,
this.AdvancedSearchButton});
this.searchToolStripMenuItem.Name = "searchToolStripMenuItem";
this.searchToolStripMenuItem.Size = new System.Drawing.Size(54, 20);
this.searchToolStripMenuItem.Text = "Search";
@@ -478,6 +482,28 @@ namespace MusicPlayer
this.ClearArtistSearchButton.Text = "Clear Search";
this.ClearArtistSearchButton.Click += new System.EventHandler(this.ClearArtistSearchButton_Click);
//
// songsToolStripMenuItem
//
this.songsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SearchSongsTextBox,
this.SearchSongsButton});
this.songsToolStripMenuItem.Name = "songsToolStripMenuItem";
this.songsToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.songsToolStripMenuItem.Text = "Songs";
//
// SearchSongsTextBox
//
this.SearchSongsTextBox.Name = "SearchSongsTextBox";
this.SearchSongsTextBox.Size = new System.Drawing.Size(100, 23);
//
// SearchSongsButton
//
this.SearchSongsButton.Enabled = false;
this.SearchSongsButton.Name = "SearchSongsButton";
this.SearchSongsButton.Size = new System.Drawing.Size(160, 22);
this.SearchSongsButton.Text = "Search";
this.SearchSongsButton.Click += new System.EventHandler(this.SearchSongsButton_Click);
//
// serverToolStripMenuItem
//
this.serverToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
@@ -790,27 +816,17 @@ namespace MusicPlayer
this.NotifyMenuStripPreviousButton.Text = "Previous";
this.NotifyMenuStripPreviousButton.Click += new System.EventHandler(this.NotifyMenuStripPreviousButton_Click);
//
// songsToolStripMenuItem
// AdvancedSearchButton
//
this.songsToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.SearchSongsTextBox,
this.SearchSongsButton});
this.songsToolStripMenuItem.Name = "songsToolStripMenuItem";
this.songsToolStripMenuItem.Size = new System.Drawing.Size(152, 22);
this.songsToolStripMenuItem.Text = "Songs";
this.AdvancedSearchButton.Name = "AdvancedSearchButton";
this.AdvancedSearchButton.Size = new System.Drawing.Size(152, 22);
this.AdvancedSearchButton.Text = "Advanced";
this.AdvancedSearchButton.Click += new System.EventHandler(this.AdvancedSearchButton_Click);
//
// SearchSongsTextBox
// toolStripSeparator7
//
this.SearchSongsTextBox.Name = "SearchSongsTextBox";
this.SearchSongsTextBox.Size = new System.Drawing.Size(100, 23);
//
// SearchSongsButton
//
this.SearchSongsButton.Enabled = false;
this.SearchSongsButton.Name = "SearchSongsButton";
this.SearchSongsButton.Size = new System.Drawing.Size(160, 22);
this.SearchSongsButton.Text = "Search";
this.SearchSongsButton.Click += new System.EventHandler(this.SearchSongsButton_Click);
this.toolStripSeparator7.Name = "toolStripSeparator7";
this.toolStripSeparator7.Size = new System.Drawing.Size(149, 6);
//
// MainForm
//
@@ -921,6 +937,8 @@ namespace MusicPlayer
private System.Windows.Forms.ToolStripMenuItem songsToolStripMenuItem;
private System.Windows.Forms.ToolStripTextBox SearchSongsTextBox;
private System.Windows.Forms.ToolStripMenuItem SearchSongsButton;
private System.Windows.Forms.ToolStripSeparator toolStripSeparator7;
private System.Windows.Forms.ToolStripMenuItem AdvancedSearchButton;
}
}
+6
View File
@@ -584,5 +584,11 @@ namespace MusicPlayer
SearchSongsTextBox.Text = "";
}
}
private void AdvancedSearchButton_Click(object sender, EventArgs e)
{
AdvancedSearch av = new AdvancedSearch(main);
av.ShowDialog();
}
}
}
@@ -77,6 +77,12 @@
<Compile Include="NetworkHandler.cs" />
<Compile Include="Playlist.cs" />
<Compile Include="PlaylistHandler.cs" />
<Compile Include="AdvancedSearch.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="AdvancedSearch.Designer.cs">
<DependentUpon>AdvancedSearch.cs</DependentUpon>
</Compile>
<Compile Include="PlaylistMaker.cs">
<SubType>Form</SubType>
</Compile>
@@ -94,6 +100,9 @@
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="AdvancedSearch.resx">
<DependentUpon>AdvancedSearch.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="PlaylistMaker.resx">
<DependentUpon>PlaylistMaker.cs</DependentUpon>
</EmbeddedResource>
+3 -2
View File
@@ -24,7 +24,6 @@ namespace MusicPlayer
public JObject SendString(string m)
{
string encodedstring = Microsoft.Security.Application.Encoder.HtmlEncode(m);
Console.WriteLine(encodedstring);
HttpWebRequest server = (HttpWebRequest)WebRequest.Create(ip+":"+port+"/"+encodedstring);
server.KeepAlive = false;
try {
@@ -63,7 +62,9 @@ namespace MusicPlayer
{
try
{
WebRequest req = WebRequest.Create((ip + "/music/.artwork/"+album).Replace(" ", "%20"));
string encodedstring = Microsoft.Security.Application.Encoder.HtmlEncode(ip + "/music/.artwork/" + album);
WebRequest req = WebRequest.Create(encodedstring);
//WebRequest req = WebRequest.Create((ip + "/music/.artwork/" + album).Replace(" ","%20"));
WebResponse response = req.GetResponse();
Stream stream = response.GetResponseStream();