fix music brainz album search results
This commit is contained in:
parent
8a7b24000d
commit
1d37f9ad0e
|
@ -81,46 +81,24 @@ namespace MediaBrowser.Providers.Music
|
|||
|
||||
private IEnumerable<RemoteSearchResult> GetResultsFromResponse(XmlDocument doc)
|
||||
{
|
||||
var ns = new XmlNamespaceManager(doc.NameTable);
|
||||
ns.AddNamespace("mb", MusicBrainzBaseUrl + "/ns/mmd-2.0#");
|
||||
|
||||
var list = new List<RemoteSearchResult>();
|
||||
|
||||
var nodes = doc.SelectNodes("//mb:release-list/mb:release", ns);
|
||||
|
||||
if (nodes != null)
|
||||
return ReleaseResult.Parse(doc).Select(i =>
|
||||
{
|
||||
foreach (var node in nodes.Cast<XmlNode>())
|
||||
var result = new RemoteSearchResult
|
||||
{
|
||||
if (node.Attributes != null)
|
||||
{
|
||||
string name = null;
|
||||
Name = i.Title
|
||||
};
|
||||
|
||||
string mbzId = node.Attributes["id"].Value;
|
||||
|
||||
var nameNode = node.SelectSingleNode("//mb:title", ns);
|
||||
|
||||
if (nameNode != null)
|
||||
{
|
||||
name = nameNode.InnerText;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(mbzId) && !string.IsNullOrWhiteSpace(name))
|
||||
{
|
||||
var result = new RemoteSearchResult
|
||||
{
|
||||
Name = name
|
||||
};
|
||||
|
||||
result.SetProviderId(MetadataProviders.MusicBrainzAlbum, mbzId);
|
||||
|
||||
list.Add(result);
|
||||
}
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(i.ReleaseId))
|
||||
{
|
||||
result.SetProviderId(MetadataProviders.MusicBrainzAlbum, i.ReleaseId);
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(i.ReleaseGroupId))
|
||||
{
|
||||
result.SetProviderId(MetadataProviders.MusicBrainzAlbum, i.ReleaseGroupId);
|
||||
}
|
||||
}
|
||||
|
||||
return list;
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
public async Task<MetadataResult<MusicAlbum>> GetMetadata(AlbumInfo id, CancellationToken cancellationToken)
|
||||
|
@ -208,7 +186,7 @@ namespace MediaBrowser.Providers.Music
|
|||
|
||||
var doc = await GetMusicBrainzResponse(url, true, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return ReleaseResult.Parse(doc);
|
||||
return ReleaseResult.Parse(doc, 1).FirstOrDefault();
|
||||
}
|
||||
|
||||
private async Task<ReleaseResult> GetReleaseResultByArtistName(string albumName, string artistName, CancellationToken cancellationToken)
|
||||
|
@ -219,32 +197,32 @@ namespace MediaBrowser.Providers.Music
|
|||
|
||||
var doc = await GetMusicBrainzResponse(url, true, cancellationToken).ConfigureAwait(false);
|
||||
|
||||
return ReleaseResult.Parse(doc);
|
||||
return ReleaseResult.Parse(doc, 1).FirstOrDefault();
|
||||
}
|
||||
|
||||
private class ReleaseResult
|
||||
{
|
||||
public string ReleaseId;
|
||||
public string ReleaseGroupId;
|
||||
public string Title;
|
||||
|
||||
public static ReleaseResult Parse(XmlDocument doc)
|
||||
public static List<ReleaseResult> Parse(XmlDocument doc, int? limit = null)
|
||||
{
|
||||
var docElem = doc.DocumentElement;
|
||||
var list = new List<ReleaseResult>();
|
||||
|
||||
if (docElem == null)
|
||||
{
|
||||
return new ReleaseResult();
|
||||
return list;
|
||||
}
|
||||
|
||||
var releaseList = docElem.FirstChild;
|
||||
if (releaseList == null)
|
||||
{
|
||||
return new ReleaseResult();
|
||||
return list;
|
||||
}
|
||||
|
||||
var nodes = releaseList.ChildNodes;
|
||||
string releaseId = null;
|
||||
string releaseGroupId = null;
|
||||
|
||||
if (nodes != null)
|
||||
{
|
||||
|
@ -252,18 +230,42 @@ namespace MediaBrowser.Providers.Music
|
|||
{
|
||||
if (string.Equals(node.Name, "release", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
releaseId = node.Attributes["id"].Value;
|
||||
releaseGroupId = GetReleaseGroupIdFromReleaseNode(node);
|
||||
break;
|
||||
var releaseId = node.Attributes["id"].Value;
|
||||
var releaseGroupId = GetReleaseGroupIdFromReleaseNode(node);
|
||||
|
||||
list.Add(new ReleaseResult
|
||||
{
|
||||
ReleaseId = releaseId,
|
||||
ReleaseGroupId = releaseGroupId,
|
||||
Title = GetTitleFromReleaseNode(node)
|
||||
});
|
||||
|
||||
if (limit.HasValue && list.Count >= limit.Value)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new ReleaseResult
|
||||
return list;
|
||||
}
|
||||
|
||||
private static string GetTitleFromReleaseNode(XmlNode node)
|
||||
{
|
||||
var subNodes = node.ChildNodes;
|
||||
if (subNodes != null)
|
||||
{
|
||||
ReleaseId = releaseId,
|
||||
ReleaseGroupId = releaseGroupId
|
||||
};
|
||||
foreach (var subNode in subNodes.Cast<XmlNode>())
|
||||
{
|
||||
if (string.Equals(subNode.Name, "title", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return subNode.InnerText;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static string GetReleaseGroupIdFromReleaseNode(XmlNode node)
|
||||
|
|
Loading…
Reference in New Issue
Block a user