public void PL_TestSMIL() { 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 { IPlaylistReader theReader = PlaylistReaders.PlaylistReaderFactory.GetInstance().GetPlaylistReader(testFileLocation); Assert.IsNotInstanceOfType(theReader, typeof(PlaylistReaders.BinaryLogic.DummyReader)); Assert.AreEqual(3, theReader.GetFiles().Count); foreach (string s in theReader.GetFiles()) { System.Console.WriteLine(s); Assert.IsTrue(System.IO.File.Exists(s)); } } finally { File.Delete(testFileLocation); } }
/// <summary> /// Instantiate a new playlist reader based on the given playlist file path. /// </summary> /// <param name="path"> /// The path of a playlist file including a recognizeable extension: M3U, PLS, WPL, /// or ZPL. /// </param> /// <returns>An IPlaylistReader instance.</returns> public static IPlaylistReader CreateReader(string path) { IPlaylistReader reader = null; string extension = Path.GetExtension(path); if (extension[0] == '.') { extension = extension.Substring(1); } switch (extension.ToUpper()) { case "M3U": reader = new M3UPlaylistReader(path); break; case "PLS": reader = new PLSPlaylistReader(path); break; case "WPL": case "ZPL": reader = new WPLPlaylistReader(path); break; } return(reader); }
//======================================================================================== // Execute() //======================================================================================== /// <summary> /// Execute the scanner. /// </summary> public override void Execute() { Logger.WriteLine(base.name, String.Format("Import beginning, path '{0}'", playlistPath)); reader = PlaylistProviderFactory.CreateReader(playlistPath); try { ExecuteInternal(); } catch (Exception exc) { Logger.WriteLine(base.name, exc); } finally { if (reader != null) { reader.Dispose(); reader = null; } base.ProgressPercentage = 100; UpdateProgress(Resx.Completed); Logger.WriteLine(base.name, "Import completed"); } }
public void PL_M3U() { IPlaylistReader theReader = PlaylistReaders.PlaylistReaderFactory.GetInstance().GetPlaylistReader(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_simple.m3u"); Assert.AreEqual(1, theReader.GetFiles().Count); foreach (string s in theReader.GetFiles()) { System.Console.WriteLine(s); 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 = PlaylistReaders.PlaylistReaderFactory.GetInstance().GetPlaylistReader(testFileLocation); Assert.AreEqual(3, theReader.GetFiles().Count); foreach (string s in theReader.GetFiles()) { System.Console.WriteLine(s); Assert.IsTrue(System.IO.File.Exists(s)); } } finally { File.Delete(testFileLocation); } }
//[TestMethod] public void CS_ReadingPlaylist() { IPlaylistReader theReader = PlaylistReaderFactory.GetInstance().GetPlaylistReader(playlistPath); foreach (string s in theReader.GetFiles()) { System.Console.WriteLine(s); } }
public static short?DetermineTotalTrackNumbers(string filename, string trackNumber = null) { short?result = null; if (!string.IsNullOrEmpty(filename)) { var fileInfo = new FileInfo(filename); var directoryName = fileInfo.DirectoryName; // See if CUE sheet exists if so read tracks from that and return latest track number var cueFiles = Directory.GetFiles(directoryName, ("*.cue")); if (cueFiles != null && cueFiles.Any()) { try { ICatalogDataReader theReader = CatalogDataReaderFactory.GetInstance().GetCatalogDataReader(cueFiles.First()); result = (short)theReader.Tracks.Max(x => x.TrackNumber); } catch (Exception ex) { Trace.Write("Error Reading Cue: " + ex.ToString()); } } if (!result.HasValue) { // See if M3U sheet exists if so read tracks from that and return latest track number var m3uFiles = Directory.GetFiles(directoryName, ("*.m3u")); if (m3uFiles != null && m3uFiles.Any()) { try { IPlaylistReader theReader = PlaylistReaderFactory.GetInstance().GetPlaylistReader(m3uFiles.First()); result = (short)theReader.GetFiles().Count(); } catch (Exception ex) { Trace.Write("Error Reading m3u: " + ex.ToString()); } } } } // Try to parse from TrackNumber if (!result.HasValue) { result = ID3TagsHelper.ParseTotalTrackNumber(trackNumber); } return(result); }
public void PL_B4S() { string testFileLocation = TestUtils.CopyFileAndReplace(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist.b4s", "$PATH", TestUtils.GetResourceLocationRoot(false)); try { IPlaylistReader theReader = PlaylistReaders.PlaylistReaderFactory.GetInstance().GetPlaylistReader(testFileLocation); Assert.AreEqual(3, theReader.GetFiles().Count); foreach (string s in theReader.GetFiles()) { Assert.IsTrue(System.IO.File.Exists(s)); } } finally { File.Delete(testFileLocation); } }
public Player(IFileFinder fileFinder, IPlaylistReader playlistReader, IAudioStreamFactory audioStreamFactory, IBackgroundWorkerFactory backgroundWorkerFactory, IFileSystemFacade fileSystem) { this.fileFinder = fileFinder; this.playlistReader = playlistReader; this.backgroundWorkerFactory = backgroundWorkerFactory; this.audioStreamFactory = audioStreamFactory; this.fileSystem = fileSystem; history = new List<string>(); isStopped = true; isPlaying = false; isPaused = false; wasPausedBeforeBadSound = isPaused; loopType = LoopType.None; upto = 0; }
public void PL_TestCommon() { IPlaylistReader theReader = PlaylistReaders.PlaylistReaderFactory.GetInstance().GetPlaylistReader(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_simple.m3u"); Assert.AreEqual(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_simple.m3u", theReader.Path); ArrayLogger log = new ArrayLogger(); try { theReader = PlaylistReaders.PlaylistReaderFactory.GetInstance().GetPlaylistReader(TestUtils.GetResourceLocationRoot() + "_Playlists/efiufhziuefizeub.m3u"); theReader.GetFiles(); 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 void PL_TestB4S() { string testFileLocation = TestUtils.CopyFileAndReplace(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist.b4s", "$PATH", TestUtils.GetResourceLocationRoot(false)); try { IPlaylistReader theReader = PlaylistReaders.PlaylistReaderFactory.GetInstance().GetPlaylistReader(testFileLocation); Assert.IsNotInstanceOfType(theReader, typeof(PlaylistReaders.BinaryLogic.DummyReader)); Assert.AreEqual(3, theReader.GetFiles().Count); foreach (string s in theReader.GetFiles()) { System.Console.WriteLine(s); Assert.IsTrue(System.IO.File.Exists(s)); } } finally { File.Delete(testFileLocation); } }
public PlaylistExporter(IFileSystem fileSystem, IPlaylistReader playlistReader, IPlaylistWriter playlistWriter) { if (fileSystem == null) { throw new ArgumentNullException(nameof(fileSystem)); } if (playlistReader == null) { throw new ArgumentNullException(nameof(playlistReader)); } if (playlistWriter == null) { throw new ArgumentNullException(nameof(playlistWriter)); } _fileSystem = fileSystem; _playlistReader = playlistReader; _playlistWriter = playlistWriter; }
public IPlaylistReader GetPlaylistReader(int formatId) { IPlaylistReader theReader = null; if (PL_PLS == formatId) { theReader = new PLSReader(); } else if (PL_M3U == formatId) { theReader = new M3UReader(); } else if (PL_FPL == formatId) { theReader = new FPLReader(); } else if (PL_XSPF == formatId) { theReader = new XSPFReader(); } else if (PL_SMIL == formatId) { theReader = new SMILReader(); } else if (PL_ASX == formatId) { theReader = new ASXReader(); } else if (PL_B4S == formatId) { theReader = new B4SReader(); } if (null == theReader) { theReader = new DummyReader(); } return(theReader); }
public MainWindow() { _audioDeviceLocater = new AudioDeviceLocater(); //Load app configuration string configFilename = System.IO.Path.Join(AppContext.BaseDirectory, CONFIG_FILENAME); ConfigurationLoader configLoader = new ConfigurationLoader(); configLoader.LoadFromFile(configFilename); _config = configLoader.Configuration; //Get list of Music search locations List <string> searchLocations = new List <string>(); searchLocations.Add(System.IO.Path.Join(AppContext.BaseDirectory, "Music")); searchLocations.AddRange(_config.SearchLocations); _fileLocater = new LocalTrackLocater(searchLocations.ToArray()); //Instantiate requires classes _metadataExtractor = new MetadataExtractor(); _localLibraryManager = new LocalLibraryManager(_fileLocater, _metadataExtractor); _musicPlayer = new MusicPlayer(); _queueBuilder = new QueueBuilder(); _playlistReader = new LocalPlaylistReader(_localLibraryManager, System.IO.Path.Join(AppContext.BaseDirectory, "Playlists")); _playlistWriter = new LocalPlaylistWriter(System.IO.Path.Join(AppContext.BaseDirectory, "Playlists")); _playlistManager = new PlaylistManager(_playlistReader, _playlistWriter); _trackProgressTimer = new DispatcherTimer(); _trackProgressTimer.Interval = TimeSpan.FromSeconds(0.5); _trackProgressTimer.Tick += (_, __) => { lblCurrentTime.Content = _musicPlayer.GetCurrentTrackTimePosition().ToString(@"mm\:ss"); }; //Initialise the search page _searchPage = new TrackPage(); InitializeComponent(); }
public IPlaylistReader GetPlaylistReader(Int32 formatId) { IPlaylistReader theReader = null; if (PL_PLS == formatId) { theReader = new PlsReader(); } else if (PL_M3U == formatId) { theReader = new M3UReader(); } else if (PL_XSPF == formatId) { theReader = new XspfReader(); } else if (PL_SMIL == formatId) { theReader = new SmilReader(); } else if (PL_ASX == formatId) { theReader = new AsxReader(); } else if (PL_B4S == formatId) { theReader = new B4SReader(); } if (null == theReader) { theReader = new DummyReader(); } return(theReader); }
public MusicComparer(string sourceRoot, string targetRoot, IEnumerable <string> playlists) { // Make sure the root paths end with "\". if (!sourceRoot.EndsWith("\\")) { sourceRoot += "\\"; } if (!targetRoot.EndsWith("\\")) { targetRoot += "\\"; } // Create list of source playlists. sourcePlaylists = playlists.ToList(); // Create list of song in the playlists. SortedDictionary <string, string> sourceSongs = new SortedDictionary <string, string>(); foreach (string playlistPath in playlists) { IPlaylistReader playlist = PlaylistReaderFactory.CreateReader(playlistPath); if (playlist != null) { foreach (PlaylistEntry entry in playlist.Songs.Where(e => Utils.IsPathRelative(e.Path, sourceRoot))) { AddSongToList(entry.Path, sourceRoot, sourceSongs); } } } // Create a list of all songs in the target folder. SortedDictionary <string, string> targetSongs = new SortedDictionary <string, string>(); IEnumerable <string> targetFiles = Directory.GetFiles(targetRoot, "*", SearchOption.AllDirectories); IEnumerable <string> targetSongFiles = targetFiles.Where(path => songExtensions.Contains(Path.GetExtension(path))); foreach (string songPath in targetSongFiles) { AddSongToList(songPath, targetRoot, targetSongs); } // Create list of target playlists. targetPlaylists = targetFiles.Where(path => playlistExtensions.Contains(Path.GetExtension(path))).ToList(); // Compare source and target songs. var itSource = sourceSongs.GetEnumerator(); var itTarget = targetSongs.GetEnumerator(); bool hasSource = itSource.MoveNext(); bool hasTarget = itTarget.MoveNext(); while (hasSource || hasTarget) { if (!hasSource) { combinedSongs.Add(new SongInfo(itTarget.Current.Key, "", itTarget.Current.Value)); hasTarget = itTarget.MoveNext(); } else if (!hasTarget) { combinedSongs.Add(new SongInfo(itSource.Current.Key, itSource.Current.Value, Path.Combine(targetRoot, itSource.Current.Key) + ".mp3")); hasSource = itSource.MoveNext(); } else { int compareResult = string.Compare(itSource.Current.Key, itTarget.Current.Key, true); if (compareResult < 0) { combinedSongs.Add(new SongInfo(itSource.Current.Key, itSource.Current.Value, Path.Combine(targetRoot, itSource.Current.Key) + ".mp3")); hasSource = itSource.MoveNext(); } else if (compareResult > 0) { combinedSongs.Add(new SongInfo(itTarget.Current.Key, "", itTarget.Current.Value)); hasTarget = itTarget.MoveNext(); } else { combinedSongs.Add(new SongInfo(itSource.Current.Key, itSource.Current.Value, itTarget.Current.Value)); hasSource = itSource.MoveNext(); hasTarget = itTarget.MoveNext(); } } } // Write test log. foreach (SongInfo song in combinedSongs) { Logger.WriteLine(song.State.ToString().Substring(0, 3) + " " + song.Name); } }
public void AddReader(IPlaylistReader reader) { Readers.Add(reader.Id, reader); }
public override void SetUp() { fileSystem = CreateMock<IFileSystemFacade>(); playlistReader = new PlaylistReader(fileSystem); }
public PlaylistManager(IPlaylistReader PlaylistReader, IPlaylistWriter PlaylistWriter) { _playlistReader = PlaylistReader; _playlistWriter = PlaylistWriter; }
public override void SetUp() { fileFinder = CreateMock<IFileFinder>(); playlistReader = CreateMock<IPlaylistReader>(); audioStreamFactory = CreateMock<IAudioStreamFactory>(); backgroundWorkerFactory = CreateMock<IBackgroundWorkerFactory>(); fileSystem = DynamicMock<IFileSystemFacade>(); player = new Player(fileFinder, playlistReader, audioStreamFactory, backgroundWorkerFactory, fileSystem); }
public void PL_ReadNoFormat() { IPlaylistReader theReader = PlaylistReaders.PlaylistReaderFactory.GetInstance().GetPlaylistReader(TestUtils.GetResourceLocationRoot() + "_Playlists/playlist_simple.xyz"); Assert.IsInstanceOfType(theReader, typeof(PlaylistReaders.BinaryLogic.DummyReader)); }
public PlaylistExporterTest() { _fileSystem = Substitute.For <IFileSystem>(); _playlistReader = Substitute.For <IPlaylistReader>(); _playlistWriter = Substitute.For <IPlaylistWriter>(); }
public PlaylistExporterTest() { _fileSystem = new FileSystem(); _playlistReader = new PlaylistReader(); }