Exemple #1
0
        public static Task <int> UpdateMusicIdentificationAsync(Ares.ModelInfo.IProgressMonitor monitor, IList <String> files, String musicDirectory,
                                                                CancellationToken cancellationToken)
        {
            MusicIdentification identification = new MusicIdentification(monitor, cancellationToken);

            return(identification.DoUpdateAsync(files, musicDirectory));
        }
Exemple #2
0
 public static Task <int> FindTagsByIdsAsync(Ares.ModelInfo.IProgressMonitor progressMonitor, IList <FileIdentification> files, IList <String> filesToSearch, CancellationToken token)
 {
     return(Task.Factory.StartNew(() =>
     {
         TagsFromIds processor = new TagsFromIds(progressMonitor, token);
         return processor.DoFindTags(files, filesToSearch);
     }));
 }
Exemple #3
0
 public static Task <int> SetTagsFromIdsAsync(Ares.ModelInfo.IProgressMonitor progressMonitor, IList <FileIdentification> files, int languageId, bool interpret, bool album, CancellationToken token)
 {
     return(Task.Factory.StartNew(() =>
     {
         TagsFromIds processor = new TagsFromIds(progressMonitor, token);
         return processor.DoSetTags(files, languageId, interpret, album);
     }));
 }
Exemple #4
0
        public static Task <String> UploadTagsAsync(Ares.ModelInfo.IProgressMonitor monitor, IList <String> files, String user, bool includeLog, CancellationToken cancellationToken)
        {
            GlobalDbUpload instance = new GlobalDbUpload(monitor, cancellationToken);

            return(Task.Factory.StartNew(() =>
            {
                return instance.DoUploadTags(files, user, includeLog);
            }));
        }
Exemple #5
0
        public static Task ExtractTagsAsync(Ares.ModelInfo.IProgressMonitor progressMonitor, IList <String> files, String musicDirectory, int languageId,
                                            bool interpret, bool album, bool genre, bool mood, CancellationToken token)
        {
            TagExtractor      extractor = new TagExtractor(progressMonitor, token);
            TagExtractionInfo info      = new TagExtractionInfo()
            {
                Files = files, MusicDirectory = musicDirectory, Interpret = interpret, Album = album, Genre = genre, Mood = mood, LanguageId = languageId
            };

            return(Task.Factory.StartNew(() => { extractor.DoExtraction(info); }));
        }
Exemple #6
0
        public static Task <DownloadResult> DownloadTagsAsync(Ares.ModelInfo.IProgressMonitor monitor, IList <String> files, bool includeLog, CancellationToken cancellationToken)
        {
            GlobalDbDownload instance = new GlobalDbDownload(monitor, cancellationToken);

            return(Task.Factory.StartNew(() =>
            {
                int nrOfFoundFiles = 0;
                String res = instance.DoDownloadTags(files, out nrOfFoundFiles, includeLog);
                return new DownloadResult {
                    Result = res, NrOfFoundFiles = nrOfFoundFiles
                };
            }));
        }
Exemple #7
0
        private AcoustIdInfo QueryForAcoustId(String fileName, Ares.ModelInfo.IProgressMonitor progressMonitor)
        {
            var pcmTask = Task.Factory.StartNew(() =>
            {
                double seconds;
                Int16[] data = PcmExtractor.ExtractPcm(fileName, out seconds);
                progressMonitor.IncreaseProgress(25);
                return(new PcmInfo {
                    Data = data, Seconds = seconds
                });
            }, m_Token, TaskCreationOptions.AttachedToParent, TaskScheduler.Default);

            var chromaTask = pcmTask.ContinueWith((task) =>
            {
                var result = (pcmTask.Result != null && pcmTask.Result.Data != null) ? new ChromaPrintInfo {
                    Code = ChromaPrint.CalculateChromaprintCode(pcmTask.Result.Data), Seconds = pcmTask.Result.Seconds
                } : null;
                progressMonitor.IncreaseProgress(15);
                return(result);
            }, m_Token, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent, TaskScheduler.Default);

            var acoustTask = chromaTask.ContinueWith((task) =>
            {
                var result = (chromaTask.Result != null && !String.IsNullOrEmpty(chromaTask.Result.Code)) ? m_AcoustAPI.IdentifySong(chromaTask.Result.Code, chromaTask.Result.Seconds) : null;
                progressMonitor.IncreaseProgress(60);
                return(result);
            }, m_Token, TaskContinuationOptions.OnlyOnRanToCompletion | TaskContinuationOptions.AttachedToParent, TaskScheduler.Default);

            try
            {
                return(acoustTask.Result);
            }
            catch (OperationCanceledException)
            {
                return(new AcoustIdInfo()
                {
                    AcoustId = String.Empty, MusicBrainzId = String.Empty
                });
            }
            catch (AggregateException)
            {
                return(new AcoustIdInfo()
                {
                    AcoustId = String.Empty, MusicBrainzId = String.Empty
                });
            }
        }
Exemple #8
0
        private List <Task> CreateTaskPackage(List <String> filesNeedRetrieval, String basePath,
                                              MusicIdentificationRetriever retriever,
                                              List <Ares.Tags.FileIdentification> retrievedInfo,
                                              Ares.ModelInfo.IProgressMonitor progressMon,
                                              int packageIndex, int packageSize)
        {
            List <Task> subTasks = new List <Task>();

            for (int i = 0; i < packageSize; ++i)
            {
                int fileIndex = packageIndex * packageSize + i;
                if (fileIndex >= filesNeedRetrieval.Count)
                {
                    break;
                }
                String path  = System.IO.Path.Combine(basePath, filesNeedRetrieval[fileIndex]);
                var    task2 = Task.Factory.StartNew(() =>
                {
                    retriever.RetrieveFileInfo(path, retrievedInfo[fileIndex], progressMon);
                }, m_Token);
                subTasks.Add(task2);
            }
            return(subTasks);
        }
