From 21df06bba989011071c8ab3e6d3a955307744bdb Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 31 Oct 2016 14:59:58 -0400 Subject: [PATCH] update musicbrainz providers --- .../Music/MusicBrainzAlbumProvider.cs | 38 +++++++++++++++---- .../Music/MusicBrainzArtistProvider.cs | 12 +++++- 2 files changed, 40 insertions(+), 10 deletions(-) diff --git a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs index 6bda0278c7..844614791a 100644 --- a/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs +++ b/MediaBrowser.Providers/Music/MusicBrainzAlbumProvider.cs @@ -7,6 +7,7 @@ using MediaBrowser.Model.Logging; using MediaBrowser.Model.Providers; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Net; @@ -266,7 +267,7 @@ namespace MediaBrowser.Providers.Music reader.MoveToContent(); // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -287,6 +288,10 @@ namespace MediaBrowser.Providers.Music } } } + else + { + reader.Read(); + } } return list; @@ -299,7 +304,7 @@ namespace MediaBrowser.Providers.Music reader.MoveToContent(); // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -326,6 +331,10 @@ namespace MediaBrowser.Providers.Music } } } + else + { + reader.Read(); + } } return list; @@ -421,7 +430,7 @@ namespace MediaBrowser.Providers.Music reader.MoveToContent(); // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -441,6 +450,10 @@ namespace MediaBrowser.Providers.Music } } } + else + { + reader.Read(); + } } return null; } @@ -453,7 +466,7 @@ namespace MediaBrowser.Providers.Music reader.MoveToContent(); // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -470,6 +483,10 @@ namespace MediaBrowser.Providers.Music } } } + else + { + reader.Read(); + } } return null; @@ -517,7 +534,9 @@ namespace MediaBrowser.Providers.Music using (var stream = await _httpClient.Get(options).ConfigureAwait(false)) { - list = _json.DeserializeFromStream>(stream); + var results = _json.DeserializeFromStream>(stream); + + list = results; } _lastMbzUrlQueryTicks = DateTime.UtcNow.Ticks; } @@ -550,11 +569,13 @@ namespace MediaBrowser.Providers.Music internal async Task GetMusicBrainzResponse(string url, bool isSearch, CancellationToken cancellationToken) { var urlInfo = await GetMbzUrl().ConfigureAwait(false); + var throttleMs = urlInfo.throttleMs; - if (urlInfo.throttleMs > 0) + if (throttleMs > 0) { // MusicBrainz is extremely adamant about limiting to one request per second - await Task.Delay(urlInfo.throttleMs, cancellationToken).ConfigureAwait(false); + _logger.Debug("Throttling MusicBrainz by {0}ms", throttleMs.ToString(CultureInfo.InvariantCulture)); + await Task.Delay(throttleMs, cancellationToken).ConfigureAwait(false); } url = urlInfo.url.TrimEnd('/') + url; @@ -564,7 +585,8 @@ namespace MediaBrowser.Providers.Music Url = url, CancellationToken = cancellationToken, UserAgent = _appHost.Name + "/" + _appHost.ApplicationVersion, - ResourcePool = _musicBrainzResourcePool + ResourcePool = _musicBrainzResourcePool, + BufferContent = throttleMs > 0 }; return await _httpClient.Get(options).ConfigureAwait(false); diff --git a/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs b/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs index d670c8de18..f752a85cbd 100644 --- a/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs +++ b/MediaBrowser.Providers/Music/MusicBrainzArtistProvider.cs @@ -88,7 +88,7 @@ namespace MediaBrowser.Providers.Music reader.MoveToContent(); // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -108,6 +108,10 @@ namespace MediaBrowser.Providers.Music } } } + else + { + reader.Read(); + } } return new List(); @@ -122,7 +126,7 @@ namespace MediaBrowser.Providers.Music reader.MoveToContent(); // Loop through each element - while (reader.Read()) + while (!reader.EOF) { if (reader.NodeType == XmlNodeType.Element) { @@ -149,6 +153,10 @@ namespace MediaBrowser.Providers.Music } } } + else + { + reader.Read(); + } } return list;