From 9434d05a5f569acc9f23a0c754f42e9242cc974e Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 5 May 2013 21:15:48 -0400 Subject: [PATCH] added stub page to edit metatada for an item --- MediaBrowser.Controller/Entities/Folder.cs | 2 +- .../Movies/RottenTomatoesMovieProvider.cs | 41 ++++++++----------- .../Providers/Music/FanArtAlbumProvider.cs | 17 ++++++-- .../Api/DashboardService.cs | 1 + .../MediaBrowser.WebDashboard.csproj | 6 +++ 5 files changed, 40 insertions(+), 27 deletions(-) diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 63b6f377b..7918be877 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -729,7 +729,7 @@ namespace MediaBrowser.Controller.Entities foreach (var tuple in list) { - if (tasks.Count > 5) + if (tasks.Count > 8) { await Task.WhenAll(tasks).ConfigureAwait(false); } diff --git a/MediaBrowser.Controller/Providers/Movies/RottenTomatoesMovieProvider.cs b/MediaBrowser.Controller/Providers/Movies/RottenTomatoesMovieProvider.cs index 0e99ea9df..d6f66fa4f 100644 --- a/MediaBrowser.Controller/Providers/Movies/RottenTomatoesMovieProvider.cs +++ b/MediaBrowser.Controller/Providers/Movies/RottenTomatoesMovieProvider.cs @@ -11,6 +11,7 @@ using System.Threading; using System.Threading.Tasks; using System.IO; using System.Collections.Generic; +using System.Linq; namespace MediaBrowser.Controller.Providers.Movies { @@ -70,7 +71,7 @@ namespace MediaBrowser.Controller.Providers.Movies { get { - return "1"; + return "2"; } } @@ -139,8 +140,6 @@ namespace MediaBrowser.Controller.Providers.Movies /// true if XXXX, false otherwise protected override bool NeedsRefreshInternal(BaseItem item, BaseProviderInfo providerInfo) { - return true; - // Refresh if imdb id has changed if (providerInfo.Data != GetComparisonData(item.GetProviderId(MetadataProviders.Imdb))) { @@ -174,10 +173,10 @@ namespace MediaBrowser.Controller.Providers.Movies { // No IMDB Id, search RT for an ID - int page = 1; - using (Stream stream = HttpClient.Get(MovieSearchUrl(item.Name, page), _rottenTomatoesResourcePool, cancellationToken).Result) + var page = 1; + using (var stream = HttpClient.Get(MovieSearchUrl(item.Name, page), _rottenTomatoesResourcePool, cancellationToken).Result) { - RTSearchResults result = JsonSerializer.DeserializeFromStream(stream); + var result = JsonSerializer.DeserializeFromStream(stream); if (result.total == 1) { @@ -203,9 +202,9 @@ namespace MediaBrowser.Controller.Providers.Movies if (hit == null) { - using (Stream newPageStream = HttpClient.Get(MovieSearchUrl(item.Name, page++), _rottenTomatoesResourcePool, cancellationToken).Result) + using (var newPageStream = HttpClient.Get(MovieSearchUrl(item.Name, page++), _rottenTomatoesResourcePool, cancellationToken).Result) { - result = JsonSerializer.DeserializeFromStream(stream); + result = JsonSerializer.DeserializeFromStream(newPageStream); if (result.total == 0) { @@ -223,9 +222,9 @@ namespace MediaBrowser.Controller.Providers.Movies else { // Have IMDB Id - using (Stream stream = HttpClient.Get(MovieImdbUrl(imdbId), _rottenTomatoesResourcePool, cancellationToken).Result) + using (var stream = HttpClient.Get(MovieImdbUrl(imdbId), _rottenTomatoesResourcePool, cancellationToken).Result) { - RTMovieSearchResult result = JsonSerializer.DeserializeFromStream(stream); + var result = JsonSerializer.DeserializeFromStream(stream); if (!string.IsNullOrEmpty(result.id)) { @@ -241,23 +240,20 @@ namespace MediaBrowser.Controller.Providers.Movies item.CriticRatingSummary = hit.critics_concensus; item.CriticRating = float.Parse(hit.ratings.critics_score); - using (Stream stream = HttpClient.Get(MovieReviewsUrl(hit.id), _rottenTomatoesResourcePool, cancellationToken).Result) + using (var stream = HttpClient.Get(MovieReviewsUrl(hit.id), _rottenTomatoesResourcePool, cancellationToken).Result) { - RTReviewList result = JsonSerializer.DeserializeFromStream(stream); + var result = JsonSerializer.DeserializeFromStream(stream); - item.CriticReviews.Clear(); - foreach (var rtReview in result.reviews) + item.CriticReviews = result.reviews.Select(rtReview => new ItemReview { - ItemReview review = new ItemReview(); + ReviewerName = rtReview.critic, + Publisher = rtReview.publication, + Date = DateTime.Parse(rtReview.date).ToUniversalTime(), + Caption = rtReview.quote, + Url = rtReview.links.review - review.ReviewerName = rtReview.critic; - review.Publisher = rtReview.publication; - review.Date = DateTime.Parse(rtReview.date).ToUniversalTime(); - review.Caption = rtReview.quote; - review.Url = rtReview.links.review; - item.CriticReviews.Add(review); - } + }).ToList(); if (data == null) { @@ -286,7 +282,6 @@ namespace MediaBrowser.Controller.Providers.Movies SetLastRefreshed(item, DateTime.UtcNow); - return Task.FromResult(true); } diff --git a/MediaBrowser.Controller/Providers/Music/FanArtAlbumProvider.cs b/MediaBrowser.Controller/Providers/Music/FanArtAlbumProvider.cs index d9ccc6fdc..96717fe3f 100644 --- a/MediaBrowser.Controller/Providers/Music/FanArtAlbumProvider.cs +++ b/MediaBrowser.Controller/Providers/Music/FanArtAlbumProvider.cs @@ -83,7 +83,7 @@ namespace MediaBrowser.Controller.Providers.Music { get { - return "11"; + return "12"; } } @@ -211,6 +211,8 @@ namespace MediaBrowser.Controller.Providers.Music /// private DateTime _lastMusicBrainzRequest = DateTime.MinValue; + private readonly SemaphoreSlim _musicBrainzSemaphore = new SemaphoreSlim(1, 1); + /// /// Gets the music brainz response. /// @@ -223,7 +225,7 @@ namespace MediaBrowser.Controller.Providers.Music try { - var diff = 1000 - (DateTime.Now - _lastMusicBrainzRequest).TotalMilliseconds; + var diff = 1500 - (DateTime.Now - _lastMusicBrainzRequest).TotalMilliseconds; // MusicBrainz is extremely adamant about limiting to one request per second @@ -236,7 +238,14 @@ namespace MediaBrowser.Controller.Providers.Music var doc = new XmlDocument(); - using (var xml = await HttpClient.Get(url, cancellationToken).ConfigureAwait(false)) + using (var xml = await HttpClient.Get(new HttpRequestOptions + { + Url = url, + CancellationToken = cancellationToken, + ResourcePool = _musicBrainzSemaphore, + UserAgent = "MediaBrowserServer/www.mediabrowser3.com" + + }).ConfigureAwait(false)) { using (var oReader = new StreamReader(xml, Encoding.UTF8)) { @@ -248,6 +257,8 @@ namespace MediaBrowser.Controller.Providers.Music } finally { + _lastMusicBrainzRequest = DateTime.Now; + _musicBrainzResourcePool.Release(); } } diff --git a/MediaBrowser.WebDashboard/Api/DashboardService.cs b/MediaBrowser.WebDashboard/Api/DashboardService.cs index a82f7be4d..ab03ca358 100644 --- a/MediaBrowser.WebDashboard/Api/DashboardService.cs +++ b/MediaBrowser.WebDashboard/Api/DashboardService.cs @@ -455,6 +455,7 @@ namespace MediaBrowser.WebDashboard.Api "boxsets.js", "clientsettings.js", "dashboardpage.js", + "edititemmetadata.js", "edititemimages.js", "edituserpage.js", "gamesrecommendedpage.js", diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index bda7c013c..29765542d 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -213,6 +213,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest @@ -276,6 +279,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest