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();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        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);
                }
            }
        }
Ejemplo n.º 4
0
 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();
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
        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);
            }
        }
Ejemplo n.º 6
0
        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);
                }
            }
        }
Ejemplo n.º 7
0
        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);
            }
        }
Ejemplo n.º 8
0
        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;
            }
        }
Ejemplo n.º 9
0
        public void CS_ReadingPlaylist()
        {
            IPlaylistIO theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(playlistPath);

            foreach (string s in theReader.FilePaths)
            {
                System.Console.WriteLine(s);
            }
        }
Ejemplo n.º 10
0
        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;
            }
        }
Ejemplo n.º 11
0
        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!");
            });
        }
Ejemplo n.º 12
0
        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;
            }
        }
Ejemplo n.º 13
0
        public void CS_ListingSupportedFormats()
        {
            System.Text.StringBuilder filter = new System.Text.StringBuilder("");

            foreach (Format f in PlaylistIOFactory.GetInstance().getFormats())
            {
                if (f.Readable)
                {
                    foreach (string extension in f)
                    {
                        filter.Append(extension).Append(";");
                    }
                }
            }
            // Removes the last separator
            filter.Remove(filter.Length - 1, 1);
        }
Ejemplo n.º 14
0
        public async void BrowsePlaylistsCommand()
        {
            string[] acceptableFiles = { "xspf", "asx", "wvx", "b4s", "m3u", "m3u8", "pls", "smil", "smi", "zpl" };
            var      dialog          = new OpenFileDialogEx()
            {
                Filters = new[]
                {
                    new FileDialogFilter()
                    {
                        Name       = Resources.FileFilter_PlaylistFiles,
                        Extensions = acceptableFiles.ToList()
                    }
                },
                WindowTitle       = Resources.ImportPlaylistFiles,
                AcceptButtonLabel = Resources.ImportPlaylistFiles
            };
            var files = await dialog.ShowAsync(GetMainWindow());

            if (files.Length <= 0 && files is null)
            {
                return;
            }

            var reader = PlaylistIOFactory.GetInstance().GetPlaylistIO(files[0]);

            foreach (var s in reader.FilePaths)
            {
                if (!File.Exists(s))
                {
                    Window.Notifications.Add(new()
                    {
                        ContentText = string.Format(Properties.Resources.Notification_FileInPlaylistMissing,
                                                    Path.GetFileName(s)),
                        DisplayAsToast = true,
                        IsImportant    = true,
                        Type           = NotificationType.Failure
                    });
                    continue;
                }
            }

            Window.Player.Queue.Add(reader.FilePaths.ToArray());
            await Task.Run(() => Window.Library.Import(reader.FilePaths.ToArray()));

            await Window.Player.PlayAsync();
        }
Ejemplo n.º 15
0
        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);
                }
            }
        }
Ejemplo n.º 16
0
        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;
        }
Ejemplo n.º 17
0
        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);
            }
        }
Ejemplo n.º 18
0
        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
            }
        }
Ejemplo n.º 19
0
        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);
            }
        }
Ejemplo n.º 20
0
        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);
            }
        }
Ejemplo n.º 21
0
 public IPlaylistReader GetPlaylistReader(string path, int alternate = 0)
 {
     return(new PlaylistIOAdapter(PlaylistIOFactory.GetInstance().GetPlaylistIO(path)));
 }
