Example #1
0
        public bool CanGetValue(IFileData fileData, OnDemandMetaDataRequest request)
        {
            var provider = request.State as LyricsProvider ?? this.GetAutoLookupProvider();

            if (provider == null)
            {
                return(false);
            }
            if (request.User)
            {
                //User requests are always processed.
                return(true);
            }
            lock (fileData.MetaDatas)
            {
                var metaDataItem = fileData.MetaDatas.FirstOrDefault(
                    element => string.Equals(element.Name, CustomMetaData.LyricsRelease, StringComparison.OrdinalIgnoreCase) && element.Type == MetaDataItemType.Tag
                    );
                if (metaDataItem != null && string.Equals(metaDataItem.Value, provider.None, StringComparison.OrdinalIgnoreCase))
                {
                    //We have previously attempted a lookup and it failed, don't try again (automatically).
                    return(false);
                }
            }
            return(true);
        }
Example #2
0
 public Task SetMetaData(OnDemandMetaDataRequest request, OnDemandMetaDataValues result)
 {
     foreach (var value in result.Values)
     {
         this.AddMetaData(request, value);
     }
     return(this.SaveMetaData(request, result));
 }
Example #3
0
        protected virtual async Task SaveMetaData(OnDemandMetaDataRequest request, OnDemandMetaDataValues result)
        {
            var fileDatas = result.Values.Select(value => value.FileData).ToArray();

            await this.MetaDataManager.Save(fileDatas, result.Write, result.Write, request.Name).ConfigureAwait(false);

            if (request.User)
            {
                await this.HierarchyManager.Refresh(fileDatas, request.Name);
            }
        }
Example #4
0
 protected virtual void AddMetaData(OnDemandMetaDataRequest request, OnDemandMetaDataValue value)
 {
     lock (value.FileData.MetaDatas)
     {
         var metaDataItem = value.FileData.MetaDatas.FirstOrDefault(
             element => string.Equals(element.Name, request.Name, StringComparison.OrdinalIgnoreCase) && element.Type == request.Type
             );
         if (metaDataItem == null)
         {
             metaDataItem = new MetaDataItem(request.Name, request.Type);
             value.FileData.MetaDatas.Add(metaDataItem);
         }
         metaDataItem.Value = value.Value;
     }
 }
Example #5
0
        public async Task <OnDemandMetaDataValues> GetValues(IEnumerable <IFileData> fileDatas, OnDemandMetaDataRequest request)
        {
            var provider = request.State as LyricsProvider ?? this.GetAutoLookupProvider();

            if (provider == null)
            {
                return(null);
            }
            var values = new List <OnDemandMetaDataValue>();

            foreach (var fileData in fileDatas)
            {
                Logger.Write(this, LogLevel.Debug, "Looking up lyrics for file \"{0}\"..", fileData.FileName);
                var result = await provider.Lookup(fileData).ConfigureAwait(false);

                if (!result.Success)
                {
                    Logger.Write(this, LogLevel.Warn, "Failed to look up lyrics for file \"{0}\".", fileData.FileName);
                    continue;
                }
                Logger.Write(this, LogLevel.Debug, "Looking up lyrics for file \"{0}\": OK.", fileData.FileName);
                values.Add(new OnDemandMetaDataValue(fileData, result.Lyrics));
            }
            return(new OnDemandMetaDataValues(values, this.Behaviour.WriteTags.Value));
        }
Example #6
0
        public IDictionary <IFileData, string> GetCurrentMetaData(IEnumerable <IFileData> fileDatas, OnDemandMetaDataRequest request)
        {
            var values = new Dictionary <IFileData, string>();

            foreach (var fileData in fileDatas)
            {
                lock (fileData.MetaDatas)
                {
                    var metaDataItem = fileData.MetaDatas.FirstOrDefault(
                        element => string.Equals(element.Name, request.Name, StringComparison.OrdinalIgnoreCase) && element.Type == request.Type
                        );
                    if (metaDataItem != null)
                    {
                        values[fileData] = metaDataItem.Value;
                    }
                }
            }
            return(values);
        }
Example #7
0
        public string GetCurrentMetaData(IFileData fileData, OnDemandMetaDataRequest request)
        {
            var values = this.GetCurrentMetaData(new[] { fileData }, request);

            return(values.Values.FirstOrDefault());
        }
Example #8
0
        public async Task <IEnumerable <string> > GetMetaData(IEnumerable <IFileData> fileDatas, OnDemandMetaDataRequest request)
        {
            using (await KeyLock.LockAsync(request.Name).ConfigureAwait(false))
            {
                var values = this.GetCurrentMetaData(fileDatas, request);
                var queue  = new HashSet <IFileData>(fileDatas.Except(values.Keys));
                if (queue.Any())
                {
                    var sources = this.GetSources(request.Name, request.Type);
                    foreach (var source in sources)
                    {
                        var result = await source.GetValues(
                            queue.Where(fileData => source.CanGetValue(fileData, request)).ToArray(),
                            request
                            ).ConfigureAwait(false);

                        if (result != null && result.Values.Any())
                        {
                            foreach (var value in result.Values)
                            {
                                this.AddMetaData(request, value);
                                values[value.FileData] = value.Value;
                                queue.Remove(value.FileData);
                            }
                            this.Dispatch(() => this.SaveMetaData(request, result));
                        }
                    }
                }
                return(new HashSet <string>(values.Values, StringComparer.OrdinalIgnoreCase));
            }
        }
Example #9
0
        public async Task <string> GetMetaData(IFileData fileData, OnDemandMetaDataRequest request)
        {
            var values = await this.GetMetaData(new[] { fileData }, request).ConfigureAwait(false);

            return(values.FirstOrDefault());
        }
Example #10
0
        public async Task <OnDemandMetaDataValues> GetValues(IEnumerable <IFileData> fileDatas, OnDemandMetaDataRequest request)
        {
            var releaseLookups = await this.Behaviour.FetchArtwork(fileDatas).ConfigureAwait(false);

            return(this.Behaviour.GetMetaDataValues(releaseLookups));
        }