Ejemplo n.º 1
0
        private void RetrieveInfo(String fileName, Ares.Tags.FileIdentification data, int query, Ares.ModelInfo.IProgressMonitor progressMonitor)
        {
            var id3Task = Task.Factory.StartNew(() =>
            {
                if ((query & (ARTIST | ALBUM | TITLE)) != 0)
                {
                    Un4seen.Bass.AddOn.Tags.TAG_INFO tag = Un4seen.Bass.AddOn.Tags.BassTags.BASS_TAG_GetFromFile(fileName, true, true);
                    if (tag != null)
                    {
                        if (!String.IsNullOrEmpty(tag.artist) && ((query & ARTIST) != 0))
                        {
                            data.Artist = tag.artist;
                            query      &= ~ARTIST;
                        }
                        if (!String.IsNullOrEmpty(tag.album) && ((query & ALBUM) != 0))
                        {
                            data.Album = tag.album;
                            query     &= ~ALBUM;
                        }
                        if (!String.IsNullOrEmpty(tag.title) && ((query & TITLE) != 0))
                        {
                            data.Title = tag.title;
                            // API always returns a title
                            // try to get a better title through MusicBrainz if it must be queried anyway
                            if ((query & (ARTIST | ALBUM)) == 0)
                            {
                                query &= ~TITLE;
                            }
                        }
                    }
                }
                progressMonitor.IncreaseProgress(15);
                return(query);
            }, m_Token, TaskCreationOptions.AttachedToParent, TaskScheduler.Default);


            var acoustIdTask = id3Task.ContinueWith((task) =>
            {
                SequentialProgressMonitor subMon = new SequentialProgressMonitor(progressMonitor, 15, 55);
                return(id3Task.Result != 0 ? QueryForAcoustId(fileName, subMon) : null);
            }, m_Token, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent, TaskScheduler.Default);

            var lastTask = acoustIdTask.ContinueWith((task) =>
            {
                if (acoustIdTask.Result != null)
                {
                    int adaptedQuery = id3Task.Result;
                    data.AcoustId    = acoustIdTask.Result.AcoustId;
                    if (((adaptedQuery & (ARTIST | ALBUM | TITLE)) != 0) && !String.IsNullOrEmpty(acoustIdTask.Result.MusicBrainzId))
                    {
                        QueryForMusicInfo(data, adaptedQuery, acoustIdTask.Result.MusicBrainzId);
                    }
                }
                progressMonitor.IncreaseProgress(30);
            }, m_Token, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent, TaskScheduler.Default);
        }
Ejemplo n.º 2
0
        private void QueryForMusicInfo(Ares.Tags.FileIdentification data, int query, String musicBrainzId)
        {
            String title, artist, album;

            m_MusicBrainzAPI.RetrieveMusicInfos(musicBrainzId, out title, out album, out artist);
            if (!String.IsNullOrEmpty(title) && ((query & TITLE) != 0))
            {
                data.Title = title;
            }
            if (!String.IsNullOrEmpty(album) && ((query & ALBUM) != 0))
            {
                data.Album = album;
            }
            if (!String.IsNullOrEmpty(artist) && ((query & ARTIST) != 0))
            {
                data.Artist = artist;
            }
        }
Ejemplo n.º 3
0
 private static bool NeedsRetrieval(Ares.Tags.FileIdentification item)
 {
     if (String.IsNullOrEmpty(item.Artist))
     {
         return(true);
     }
     if (String.IsNullOrEmpty(item.Album))
     {
         return(true);
     }
     if (String.IsNullOrEmpty(item.Title))
     {
         return(true);
     }
     if (String.IsNullOrEmpty(item.AcoustId))
     {
         return(true);
     }
     return(false);
 }
Ejemplo n.º 4
0
        public void RetrieveFileInfo(String fileName, Ares.Tags.FileIdentification data, Ares.ModelInfo.IProgressMonitor progressMonitor)
        {
            int query = 0;

            if (String.IsNullOrEmpty(data.AcoustId))
            {
                query |= ACOUST;
            }
            if (String.IsNullOrEmpty(data.Album))
            {
                query |= ALBUM;
            }
            if (String.IsNullOrEmpty(data.Artist))
            {
                query |= ARTIST;
            }
            if (String.IsNullOrEmpty(data.Title))
            {
                query |= TITLE;
            }
            RetrieveInfo(fileName, data, query, progressMonitor);
        }