Ejemplo n.º 22
0
        private void Button1_Click(object sender, EventArgs e)
        {
            loc = textBox1.Text;
            listBox2.Items.Clear();
            switch (comboBox3.SelectedIndex)
            {
            case 0:
            {
                if (comboBox4.SelectedIndex == -1)
                {
                    asx1 = ".asx";
                }
                switch (comboBox1.SelectedIndex)
                {
                case 0:
                {
                    switch (comboBox2.SelectedIndex)
                    {
                    case 0:
                    {
                        var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFBOM" + asx1, PlaylistFormat.LocationFormatting.FilePath, PlaylistFormat.FileEncoding.UTF8_BOM);
                        IList <string> pathsToWrite = new List <string>();
                        foreach (var item in listBox1.Items)
                        {
                            pathsToWrite.Add(item.ToString());
                        }
                        pls.FilePaths = pathsToWrite;
                        var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFBOM" + asx1);
                        foreach (var s in theReader.FilePaths)
                        {
                            listBox2.Items.Add(s);
                        }

                        break;
                    }

                    case 1:
                    {
                        var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFNoBOM" + asx1, PlaylistFormat.LocationFormatting.FilePath, PlaylistFormat.FileEncoding.UTF8_NO_BOM);
                        IList <string> pathsToWrite = new List <string>();
                        foreach (var item in listBox1.Items)
                        {
                            pathsToWrite.Add(item.ToString());
                        }
                        pls.FilePaths = pathsToWrite;
                        var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFNoBOM" + asx1);
                        foreach (var s in theReader.FilePaths)
                        {
                            listBox2.Items.Add(s);
                        }

                        break;
                    }
                    }

                    break;
                }

                case 1:
                {
                    var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "MSURI" + asx1, PlaylistFormat.LocationFormatting.MS_URI);
                    IList <string> pathsToWrite = new List <string>();
                    foreach (var item in listBox1.Items)
                    {
                        pathsToWrite.Add(item.ToString());
                    }
                    pls.FilePaths = pathsToWrite;
                    var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "MSURI" + asx1);
                    foreach (var s in theReader.FilePaths)
                    {
                        listBox2.Items.Add(s);
                    }
                    break;
                }

                case 2:
                {
                    var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "RFCURI" + asx1, PlaylistFormat.LocationFormatting.RFC_URI);
                    IList <string> pathsToWrite = new List <string>();
                    foreach (var item in listBox1.Items)
                    {
                        pathsToWrite.Add(item.ToString());
                    }
                    pls.FilePaths = pathsToWrite;
                    var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "RFCURI" + asx1);
                    foreach (var s in theReader.FilePaths)
                    {
                        listBox2.Items.Add(s);
                    }
                    break;
                }
                }
                return;
            }

            case 1:
            {
                listBox2.Items.Clear();
                switch (comboBox1.SelectedIndex)
                {
                case 2:
                {
                    var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "RFCURI.b4s", PlaylistFormat.LocationFormatting.RFC_URI, PlaylistFormat.FileEncoding.UTF8_NO_BOM);
                    IList <string> pathsToWrite = new List <string>();
                    foreach (var item in listBox1.Items)
                    {
                        pathsToWrite.Add(item.ToString());
                    }
                    pls.FilePaths = pathsToWrite;
                    var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "RFCURI.b4s");
                    foreach (var s in theReader.FilePaths)
                    {
                        listBox2.Items.Add(s);
                    }
                    break;
                }

                case 3:
                {
                    var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "WinampURI.b4s", PlaylistFormat.LocationFormatting.Winamp_URI);
                    IList <string> pathsToWrite = new List <string>();
                    foreach (var item in listBox1.Items)
                    {
                        pathsToWrite.Add(item.ToString());
                    }
                    pls.FilePaths = pathsToWrite;
                    var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "WinampURI.b4s");
                    foreach (var s in theReader.FilePaths)
                    {
                        listBox2.Items.Add(s);
                    }
                    break;
                }
                }


                return;
            }

            case 2:
            {
                listBox2.Items.Clear();
                if (comboBox1.SelectedIndex == 0)
                {
                    switch (comboBox2.SelectedIndex)
                    {
                    case 0:
                    {
                        var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFBOM.m3u", PlaylistFormat.LocationFormatting.FilePath, PlaylistFormat.FileEncoding.UTF8_BOM);
                        IList <string> pathsToWrite = new List <string>();
                        foreach (var item in listBox1.Items)
                        {
                            pathsToWrite.Add(item.ToString());
                        }
                        pls.FilePaths = pathsToWrite;
                        var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFBOM.m3u");
                        foreach (var s in theReader.FilePaths)
                        {
                            listBox2.Items.Add(s);
                        }

                        break;
                    }

                    case 1:
                    {
                        var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFNoBOM.m3u", PlaylistFormat.LocationFormatting.FilePath, PlaylistFormat.FileEncoding.UTF8_NO_BOM);
                        IList <string> pathsToWrite = new List <string>();
                        foreach (var item in listBox1.Items)
                        {
                            pathsToWrite.Add(item.ToString());
                        }
                        pls.FilePaths = pathsToWrite;
                        var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFNoBOM.m3u");
                        foreach (var s in theReader.FilePaths)
                        {
                            listBox2.Items.Add(s);
                        }

                        break;
                    }
                    }

                    break;
                }
                return;
            }

            case 3:
            {
                listBox2.Items.Clear();
                switch (comboBox2.SelectedIndex)
                {
                case 0:
                {
                    var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFBOM.m3u8", PlaylistFormat.LocationFormatting.FilePath, PlaylistFormat.FileEncoding.UTF8_BOM);
                    IList <string> pathsToWrite = new List <string>();
                    foreach (var item in listBox1.Items)
                    {
                        pathsToWrite.Add(item.ToString());
                    }
                    pls.FilePaths = pathsToWrite;
                    var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFBOM.m3u8");
                    foreach (var s in theReader.FilePaths)
                    {
                        listBox2.Items.Add(s);
                    }

                    break;
                }

                case 1:
                {
                    var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFNoBOM.m3u8", PlaylistFormat.LocationFormatting.FilePath, PlaylistFormat.FileEncoding.UTF8_NO_BOM);
                    IList <string> pathsToWrite = new List <string>();
                    foreach (var item in listBox1.Items)
                    {
                        pathsToWrite.Add(item.ToString());
                    }
                    pls.FilePaths = pathsToWrite;
                    var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFNoBOM.m3u8");
                    foreach (var s in theReader.FilePaths)
                    {
                        listBox2.Items.Add(s);
                    }

                    break;
                }
                }
                return;
            }

            case 4:
            {
                listBox2.Items.Clear();
                if (comboBox1.SelectedIndex == 0)
                {
                    switch (comboBox2.SelectedIndex)
                    {
                    case 0:
                    {
                        var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFBOM.pls", PlaylistFormat.LocationFormatting.FilePath, PlaylistFormat.FileEncoding.UTF8_BOM);
                        IList <string> pathsToWrite = new List <string>();
                        foreach (var item in listBox1.Items)
                        {
                            pathsToWrite.Add(item.ToString());
                        }
                        pls.FilePaths = pathsToWrite;
                        var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFBOM.pls");
                        foreach (var s in theReader.FilePaths)
                        {
                            listBox2.Items.Add(s);
                        }

                        break;
                    }

                    case 1:
                    {
                        var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFNoBOM.pls", PlaylistFormat.LocationFormatting.FilePath, PlaylistFormat.FileEncoding.UTF8_NO_BOM);
                        IList <string> pathsToWrite = new List <string>();
                        foreach (var item in listBox1.Items)
                        {
                            pathsToWrite.Add(item.ToString());
                        }
                        pls.FilePaths = pathsToWrite;
                        var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFNoBOM.pls");
                        foreach (var s in theReader.FilePaths)
                        {
                            listBox2.Items.Add(s);
                        }

                        break;
                    }
                    }
                    break;
                }
                return;
            }

            case 5:
            {
                listBox2.Items.Clear();
                switch (comboBox1.SelectedIndex)
                {
                case 0:
                {
                    switch (comboBox2.SelectedIndex)
                    {
                    case 0:
                    {
                        var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFBOM.xspf", PlaylistFormat.LocationFormatting.FilePath, PlaylistFormat.FileEncoding.UTF8_BOM);
                        IList <string> pathsToWrite = new List <string>();
                        foreach (var item in listBox1.Items)
                        {
                            pathsToWrite.Add(item.ToString());
                        }
                        pls.FilePaths = pathsToWrite;
                        var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFBOM.xspf");
                        foreach (var s in theReader.FilePaths)
                        {
                            listBox2.Items.Add(s);
                        }

                        break;
                    }

                    case 1:
                    {
                        var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFNoBOM.xspf", PlaylistFormat.LocationFormatting.FilePath, PlaylistFormat.FileEncoding.UTF8_NO_BOM);
                        IList <string> pathsToWrite = new List <string>();
                        foreach (var item in listBox1.Items)
                        {
                            pathsToWrite.Add(item.ToString());
                        }
                        pls.FilePaths = pathsToWrite;
                        var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "FilepathUTFNoBOM.xspf");
                        foreach (var s in theReader.FilePaths)
                        {
                            listBox2.Items.Add(s);
                        }

                        break;
                    }
                    }
                    break;
                }

                case 2:
                {
                    var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "RFCURI.xspf", PlaylistFormat.LocationFormatting.RFC_URI);
                    IList <string> pathsToWrite = new List <string>();
                    foreach (var item in listBox1.Items)
                    {
                        pathsToWrite.Add(item.ToString());
                    }
                    pls.FilePaths = pathsToWrite;
                    var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "RFCURI.xspf");
                    foreach (var s in theReader.FilePaths)
                    {
                        listBox2.Items.Add(s);
                    }
                    break;
                }
                }


                return;
            }

            case 6:
            {
                if (comboBox5.SelectedIndex == -1)
                {
                    smil1 = ".wpl";
                }
                var            pls          = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "RFCURI" + smil1, PlaylistFormat.LocationFormatting.RFC_URI);
                IList <string> pathsToWrite = new List <string>();
                foreach (var item in listBox1.Items)
                {
                    pathsToWrite.Add(item.ToString());
                }
                pls.FilePaths = pathsToWrite;
                var theReader = PlaylistIOFactory.GetInstance().GetPlaylistIO(loc + "RFCURI" + smil1);
                foreach (var s in theReader.FilePaths)
                {
                    listBox2.Items.Add(s);
                }

                break;
            }
            }
        }
Ejemplo n.º 23
0
        public void PLIO_R_NoFormat()
        {
            IPlaylistIO pls = PlaylistIOFactory.GetInstance().GetPlaylistIO(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_simple.xyz");

            Assert.IsInstanceOfType(pls, typeof(ATL.Playlist.IO.DummyIO));
        }
Ejemplo n.º 24
0
        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);
                }
            }
        }
Ejemplo n.º 25
0
        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);
            }
        }
Ejemplo n.º 26
0
        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);
            }
        }
Ejemplo n.º 27
0
        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);
                }
            }
        }
Ejemplo n.º 28
0
        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);
                }
            }
        }
Ejemplo n.º 29
0
        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;
            }
        }
Ejemplo n.º 30
0
        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);
            }
        }