Exemple #1
0
        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>
        /// Finds a lyrics file asynchronously using the informations provided by an
        /// ISongInfo instance.
        /// </summary>
        /// <param name="SongInfo">An ISongInfo instance that holds informations about a song.</param>
        /// <returns>A Task for an ILyricsReader instance if the lyrics is found or null otherwise.</returns>
        public static async Task <ILyricsReader> FindLyricsAsync(ISongInfo SongInfo)
        {
            foreach (ILyricsProvider Provider in Providers)
            {
                ILyricsReader reader = await Provider.FindLyricsAsync(SongInfo);

                if (reader != null)
                {
                    return(reader);
                }
            }

            return(null);
        }
        /// <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);
        }
Exemple #4
0
        private void btnOpen_Click(object sender, EventArgs e)
        {
            OpenFileDialog dlg = new OpenFileDialog()
            {
                Filter = "Dalszöveg fájlok|*.lrc;*.xml"
            };

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                this.LyricsReader = LyricsLoader.LoadFile(dlg.FileName);

                if (this.LyricsReader == null)
                {
                    MessageBox.Show("Úgy tűnik, ez a fájl nem dalszöveg-fájl.");
                }
                else
                {
                    lFilename.Text = new FileInfo(dlg.FileName).Name;
                }
            }
        }