private async Task <FingerprintResponse> MapCommodityToProductAsync(string commodity, DateTime start, DateTime end, string apiKey) { var fingerprintRequest = new FingerprintRequest { Commodity = commodity, ProfileDefinition = new List <ProfileDefinitionType> { new ProfileDefinitionType { UtcStartDateTime = start, UtcEndDateTime = end } } }; var apiResponseWrapper = await fingerprintService.FingerprintAsync(apiKey, fingerprintRequest); return(apiResponseWrapper.Data.Any() ? apiResponseWrapper.Data.FirstOrDefault() : throw new DataException($"Could not map Commodity '{commodity}' to Product")); }
private void OnGetTagFromFingerprint(object sender, EventArgs args) { active = true; Source source = ServiceManager.SourceManager.ActiveSource; UserJob job = new UserJob(AddinManager.CurrentLocalizer.GetString("Getting sound fingerprint")); job.SetResources(Resource.Cpu, Resource.Disk, Resource.Database); job.PriorityHints = PriorityHints.SpeedSensitive; job.Status = AddinManager.CurrentLocalizer.GetString("Scanning..."); job.IconNames = new string [] { "system-search", "gtk-find" }; job.CanCancel = true; job.CancelRequested += HandleJobCancelRequested; job.Register(); if (account == null) { account = new LastfmAccount(); LoginDialog dialog = new LoginDialog(account, true); dialog.Run(); dialog.Destroy(); } //comment the timeout system for TOS because still have issue and not seems to be linked... //System.DateTime start = System.DateTime.MinValue; ThreadPool.QueueUserWorkItem(delegate { try { var selection = ((ITrackModelSource)source).TrackModel.Selection; int total = selection.Count; int count = 0; foreach (TrackInfo track in ((ITrackModelSource)source).TrackModel.SelectedItems) { if (!active) { break; } if (String.IsNullOrEmpty(track.Uri.AbsolutePath)) { continue; } ad = new AudioDecoder((int)track.Duration.TotalSeconds); //respect last fm term of service : //You will not make more than 5 requests per originating IP address per second, averaged over a 5 minute period // 2 requests are done on each loop ==> time allowed by loop : 400ms /*if (start != System.DateTime.MinValue) { * TimeSpan span = System.DateTime.Now - start; * if (lastFmTOSMinTimeout > span) * Thread.Sleep (lastFmTOSMinTimeout - span); * } * start = DateTime.Now; */ byte[] fingerprint = ad.Decode(track.Uri.AbsolutePath); FingerprintRequest request = new FingerprintRequest(); request.Send(track, fingerprint, account); int fpid = request.GetFpId(); //force GC to dispose ad = null; Log.DebugFormat("Last.fm fingerprint id for {0} is {1}", track.TrackTitle, fpid); if (fpid > 0) { FetchMetadata(track, fpid); } else { Log.WarningFormat("Could not find fingerprint id for the track {0} !", track.TrackTitle); } job.Progress = (double)++count / (double)total; } } catch (Exception e) { account = null; Log.Exception(e); } finally { job.Finish(); } }); }
public async Task <ApiResponseWrapper <IEnumerable <FingerprintResponse> > > FingerprintAsync(string apiKey, FingerprintRequest fingerprintRequest) { try { return(await TradeCubePostViaApiKeyAsync <FingerprintRequest, ApiResponseWrapper <IEnumerable <FingerprintResponse> > >(apiKey, "Fingerprint", fingerprintRequest)); } catch (Exception ex) { logger.LogError(ex, "{Message}", ex.Message); return(new ApiResponseWrapper <IEnumerable <FingerprintResponse> > { Message = ex.Message, Status = HttpStatusCode.BadRequest.ToString(), Data = new List <FingerprintResponse>() }); } }