public static ILyricsWriter CreateFromReader(ILyricsReader Reader) { XmlLyricsWriter wrt = new XmlLyricsWriter(); ILyricsMetadata Metadata = Reader as ILyricsMetadata; if (Metadata != null) { wrt.Title = Metadata.Title; wrt.Artist = Metadata.Artist; wrt.Album = Metadata.Album; } foreach (var i in Reader.Translations) { wrt.AddTranslation(i.Value); Reader.TranslationID = i.Key; foreach (var line in Reader.GetAllLines()) { wrt.AddLine(i.Key, line); } } wrt.DefaultTranslationID = Reader.DefaultTranslationID; return(wrt); }
/// <summary> /// Performs a scan in the directory that contains the music file for a /// matching lyrics file. /// </summary> /// <param name="SongInfo">An <see cref="ISongInfo"/> instance that holds informations about a song.</param> /// <returns>An <see cref="ILyricsReader"/> instance if the lyrics is found or null otherwise.</returns> private ILyricsReader ScanFileDirectory(ISongInfo SongInfo) { string Dir = Path.GetDirectoryName(SongInfo.Source); #region Error checking if (!Directory.Exists(Dir)) { return(null); } #endregion //Try to find a lyrics file with the same name as in SongInfo. //Eg. if we have "test.mp3", try to find "test.lrc". foreach (var Ext in LyricsLoader.SupportedExtensions) { string Filename = Path.ChangeExtension(SongInfo.Source, Ext); if (File.Exists(Filename)) { return(LyricsLoader.LoadFile(Filename)); } } //Scan all the lyrics files in the same folder. foreach (var File in LyricsLoader.FindAllLyricsFiles(Dir)) { try { ILyricsReader reader = LyricsLoader.LoadFile(File); ILyricsMetadata metadata = reader as ILyricsMetadata; if (metadata != null) { if (metadata.Title == SongInfo.Title && metadata.Artist == SongInfo.Artist) { return(reader); } } } catch {} } //If lyrics was not found, null is returned. return(null); }