public int CompareTo(object o) { SongMusicItem other = o as SongMusicItem; if (album.CompareTo(other.Album) == 0) { return(id - other.Id); } return(album.CompareTo(other.Album)); }
public static List <SongMusicItem> search(string query) //queries should be in the form <field>:\"<name>\" { List <SongMusicItem> songs = new List <SongMusicItem>(); string line; string[] data; string[] delimarr = new string[] { "| ", }; SongMusicItem song; try{ System.Diagnostics.Process getLib; getLib = new System.Diagnostics.Process(); getLib.StartInfo.FileName = "xmms2"; getLib.StartInfo.Arguments = string.Format("mlib search {0}", query); getLib.StartInfo.RedirectStandardOutput = true; getLib.StartInfo.UseShellExecute = false; getLib.Start(); getLib.StandardOutput.ReadLine(); //get rid of extraneous getLib.StandardOutput.ReadLine(); //lines at the top while (null != (line = getLib.StandardOutput.ReadLine())) { if (line.Substring(0, 1) != "-") { data = line.Split(delimarr, StringSplitOptions.RemoveEmptyEntries); int id = int.Parse(data[0]); for (int i = 1; i <= 3; i++) { data[i] = Regex.Replace(data[i], " +$", ""); //keeps formatting right, also ensures searches actually work! } song = new SongMusicItem(id, data[1], data[2], data[3]); songs.Add(song); } } } catch (Exception e) { Console.Error.WriteLine("xmms2 mlib search failed: " + e.Message + " query was " + query); } return(songs); }
public static List <SongMusicItem> LoadSongsFor(PlaylistItem list) { string line; string[] delimarr = new string[] { " - ", }; string[] data; int id; SongMusicItem entry; List <SongMusicItem> entries = new List <SongMusicItem>(); System.Diagnostics.Process getList; getList = new System.Diagnostics.Process(); getList.StartInfo.FileName = "xmms2"; getList.StartInfo.Arguments = string.Format("list {0}", list.Name); //Warning: does not guard against improperly formatted queries getList.StartInfo.RedirectStandardOutput = true; getList.StartInfo.UseShellExecute = false; getList.Start(); while (null != (line = getList.StandardOutput.ReadLine())) { try{ if (line.Substring(2, 1) == "[") { line = Regex.Replace(line, "..\\[.+?\\/", ""); //clears out beginning of line format line = Regex.Replace(line, "\\]", " -"); //clears the other ] data = line.Split(delimarr, StringSplitOptions.None); id = int.Parse(data[0]); data[2] = Regex.Replace(data[2], "[^\\w\\s\\d].+$", ""); entry = new SongMusicItem(id, data[1], "", data[2]); //blank album to match default output. phooey. entries.Add(entry); } }catch (Exception e) { Console.Error.WriteLine("failed to load playlist: " + e.Message + " at " + line); } } return(entries); }