public static LyricArchiveWrapper GetLyrics(IITTrackWrapper track)
        {
            var arcCached = App.LyricCollection.FindById(LyricArchive.GetID(track));

            if (arcCached != null && arcCached.Lyric != null)
            {
                return(new LyricArchiveWrapper(track, arcCached, true));
            }

            AlsongLyric[]       lyrics;
            LyricArchiveWrapper archive;

            lyrics = AlsongAPI.SearchByFile(track.Location);
            if (lyrics?.Length > 0 && TryWrap(track, lyrics[0], out archive))
            {
                return(archive);
            }

            lyrics = AlsongAPI.SearchByText(track.Artist, track.Title, 0);
            if (lyrics?.Length > 0 && TryWrap(track, lyrics[0], out archive))
            {
                return(archive);
            }

            return(null);
        }
Esempio n. 2
0
        private void SearchTask(object oargs)
        {
            var args = (SearchTaskArgs)oargs;

            AlsongLyric[] lyrics     = null;
            var           totalCount = 0;

            ////////////////////////////////////////////////////////////
            // Search By File
            lyrics = AlsongAPI.SearchByFile(args.Track.Location);
            if (lyrics != null)
            {
                totalCount += 1;

                this.Dispatcher.Invoke(new Action <IEnumerable <AlsongLyricWrapper> >(this.AddToResults), lyrics.Select(e => new AlsongLyricWrapper(args.Track, true, e)));
            }

            ////////////////////////////////////////////////////////////
            // Search By Text
            var page = 0;

            do
            {
                lyrics = AlsongAPI.SearchByText(args.Artist, args.Title, page++);

                if (lyrics == null)
                {
                    break;
                }

                totalCount += lyrics.Length;
                this.Dispatcher.Invoke(new Action <IEnumerable <AlsongLyricWrapper> >(this.AddToResults), lyrics.Select(e => new AlsongLyricWrapper(args.Track, false, e)));
            } while (args.Token.IsCancellationRequested || lyrics == null);

            ////////////////////////////////////////////////////////////

            if (totalCount == 0)
            {
                this.Dispatcher.Invoke(() =>
                {
                    this.ctlSearchResults.Visibility   = Visibility.Hidden;
                    this.ctlSearchNoResults.Visibility = Visibility.Visible;
                });
            }
            else
            {
                this.Dispatcher.Invoke(() =>
                {
                    this.ctlSearchResults.Visibility   = Visibility.Visible;
                    this.ctlSearchNoResults.Visibility = Visibility.Hidden;
                });
            }

            this.Dispatcher.Invoke(new Action <bool>(this.StopSearch), false);
        }