Exemple #9
0
 private TagsFromIds(Ares.ModelInfo.IProgressMonitor progressMonitor, CancellationToken token)
 {
     m_Monitor = progressMonitor;
     m_Token   = token;
 }
Exemple #10
0
 private TagExtractor(Ares.ModelInfo.IProgressMonitor monitor, CancellationToken token)
 {
     m_Monitor = monitor;
     m_Token   = token;
 }
Exemple #11
0
 private GlobalDbUpload(Ares.ModelInfo.IProgressMonitor monitor, CancellationToken token)
 {
     m_Monitor = monitor;
     m_Token   = token;
 }
Exemple #12
0
 private MusicIdentification(Ares.ModelInfo.IProgressMonitor monitor, CancellationToken token)
 {
     m_Monitor = monitor;
     m_Token   = token;
 }
Exemple #13
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);
        }
Exemple #14
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);
        }
Exemple #15
0
        private static IEnumerable <IElement> DoGetElementsFromDroppedItems(FileDragInfo dragInfo, String musicDirectory, String soundDirectory,
                                                                            System.Threading.CancellationToken token, Ares.ModelInfo.IProgressMonitor progressMonitor)
        {
            Ares.TagsImport.SequentialProgressMonitor monitor1 = null, monitor2 = null;
            if (progressMonitor != null)
            {
                monitor1 = new TagsImport.SequentialProgressMonitor(progressMonitor, 0.1, 9.9);
            }

            HashSet <String> allowedItems   = null;
            HashSet <String> unallowedItems = null;

            if (dragInfo.TagsFilter != null && dragInfo.TagsFilter.FilterMode != TagsFilterMode.NoFilter)
            {
                IList <String> files = null;
                try
                {
                    var dbRead = Ares.Tags.TagsModule.GetTagsDB().ReadInterface;
                    if (dragInfo.TagsFilter.FilterMode == TagsFilterMode.NormalFilter)
                    {
                        switch (dragInfo.TagsFilter.TagCategoryCombination)
                        {
                        case TagCategoryCombination.UseOneTagOfEachCategory:
                            files = dbRead.GetAllFilesWithAnyTagInEachCategory(dragInfo.TagsFilter.TagsByCategories);
                            break;

                        case TagCategoryCombination.UseAnyTag:
                        {
                            HashSet <int> allTags = new HashSet <int>();
                            foreach (var entry in dragInfo.TagsFilter.TagsByCategories)
                            {
                                allTags.UnionWith(entry.Value);
                            }
                            files = dbRead.GetAllFilesWithAnyTag(allTags);
                        }
                        break;

                        case TagCategoryCombination.UseAllTags:
                        default:
                        {
                            HashSet <int> allTags = new HashSet <int>();
                            foreach (var entry in dragInfo.TagsFilter.TagsByCategories)
                            {
                                allTags.UnionWith(entry.Value);
                            }
                            files = dbRead.GetAllFilesWithAllTags(allTags);
                        }
                        break;
                        }
                        if (files != null)
                        {
                            allowedItems = new HashSet <string>();
                            allowedItems.UnionWith(files);
                        }
                    }
                    else
                    {
                        files = dbRead.GetAllFilesWithAnyTag();
                        if (files != null)
                        {
                            unallowedItems = new HashSet <string>();
                            unallowedItems.UnionWith(files);
                        }
                    }
                }
                catch (Ares.Tags.TagsDbException)
                {
                    files = null;
                }
            }

            Dictionary <string, DraggedItem> uniqueItems = new Dictionary <string, DraggedItem>();

            foreach (DraggedItem item in dragInfo.DraggedItems)
            {
                AddItemsToSet(uniqueItems, item, allowedItems, unallowedItems, musicDirectory, soundDirectory, token);
                token.ThrowIfCancellationRequested();
                if (monitor1 != null)
                {
                    monitor1.IncreaseProgress(100.0 / dragInfo.DraggedItems.Count);
                }
            }

            if (progressMonitor != null)
            {
                monitor2 = new TagsImport.SequentialProgressMonitor(progressMonitor, 10.0, 90.0);
            }
            foreach (DraggedItem item in uniqueItems.Values)
            {
                yield return(CreateFileElement(item, musicDirectory, soundDirectory));

                token.ThrowIfCancellationRequested();
                if (monitor2 != null)
                {
                    monitor2.IncreaseProgress(100.0 / uniqueItems.Count);
                }
            }
        }
Exemple #16
0
        public static System.Threading.Tasks.Task <IList <IElement> > GetElementsFromDroppedItemsAsync(FileDragInfo dragInfo, System.Threading.CancellationToken token, Ares.ModelInfo.IProgressMonitor progressMonitor)
        {
            String musicDirectory = Settings.Settings.Instance.MusicDirectory;
            String soundDirectory = Settings.Settings.Instance.SoundDirectory;

            return(System.Threading.Tasks.Task.Factory.StartNew(() =>
            {
                try
                {
                    var result = new List <IElement>(DoGetElementsFromDroppedItems(dragInfo, musicDirectory, soundDirectory, token, progressMonitor));
                    return (IList <IElement>)result;
                }
                catch (OperationCanceledException)
                {
                    return null;
                }
                catch (AggregateException)
                {
                    return null;
                }
            }));
        }