示例#1
0
            public float Similarity(ReleaseLookup releaseLookup)
            {
                var title = default(string);

                switch (releaseLookup.Type)
                {
                case ReleaseLookupType.Album:
                    title = string.Format("{0} - {1}", releaseLookup.Artist, releaseLookup.Album);
                    break;

                case ReleaseLookupType.Track:
                    if (!string.IsNullOrEmpty(releaseLookup.Artist))
                    {
                        title = string.Format("{0} - {1}", releaseLookup.Artist, releaseLookup.Title);
                    }
                    else
                    {
                        title = releaseLookup.Title;
                    }
                    break;
                }
                var similarity = Sanitize(this.Title).Similarity(title, true);

                return(similarity);
            }
示例#2
0
        public async Task <IEnumerable <Release> > GetReleases(ReleaseLookup releaseLookup, bool master)
        {
            var url = this.GetUrl(releaseLookup, master);

            Logger.Write(this, LogLevel.Debug, "Querying the API: {0}", url);
            var request = this.CreateRequest(url);

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    Logger.Write(this, LogLevel.Warn, "Status code does not indicate success.");
                    return(Enumerable.Empty <Release>());
                }
                return(await this.GetReleases(response.GetResponseStream()).ConfigureAwait(false));
            }
        }
示例#3
0
        protected virtual string GetUrl(ReleaseLookup releaseLookup, bool master)
        {
            var builder = new StringBuilder();

            builder.Append(this.BaseUrl);
            builder.Append("/database/search?");
            if (master)
            {
                builder.Append("type=master&");
                builder.Append(UrlHelper.GetParameters(new Dictionary <string, string>()
                {
                    { "artist", releaseLookup.Artist },
                    { "release_title", releaseLookup.Album },
                    { "track", releaseLookup.Title }
                }));
            }
            else
            {
                builder.Append("query=");
                builder.Append(this.GetQuery(releaseLookup));
            }
            return(builder.ToString());
        }
示例#4
0
        protected virtual string GetQuery(ReleaseLookup releaseLookup)
        {
            var builder = new StringBuilder();
            var parts   = new[]
            {
                releaseLookup.Artist,
                releaseLookup.Album,
                releaseLookup.Title
            };

            foreach (var part in parts)
            {
                if (string.IsNullOrEmpty(part))
                {
                    continue;
                }
                if (builder.Length > 0)
                {
                    builder.Append(UrlHelper.EscapeDataString(" - "));
                }
                builder.Append(UrlHelper.EscapeDataString(part));
            }
            return(builder.ToString());
        }