private void addPlaylist_Click(object sender, EventArgs e) { OpenFileDialog selectFileDialog = new OpenFileDialog(); selectFileDialog.Filter = "Playlist Files|*.xspf;*.asx;*.wax;*.wvx;*.b4s;*.m3u;*.m3u8;*.pls;*.smil;*.smi;*.zpl;"; { if (selectFileDialog.ShowDialog() == DialogResult.OK) { IPlaylistIO theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(selectFileDialog.FileName); try { foreach (string s in theReader.FilePaths) { PlayerForm.AddQueue(s); } listBox1.Items.Clear(); PopulateList(); } catch (System.IO.DirectoryNotFoundException) { MessageBox.Show("This playlist file cannot be played because one or more of the songs could not be found.", "Songs not found", MessageBoxButtons.OK, MessageBoxIcon.Information); PlayerForm.ClearQueue(); } } } }
private async void BrowsePlaylistsButton_Click(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog(); dialog.Filter = "Playlist Files|*.xspf;*.asx;*.wax;*.wvx;*.b4s;*.m3u;*.m3u8;*.pls;*.smil;*.smi;*.zpl;"; if (dialog.ShowDialog() == true) { var paths = new List <string>(); IPlaylistIO reader = PlaylistIOFactory.GetInstance().GetPlaylistIO(dialog.FileName); foreach (string s in reader.FilePaths) { if (!File.Exists(s)) { window.NotificationHandler.Add(new Notification { ContentText = string.Format(Properties.Resources.NOTIFICATION_COULD_NOT_IMPORT_PLAYLIST, s), IsImportant = true, DisplayAsToast = true, Type = NotificationType.Failure }); continue; } } window.Player.Queue.Add(reader.FilePaths.ToArray()); await Task.Run(() => window.Library.Import(reader.FilePaths.ToArray())); window.Player.PlayMusic(); } }
private void AddPlaylist_Click(object sender, RoutedEventArgs e) { var dialog = new OpenFileDialog(); dialog.Filter = "Playlist Files|*.xspf;*.asx;*.wax;*.wvx;*.b4s;*.m3u;*.m3u8;*.pls;*.smil;*.smi;*.zpl;"; if (dialog.ShowDialog() == true) { IPlaylistIO reader = PlaylistIOFactory.GetInstance().GetPlaylistIO(dialog.FileName); foreach (string s in reader.FilePaths) { if (!File.Exists(s)) { window.NotificationHandler.Add(new Notification { ContentText = string.Format(Properties.Resources.NOTIFICATION_COULD_NOT_IMPORT_PLAYLIST, s), IsImportant = true, DisplayAsToast = true, Type = NotificationType.Failure }); continue; } window.Player.Queue.Add(s); } } }
private async void BrowsePlaylist() { using (OpenFileDialog selectFileDialog = new OpenFileDialog()) { selectFileDialog.Filter = "Playlist Files|*.xspf;*.asx;*.wax;*.wvx;*.b4s;*.m3u;*.m3u8;*.pls;*.smil;*.smi;*.zpl;"; { if (selectFileDialog.ShowDialog() == DialogResult.OK) { IPlaylistIO theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(selectFileDialog.FileName); try { if (AddTrackCheckBox.Checked) { DatabaseHandler.ImportSong(theReader.FilePaths); } foreach (string s in theReader.FilePaths) { Player.AddQueue(s); } LibraryNeedsUpdating = true; Player.PlayMusic(); await UpdateLibrary(); } catch (DirectoryNotFoundException) { MessageBox.Show("This playlist file cannot be played because one or more of the songs could not be found.", "Songs not found", MessageBoxButtons.OK, MessageBoxIcon.Information); Player.ClearQueue(); } } } } }
public void PLIO_R_FPL() { string testFileLocation = TestUtils.CopyFileAndReplace(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist.fpl", "$PATH", TestUtils.GetResourceLocationRoot(false)); try { IPlaylistIO theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); Assert.IsNotInstanceOfType(theReader, typeof(ATL.Playlist.IO.DummyIO)); Assert.AreEqual(4, theReader.FilePaths.Count); foreach (string s in theReader.FilePaths) { Assert.IsTrue(System.IO.File.Exists(s)); } foreach (Track t in theReader.Tracks) { Assert.IsTrue(t.Duration > 0); // Ensures the track has been parsed } } finally { if (Settings.DeleteAfterSuccess) { File.Delete(testFileLocation); } } }
public void PL_M3U() { IPlaylistIO theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_simple.m3u"); Assert.AreEqual(1, theReader.FilePaths.Count); foreach (string s in theReader.FilePaths) { Assert.IsTrue(System.IO.File.Exists(s)); } IList <KeyValuePair <string, string> > replacements = new List <KeyValuePair <string, string> >(); string resourceRoot = TestUtils.GetResourceLocationRoot(false); replacements.Add(new KeyValuePair <string, string>("$PATH", resourceRoot)); replacements.Add(new KeyValuePair <string, string>("$NODISK_PATH", resourceRoot.Substring(2, resourceRoot.Length - 2))); string testFileLocation = TestUtils.CopyFileAndReplace(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_fullPath.m3u", replacements); try { theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); Assert.AreEqual(3, theReader.FilePaths.Count); foreach (string s in theReader.FilePaths) { Assert.IsTrue(System.IO.File.Exists(s)); } } finally { File.Delete(testFileLocation); } }
public void PLIO_R_SMIL() { IList <KeyValuePair <string, string> > replacements = new List <KeyValuePair <string, string> >(); string resourceRoot = TestUtils.GetResourceLocationRoot(false); replacements.Add(new KeyValuePair <string, string>("$PATH", resourceRoot)); replacements.Add(new KeyValuePair <string, string>("$NODISK_PATH", resourceRoot.Substring(2, resourceRoot.Length - 2))); string testFileLocation = TestUtils.CopyFileAndReplace(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist.smil", replacements); try { IPlaylistIO theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); Assert.IsNotInstanceOfType(theReader, typeof(ATL.Playlist.IO.DummyIO)); Assert.AreEqual(3, theReader.FilePaths.Count); foreach (string s in theReader.FilePaths) { Assert.IsTrue(System.IO.File.Exists(s)); } foreach (Track t in theReader.Tracks) { Assert.IsTrue(t.Duration > 0); } } finally { File.Delete(testFileLocation); } }
public void PLIO_W_M3U_Simple() { IList <string> pathsToWrite = new List <string>(); pathsToWrite.Add("aaa.mp3"); pathsToWrite.Add("bbb.mp3"); bool defaultSetting = Settings.M3U_useExtendedFormat; string testFileLocation = TestUtils.CreateTempTestFile("test.m3u"); try { Settings.M3U_useExtendedFormat = false; IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); pls.FilePaths = pathsToWrite; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) using (StreamReader sr = new StreamReader(fs)) { Assert.AreEqual("aaa.mp3", sr.ReadLine()); Assert.AreEqual("bbb.mp3", sr.ReadLine()); Assert.IsTrue(sr.EndOfStream); } } finally { File.Delete(testFileLocation); Settings.M3U_useExtendedFormat = defaultSetting; } }
public void CS_ReadingPlaylist() { IPlaylistIO theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(playlistPath); foreach (string s in theReader.FilePaths) { System.Console.WriteLine(s); } }
public void PLIO_W_M3U_Simple() { IList <string> pathsToWrite = new List <string>(); pathsToWrite.Add("aaa.mp3"); pathsToWrite.Add("bbb.mp3"); bool defaultSetting = ATL.Settings.M3U_useExtendedFormat; string testFileLocation = TestUtils.CreateTempTestFile("test.m3u"); try { ATL.Settings.M3U_useExtendedFormat = false; IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); pls.FilePaths = pathsToWrite; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) { // Test if the default UTF-8 BOM has been written at the beginning of the file byte[] bom = new byte[3]; fs.Read(bom, 0, 3); Assert.IsTrue(StreamUtils.ArrEqualsArr(bom, PlaylistIO.BOM_UTF8)); fs.Seek(0, SeekOrigin.Begin); using (StreamReader sr = new StreamReader(fs)) { Assert.AreEqual("aaa.mp3", sr.ReadLine()); Assert.AreEqual("bbb.mp3", sr.ReadLine()); Assert.IsTrue(sr.EndOfStream); } } IList <string> filePaths = pls.FilePaths; Assert.AreEqual(2, filePaths.Count); Assert.IsTrue(filePaths[0].EndsWith(pathsToWrite[0])); Assert.IsTrue(filePaths[1].EndsWith(pathsToWrite[1])); } finally { if (Settings.DeleteAfterSuccess) { File.Delete(testFileLocation); } ATL.Settings.M3U_useExtendedFormat = defaultSetting; } }
private async void ExportFolderButton_Click(object sender, RoutedEventArgs e) { var count = window.Library.Read().Count; var result = MessageBox.Show($"{count * 5}MB - mp3, {count * 50}MB - flac, ok?", "FRESHMusicPlayer", MessageBoxButton.OKCancel, MessageBoxImage.Warning); if (result != MessageBoxResult.OK) { return; } var dialog = new WinForms.FolderBrowserDialog(); if (dialog.ShowDialog() != WinForms.DialogResult.OK) { return; } await Task.Run(() => { IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(Path.Combine(dialog.SelectedPath, "playlist.m3u8")); var newPaths = new List <string>(); int progress = 0; foreach (var file in window.Library.Read().Select(x => x.Path)) { var newPath = Path.Combine(dialog.SelectedPath, Path.GetFileName(file)); while (File.Exists(newPath)) { newPath = $"x{newPath}"; } File.Copy(file, newPath); progress++; newPaths.Add(newPath); Dispatcher.Invoke(() => ExportFolderSubheader.Text = $"{progress}/{count} - Copying {file}"); } Dispatcher.Invoke(() => ExportFolderSubheader.Text = $"Creating playlist files..."); pls.FilePaths = newPaths; foreach (var playlist in window.Library.Database.GetCollection <DatabasePlaylist>("playlists").Query().OrderBy("Name").ToList()) { var playlistFile = PlaylistIOFactory.GetInstance().GetPlaylistIO(Path.Combine(dialog.SelectedPath, "playlists", $"{playlist.DatabasePlaylistID}.m3u8")); playlistFile.FilePaths = playlist.Tracks; } Dispatcher.Invoke(() => ExportFolderSubheader.Text = $"Done!"); }); }
private void ExportButton_Click(object sender, RoutedEventArgs e) { var tracks = library.ReadTracksForPlaylist(playlist); var saveFileDialog = new SaveFileDialog(); saveFileDialog.Filter = "M3U UTF-8 Playlist|*.m3u8|Other|*"; if (saveFileDialog.ShowDialog() == true) { IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(saveFileDialog.FileName); IList <string> pathsToWrite = new List <string>(); foreach (var track in tracks) { pathsToWrite.Add(track.Path); } pls.FilePaths = pathsToWrite; } }
public void PLIO_R_M3U() { IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_simple.m3u"); Assert.IsNotInstanceOfType(pls, typeof(ATL.Playlist.IO.DummyIO)); Assert.AreEqual(1, pls.FilePaths.Count); foreach (string s in pls.FilePaths) { Assert.IsTrue(System.IO.File.Exists(s)); } foreach (Track t in pls.Tracks) { Assert.IsTrue(t.Duration > 0); // Ensures the track has been parsed } IList <KeyValuePair <string, string> > replacements = new List <KeyValuePair <string, string> >(); string resourceRoot = TestUtils.GetResourceLocationRoot(false); replacements.Add(new KeyValuePair <string, string>("$PATH", resourceRoot)); replacements.Add(new KeyValuePair <string, string>("$NODISK_PATH", resourceRoot.Substring(2, resourceRoot.Length - 2))); string testFileLocation = TestUtils.CopyFileAndReplace(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_fullPath.m3u", replacements); try { pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); Assert.IsNotInstanceOfType(pls, typeof(ATL.Playlist.IO.DummyIO)); Assert.AreEqual(3, pls.FilePaths.Count); foreach (string s in pls.FilePaths) { Assert.IsTrue(System.IO.File.Exists(s)); } foreach (Track t in pls.Tracks) { Assert.IsTrue(t.Duration > 0); // Ensures the track has been parsed } } finally { if (Settings.DeleteAfterSuccess) { File.Delete(testFileLocation); } } }
public void TestWritePls() { IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(playlistFilePath); // Writing file paths IList <string> pathsToWrite = new List <string>(); pathsToWrite.Add("aaa.mp3"); pathsToWrite.Add("bbb.mp3"); pls.FilePaths = pathsToWrite; // Writing tracks IList <Track> tracksToWrite = new List <Track>(); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MP3/empty.mp3")); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MOD/mod.mod")); pls.Tracks = tracksToWrite; }
public void PL_FPL() { string testFileLocation = TestUtils.CopyFileAndReplace(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist.fpl", "$PATH", TestUtils.GetResourceLocationRoot(false)); try { IPlaylistIO theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); Assert.AreEqual(4, theReader.FilePaths.Count); foreach (string s in theReader.FilePaths) { Assert.IsTrue(System.IO.File.Exists(s)); } } finally { File.Delete(testFileLocation); } }
public void PL_Common() { IPlaylistIO theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_simple.m3u"); Assert.AreEqual(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_simple.m3u", theReader.Path); ArrayLogger log = new ArrayLogger(); try { theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(TestUtils.GetResourceLocationRoot() + "_Playlists/efiufhziuefizeub.m3u"); IList <string> files = theReader.FilePaths; Assert.Fail(); } catch { IList <LogItem> logItems = log.GetAllItems(Log.LV_ERROR); Assert.AreEqual(1, logItems.Count); Assert.IsTrue(logItems[0].Message.Contains("efiufhziuefizeub.m3u")); // Can't do much more than than because the exception message is localized } }
public IPlaylistIO GetPlaylistIO(int formatId) { IPlaylistIO theReader = null; if (PL_M3U == formatId) { theReader = new M3UIO(); } else if (PL_PLS == formatId) { theReader = new PLSIO(); } else if (PL_FPL == formatId) { theReader = new FPLIO(); } else if (PL_XSPF == formatId) { theReader = new XSPFIO(); } else if (PL_SMIL == formatId) { theReader = new SMILIO(); } else if (PL_ASX == formatId) { theReader = new ASXIO(); } else if (PL_B4S == formatId) { theReader = new B4SIO(); } if (null == theReader) { theReader = new DummyIO(); } return(theReader); }
public void PLIO_R_XSPF() { string testFileLocation = TestUtils.CopyFileAndReplace(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist.xspf", "$PATH", TestUtils.GetResourceLocationRoot(false).Replace('\\', '/')); try { IPlaylistIO theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); Assert.IsNotInstanceOfType(theReader, typeof(ATL.Playlist.IO.DummyIO)); Assert.AreEqual(4, theReader.FilePaths.Count); foreach (string s in theReader.FilePaths) { Assert.IsTrue(System.IO.File.Exists(s)); } foreach (Track t in theReader.Tracks) { Assert.IsTrue(t.Duration > 0); } } finally { File.Delete(testFileLocation); } }
public void PLIO_R_PLS() { string testFileLocation = TestUtils.CopyFileAndReplace(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist.pls", "$PATH", TestUtils.GetResourceLocationRoot(false)); try { IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); Assert.IsNotInstanceOfType(pls, typeof(ATL.Playlist.IO.DummyIO)); Assert.AreEqual(3, pls.FilePaths.Count); foreach (string s in pls.FilePaths) { Assert.IsTrue(System.IO.File.Exists(s)); } foreach (Track t in pls.Tracks) { Assert.IsTrue(t.Duration > 0); // Ensures the track has been parsed } } finally { File.Delete(testFileLocation); } }
public void PLIO_W_PLS() { IList <string> pathsToWrite = new List <string>(); pathsToWrite.Add("aaa.mp3"); pathsToWrite.Add("bbb.mp3"); IList <Track> tracksToWrite = new List <Track>(); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MP3\\empty.mp3")); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MOD\\mod.mod")); string testFileLocation = TestUtils.CreateTempTestFile("test.pls"); try { IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); // Test Path writing pls.FilePaths = pathsToWrite; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) { // Test if the default UTF-8 BOM has been written at the beginning of the file byte[] bom = new byte[3]; fs.Read(bom, 0, 3); Assert.IsTrue(StreamUtils.ArrEqualsArr(bom, PlaylistIO.BOM_UTF8)); fs.Seek(0, SeekOrigin.Begin); using (StreamReader sr = new StreamReader(fs)) { Assert.AreEqual("[playlist]", sr.ReadLine()); sr.ReadLine(); Assert.AreEqual("File1=aaa.mp3", sr.ReadLine()); Assert.AreEqual("Title1=aaa", sr.ReadLine()); Assert.AreEqual("Length1=-1", sr.ReadLine()); sr.ReadLine(); Assert.AreEqual("File2=bbb.mp3", sr.ReadLine()); Assert.AreEqual("Title2=bbb", sr.ReadLine()); Assert.AreEqual("Length2=-1", sr.ReadLine()); sr.ReadLine(); Assert.AreEqual("NumberOfEntries=2", sr.ReadLine()); Assert.AreEqual("Version=2", sr.ReadLine()); Assert.IsTrue(sr.EndOfStream); } } IList <string> filePaths = pls.FilePaths; Assert.AreEqual(2, filePaths.Count); Assert.IsTrue(filePaths[0].EndsWith(pathsToWrite[0])); Assert.IsTrue(filePaths[1].EndsWith(pathsToWrite[1])); // Test Track writing pls.Tracks = tracksToWrite; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) using (StreamReader sr = new StreamReader(fs)) { Assert.AreEqual("[playlist]", sr.ReadLine()); int counter = 1; foreach (Track t in tracksToWrite) { sr.ReadLine(); Assert.AreEqual("File" + counter + "=" + t.Path, sr.ReadLine()); Assert.AreEqual("Title" + counter + "=" + t.Title, sr.ReadLine()); Assert.AreEqual("Length" + counter + "=" + t.Duration, sr.ReadLine()); counter++; } sr.ReadLine(); Assert.AreEqual("NumberOfEntries=2", sr.ReadLine()); Assert.AreEqual("Version=2", sr.ReadLine()); Assert.IsTrue(sr.EndOfStream); } IList <Track> tracks = pls.Tracks; Assert.AreEqual(2, tracks.Count); Assert.AreEqual(tracksToWrite[0].Path, tracks[0].Path); Assert.AreEqual(tracksToWrite[1].Path, tracks[1].Path); } finally { if (Settings.DeleteAfterSuccess) { File.Delete(testFileLocation); } } }
public void PLIO_W_ASX() { IList <string> pathsToWrite = new List <string>(); pathsToWrite.Add(TestUtils.GetResourceLocationRoot() + "aaa.mp3"); pathsToWrite.Add(TestUtils.GetResourceLocationRoot() + "bbb.mp3"); IList <Track> tracksToWrite = new List <Track>(); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MP3\\empty.mp3")); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MOD\\mod.mod")); string testFileLocation = TestUtils.CreateTempTestFile("test.asx"); try { IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); // Test Path writing pls.FilePaths = pathsToWrite; IList <string> parents = new List <string>(); int index = -1; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) { // Test if the default UTF-8 BOM has been written at the beginning of the file byte[] bom = new byte[3]; fs.Read(bom, 0, 3); Assert.IsTrue(StreamUtils.ArrEqualsArr(bom, PlaylistIO.BOM_UTF8)); fs.Seek(0, SeekOrigin.Begin); using (XmlReader source = XmlReader.Create(fs)) { // Read file content while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { if (source.Name.Equals("asx", StringComparison.OrdinalIgnoreCase)) { parents.Add(source.Name.ToLower()); } else if (source.Name.Equals("entry", StringComparison.OrdinalIgnoreCase) && parents.Contains("asx")) { index++; parents.Add(source.Name.ToLower()); } else if (source.Name.Equals("ref", StringComparison.OrdinalIgnoreCase) && parents.Contains("entry")) { Assert.AreEqual(pathsToWrite[index], source.GetAttribute("HREF")); } } } } } Assert.AreEqual(3, parents.Count); IList <string> filePaths = pls.FilePaths; Assert.AreEqual(2, filePaths.Count); Assert.AreEqual(pathsToWrite[0], filePaths[0]); Assert.AreEqual(pathsToWrite[1], filePaths[1]); // Test Track writing pls.Tracks = tracksToWrite; index = -1; parents.Clear(); using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) using (XmlReader source = XmlReader.Create(fs)) { while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { if (source.Name.Equals("asx", StringComparison.OrdinalIgnoreCase)) { parents.Add(source.Name.ToLower()); } else if (source.Name.Equals("entry", StringComparison.OrdinalIgnoreCase) && parents.Contains("asx")) { index++; parents.Add(source.Name.ToLower()); } else if (parents.Contains("entry")) { if (source.Name.Equals("ref", StringComparison.OrdinalIgnoreCase)) { Assert.AreEqual(tracksToWrite[index].Path, source.GetAttribute("HREF")); } else if (source.Name.Equals("title", StringComparison.OrdinalIgnoreCase)) { Assert.AreEqual(tracksToWrite[index].Title, getXmlValue(source)); } else if (source.Name.Equals("author", StringComparison.OrdinalIgnoreCase)) { Assert.AreEqual(tracksToWrite[index].Artist, getXmlValue(source)); } } } } } Assert.AreEqual(3, parents.Count); IList <Track> tracks = pls.Tracks; Assert.AreEqual(2, tracks.Count); Assert.AreEqual(tracksToWrite[0].Path, tracks[0].Path); Assert.AreEqual(tracksToWrite[1].Path, tracks[1].Path); } finally { if (Settings.DeleteAfterSuccess) { File.Delete(testFileLocation); } } }
public void PLIO_W_SMIL() { IList <string> pathsToWrite = new List <string>(); pathsToWrite.Add("aaa.mp3"); pathsToWrite.Add("bbb.mp3"); IList <Track> tracksToWrite = new List <Track>(); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MP3/empty.mp3")); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MOD/mod.mod")); string testFileLocation = TestUtils.CreateTempTestFile("test.smil"); try { IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); // Test Path writing pls.FilePaths = pathsToWrite; IList <string> parents = new List <string>(); int index = -1; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) using (XmlReader source = XmlReader.Create(fs)) { while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { if (source.Name.Equals("smil", StringComparison.OrdinalIgnoreCase)) { parents.Add(source.Name); } else if (source.Name.Equals("body", StringComparison.OrdinalIgnoreCase) && parents.Contains("smil")) { parents.Add(source.Name); } else if (source.Name.Equals("seq", StringComparison.OrdinalIgnoreCase) && parents.Contains("body")) { parents.Add(source.Name); } else if (source.Name.Equals("media", StringComparison.OrdinalIgnoreCase) && parents.Contains("seq")) { index++; Assert.AreEqual(pathsToWrite[index], source.GetAttribute("src")); } } } } Assert.AreEqual(3, parents.Count); // Test Track writing pls.Tracks = tracksToWrite; parents.Clear(); index = -1; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) using (XmlReader source = XmlReader.Create(fs)) { while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { if (source.Name.Equals("smil", StringComparison.OrdinalIgnoreCase)) { parents.Add(source.Name); } else if (source.Name.Equals("body", StringComparison.OrdinalIgnoreCase) && parents.Contains("smil")) { parents.Add(source.Name); } else if (source.Name.Equals("seq", StringComparison.OrdinalIgnoreCase) && parents.Contains("body")) { parents.Add(source.Name); } else if (source.Name.Equals("media", StringComparison.OrdinalIgnoreCase) && parents.Contains("seq")) { index++; Assert.AreEqual(tracksToWrite[index].Path.Replace('\\', '/'), source.GetAttribute("src")); } } } } Assert.AreEqual(3, parents.Count); } finally { File.Delete(testFileLocation); } }
public void PLIO_W_M3U_Extended() { bool defaultSetting = Settings.M3U_useExtendedFormat; IList <string> pathsToWrite = new List <string>(); pathsToWrite.Add("aaa.mp3"); pathsToWrite.Add("bbb.mp3"); IList <Track> tracksToWrite = new List <Track>(); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MP3\\empty.mp3")); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MOD\\mod.mod")); string testFileLocation = TestUtils.CreateTempTestFile("test.m3u"); try { Settings.M3U_useExtendedFormat = true; IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); // Test Path writing pls.FilePaths = pathsToWrite; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) using (StreamReader sr = new StreamReader(fs)) { Assert.AreEqual("#EXTM3U", sr.ReadLine()); Assert.AreEqual("#EXTINF:-1,aaa", sr.ReadLine()); Assert.AreEqual("aaa.mp3", sr.ReadLine()); Assert.AreEqual("#EXTINF:-1,bbb", sr.ReadLine()); Assert.AreEqual("bbb.mp3", sr.ReadLine()); Assert.IsTrue(sr.EndOfStream); } IList <string> filePaths = pls.FilePaths; Assert.AreEqual(2, filePaths.Count); Assert.IsTrue(filePaths[0].EndsWith(pathsToWrite[0])); Assert.IsTrue(filePaths[1].EndsWith(pathsToWrite[1])); // Test Track writing pls.Tracks = tracksToWrite; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) using (StreamReader sr = new StreamReader(fs)) { Assert.AreEqual("#EXTM3U", sr.ReadLine()); foreach (Track t in tracksToWrite) { string line = "#EXTINF:" + t.Duration + ","; if (t.Artist != null && t.Artist.Length > 0) { line += t.Artist + " - "; } line += t.Title; Assert.AreEqual(line, sr.ReadLine()); Assert.AreEqual(t.Path, sr.ReadLine()); } Assert.IsTrue(sr.EndOfStream); } IList <Track> tracks = pls.Tracks; Assert.AreEqual(2, tracks.Count); Assert.AreEqual(tracksToWrite[0].Path, tracks[0].Path); Assert.AreEqual(tracksToWrite[1].Path, tracks[1].Path); } finally { File.Delete(testFileLocation); Settings.M3U_useExtendedFormat = defaultSetting; } }
public void PLIO_W_SMIL() { IList <string> pathsToWrite = new List <string>(); pathsToWrite.Add("aaa.mp3"); pathsToWrite.Add("bbb.mp3"); IList <Track> tracksToWrite = new List <Track>(); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MP3\\empty.mp3")); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MOD\\mod.mod")); string testFileLocation = TestUtils.CreateTempTestFile("test.smil"); try { IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); // Test Path writing pls.FilePaths = pathsToWrite; IList <string> parents = new List <string>(); int index = -1; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) { // Test if the default UTF-8 BOM has been written at the beginning of the file byte[] bom = new byte[3]; fs.Read(bom, 0, 3); Assert.IsTrue(StreamUtils.ArrEqualsArr(bom, PlaylistIO.BOM_UTF8)); fs.Seek(0, SeekOrigin.Begin); using (XmlReader source = XmlReader.Create(fs)) { while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { if (source.Name.Equals("smil", StringComparison.OrdinalIgnoreCase)) { parents.Add(source.Name); } else if (source.Name.Equals("body", StringComparison.OrdinalIgnoreCase) && parents.Contains("smil")) { parents.Add(source.Name); } else if (source.Name.Equals("seq", StringComparison.OrdinalIgnoreCase) && parents.Contains("body")) { parents.Add(source.Name); } else if (source.Name.Equals("media", StringComparison.OrdinalIgnoreCase) && parents.Contains("seq")) { index++; Assert.AreEqual(pathsToWrite[index], source.GetAttribute("src")); } } } } } Assert.AreEqual(3, parents.Count); IList <string> filePaths = pls.FilePaths; Assert.AreEqual(2, filePaths.Count); Assert.IsTrue(filePaths[0].EndsWith(pathsToWrite[0])); Assert.IsTrue(filePaths[1].EndsWith(pathsToWrite[1])); // Test Track writing pls.Tracks = tracksToWrite; parents.Clear(); index = -1; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) using (XmlReader source = XmlReader.Create(fs)) { while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { if (source.Name.Equals("smil", StringComparison.OrdinalIgnoreCase)) { parents.Add(source.Name); } else if (source.Name.Equals("body", StringComparison.OrdinalIgnoreCase) && parents.Contains("smil")) { parents.Add(source.Name); } else if (source.Name.Equals("seq", StringComparison.OrdinalIgnoreCase) && parents.Contains("body")) { parents.Add(source.Name); } else if (source.Name.Equals("media", StringComparison.OrdinalIgnoreCase) && parents.Contains("seq")) { index++; Assert.AreEqual("file:///" + tracksToWrite[index].Path.Replace('\\', '/'), source.GetAttribute("src")); } } } } Assert.AreEqual(3, parents.Count); IList <Track> tracks = pls.Tracks; Assert.AreEqual(2, tracks.Count); Assert.AreEqual(tracksToWrite[0].Path, tracks[0].Path); Assert.AreEqual(tracksToWrite[1].Path, tracks[1].Path); } finally { if (Settings.DeleteAfterSuccess) { File.Delete(testFileLocation); } } }
public void PLIO_W_PLS() { IList <string> pathsToWrite = new List <string>(); pathsToWrite.Add("aaa.mp3"); pathsToWrite.Add("bbb.mp3"); IList <Track> tracksToWrite = new List <Track>(); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MP3/empty.mp3")); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MOD/mod.mod")); string testFileLocation = TestUtils.CreateTempTestFile("test.pls"); try { IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); // Test Path writing pls.FilePaths = pathsToWrite; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) using (StreamReader sr = new StreamReader(fs)) { Assert.AreEqual("[playlist]", sr.ReadLine()); sr.ReadLine(); Assert.AreEqual("File1=aaa.mp3", sr.ReadLine()); Assert.AreEqual("Title1=aaa", sr.ReadLine()); Assert.AreEqual("Length1=-1", sr.ReadLine()); sr.ReadLine(); Assert.AreEqual("File2=bbb.mp3", sr.ReadLine()); Assert.AreEqual("Title2=bbb", sr.ReadLine()); Assert.AreEqual("Length2=-1", sr.ReadLine()); sr.ReadLine(); Assert.AreEqual("NumberOfEntries=2", sr.ReadLine()); Assert.AreEqual("Version=2", sr.ReadLine()); Assert.IsTrue(sr.EndOfStream); } // Test Track writing pls.Tracks = tracksToWrite; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) using (StreamReader sr = new StreamReader(fs)) { Assert.AreEqual("[playlist]", sr.ReadLine()); int counter = 1; foreach (Track t in tracksToWrite) { sr.ReadLine(); Assert.AreEqual("File" + counter + "=" + t.Path, sr.ReadLine()); Assert.AreEqual("Title" + counter + "=" + t.Title, sr.ReadLine()); Assert.AreEqual("Length" + counter + "=" + t.Duration, sr.ReadLine()); counter++; } sr.ReadLine(); Assert.AreEqual("NumberOfEntries=2", sr.ReadLine()); Assert.AreEqual("Version=2", sr.ReadLine()); Assert.IsTrue(sr.EndOfStream); } } finally { File.Delete(testFileLocation); } }
public void PLIO_W_B4S() { IList <string> pathsToWrite = new List <string>(); pathsToWrite.Add("aaa.mp3"); pathsToWrite.Add("bbb.mp3"); IList <Track> tracksToWrite = new List <Track>(); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MP3\\empty.mp3")); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MOD\\mod.mod")); string testFileLocation = TestUtils.CreateTempTestFile("test.b4s"); try { IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); // Test Path writing pls.FilePaths = pathsToWrite; IList <string> parents = new List <string>(); int index = -1; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) { // Test if _no_ UTF-8 BOM has been written at the beginning of the file byte[] bom = new byte[3]; fs.Read(bom, 0, 3); Assert.IsFalse(StreamUtils.ArrEqualsArr(bom, PlaylistIO.BOM_UTF8)); fs.Seek(0, SeekOrigin.Begin); using (XmlReader source = XmlReader.Create(fs)) { while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { if (source.Name.Equals("WinampXML", StringComparison.OrdinalIgnoreCase)) { parents.Add(source.Name); } else if (source.Name.Equals("playlist", StringComparison.OrdinalIgnoreCase) && parents.Contains("WinampXML")) { parents.Add(source.Name); } else if (source.Name.Equals("entry", StringComparison.OrdinalIgnoreCase) && parents.Contains("playlist")) { parents.Add(source.Name); index++; Assert.AreEqual(pathsToWrite[index], source.GetAttribute("Playstring")); } } } } } Assert.AreEqual(4, parents.Count); IList <string> filePaths = pls.FilePaths; Assert.AreEqual(2, filePaths.Count); Assert.IsTrue(filePaths[0].EndsWith(pathsToWrite[0])); Assert.IsTrue(filePaths[1].EndsWith(pathsToWrite[1])); // Test Track writing pls.Tracks = tracksToWrite; index = -1; parents.Clear(); using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) using (XmlReader source = XmlReader.Create(fs)) { while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { if (source.Name.Equals("WinampXML", StringComparison.OrdinalIgnoreCase)) { parents.Add(source.Name); } else if (source.Name.Equals("playlist", StringComparison.OrdinalIgnoreCase) && parents.Contains("WinampXML")) { parents.Add(source.Name); } else if (source.Name.Equals("entry", StringComparison.OrdinalIgnoreCase) && parents.Contains("playlist")) { parents.Add(source.Name); index++; Assert.IsTrue(source.GetAttribute("Playstring").EndsWith(tracksToWrite[index].Path.Replace('\\', '/'))); } else if (parents.Contains("entry")) { if (source.Name.Equals("Name", StringComparison.OrdinalIgnoreCase)) { Assert.AreEqual(tracksToWrite[index].Title, getXmlValue(source)); } else if (source.Name.Equals("Length", StringComparison.OrdinalIgnoreCase)) { Assert.AreEqual(((long)Math.Round(tracksToWrite[index].DurationMs)).ToString(), getXmlValue(source)); } } } } } Assert.AreEqual(4, parents.Count); IList <Track> tracks = pls.Tracks; Assert.AreEqual(2, tracks.Count); Assert.AreEqual(tracksToWrite[0].Path, tracks[0].Path); Assert.AreEqual(tracksToWrite[1].Path, tracks[1].Path); } finally { if (Settings.DeleteAfterSuccess) { File.Delete(testFileLocation); } } }
public void PLIO_R_NoFormat() { IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_simple.xyz"); Assert.IsInstanceOfType(pls, typeof(ATL.Playlist.IO.DummyIO)); }
public PlaylistDatabase(IPlaylistIO io) { this.io = io; Reload(); }
public PlaylistIOAdapter(IPlaylistIO pls) { this.pls = pls; }
public void PLIO_W_XSPF() { IList <string> pathsToWrite = new List <string>(); pathsToWrite.Add(TestUtils.GetResourceLocationRoot() + "aaa.mp3"); pathsToWrite.Add(TestUtils.GetResourceLocationRoot() + "bbb.mp3"); IList <Track> tracksToWrite = new List <Track>(); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MP3\\empty.mp3")); tracksToWrite.Add(new Track(TestUtils.GetResourceLocationRoot() + "MOD\\mod.mod")); string testFileLocation = TestUtils.CreateTempTestFile("test.xspf"); try { IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(testFileLocation); // Test Path writing pls.FilePaths = pathsToWrite; IList <string> parents = new List <string>(); int index = -1; using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) { // Test if the default UTF-8 BOM has been written at the beginning of the file byte[] bom = new byte[3]; fs.Read(bom, 0, 3); Assert.IsTrue(StreamUtils.ArrEqualsArr(bom, PlaylistIO.BOM_UTF8)); fs.Seek(0, SeekOrigin.Begin); using (XmlReader source = XmlReader.Create(fs)) { while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { if (source.Name.Equals("playlist", StringComparison.OrdinalIgnoreCase)) { parents.Add(source.Name); } else if (source.Name.Equals("tracklist", StringComparison.OrdinalIgnoreCase) && parents.Contains("playlist")) { parents.Add(source.Name); } else if (source.Name.Equals("track", StringComparison.OrdinalIgnoreCase) && parents.Contains("trackList")) { parents.Add(source.Name); index++; } else if (source.Name.Equals("location", StringComparison.OrdinalIgnoreCase) && parents.Contains("track")) { Assert.AreEqual(pathsToWrite[index], getXmlValue(source).Replace('/', '\\')); } } } } } Assert.AreEqual(4, parents.Count); IList <string> filePaths = pls.FilePaths; Assert.AreEqual(2, filePaths.Count); Assert.IsTrue(filePaths[0].EndsWith(pathsToWrite[0])); Assert.IsTrue(filePaths[1].EndsWith(pathsToWrite[1])); // Test Track writing pls.Tracks = tracksToWrite; index = -1; parents.Clear(); using (FileStream fs = new FileStream(testFileLocation, FileMode.Open)) using (XmlReader source = XmlReader.Create(fs)) { while (source.Read()) { if (source.NodeType == XmlNodeType.Element) { if (source.Name.Equals("playlist", StringComparison.OrdinalIgnoreCase)) { parents.Add(source.Name); } else if (source.Name.Equals("trackList", StringComparison.OrdinalIgnoreCase) && parents.Contains("playlist")) { parents.Add(source.Name); } else if (source.Name.Equals("track", StringComparison.OrdinalIgnoreCase) && parents.Contains("trackList")) { parents.Add(source.Name); index++; } else if (parents.Contains("track")) { if (source.Name.Equals("location", StringComparison.OrdinalIgnoreCase)) { Assert.AreEqual(getXmlValue(source), tracksToWrite[index].Path); } else if (source.Name.Equals("title", StringComparison.OrdinalIgnoreCase)) { Assert.AreEqual(getXmlValue(source), tracksToWrite[index].Title); } else if (source.Name.Equals("creator", StringComparison.OrdinalIgnoreCase)) { Assert.AreEqual(getXmlValue(source), tracksToWrite[index].Artist); } else if (source.Name.Equals("album", StringComparison.OrdinalIgnoreCase)) { Assert.AreEqual(getXmlValue(source), tracksToWrite[index].Album); } else if (source.Name.Equals("annotation", StringComparison.OrdinalIgnoreCase)) { Assert.AreEqual(getXmlValue(source), tracksToWrite[index].Comment); } else if (source.Name.Equals("trackNum", StringComparison.OrdinalIgnoreCase)) { Assert.AreEqual(getXmlValue(source), tracksToWrite[index].TrackNumber); } else if (source.Name.Equals("duration", StringComparison.OrdinalIgnoreCase)) { Assert.AreEqual(getXmlValue(source), ((long)Math.Round(tracksToWrite[index].DurationMs)).ToString()); } } } } } Assert.AreEqual(4, parents.Count); IList <Track> tracks = pls.Tracks; Assert.AreEqual(2, tracks.Count); Assert.AreEqual(tracksToWrite[0].Path, tracks[0].Path); Assert.AreEqual(tracksToWrite[1].Path, tracks[1].Path); } finally { File.Delete(testFileLocation); } }