From 6aff6de378b1d221731236c3cb24343239055975 Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Fri, 5 May 2017 14:33:46 -0500 Subject: [PATCH] Added Artist Overview. --- .../MetadataSource/SkyHook/SkyHookProxy.cs | 47 +++++++++++++++---- src/NzbDrone.Core/Music/AddArtistService.cs | 7 ++- src/UI/Handlebars/Helpers/Series.js | 12 +++++ .../SeriesOverviewItemViewTemplate.hbs | 10 ++-- src/UI/Series/Index/SeriesIndexLayout.js | 1 + src/UI/Series/series.less | 6 +++ 6 files changed, 64 insertions(+), 19 deletions(-) diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index 735ee3716..84600ae18 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -182,7 +182,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook httpRequest1.SuppressHttpError = true; var httpResponse = _httpClient.Get(httpRequest1); - var httpResponse2 = _httpClient.Get(httpRequest2); + if (httpResponse.HasHttpError) { @@ -197,18 +197,18 @@ namespace NzbDrone.Core.MetadataSource.SkyHook } List artists = MapArtists(httpResponse.Resource); - - if (httpResponse2.HasHttpError) + List newArtists = new List(artists.Count); + int count = 0; + foreach (var artist in artists) { - if (artists.Count == 1) - { - artists[0].Overview = httpResponse2.Resource.StorePlatformData.Artist.Results[itunesId].artistBio; - } + newArtists.Add(AddOverview(artist)); + count++; } // I don't know how we are getting tracks from iTunes yet. - return new Tuple>(artists[0], new List()); + return new Tuple>(newArtists[0], new List()); } + public List SearchForNewArtist(string title) { try @@ -247,7 +247,18 @@ namespace NzbDrone.Core.MetadataSource.SkyHook var httpResponse = _httpClient.Get(httpRequest); - return MapArtists(httpResponse.Resource); + + List artists = MapArtists(httpResponse.Resource); + List newArtists = new List(artists.Count); + int count = 0; + foreach (var artist in artists) + { + newArtists.Add(AddOverview(artist)); + count++; + } + + + return newArtists; } catch (HttpException) { @@ -260,6 +271,24 @@ namespace NzbDrone.Core.MetadataSource.SkyHook } } + private Artist AddOverview(Artist artist) + { + var httpRequest = _internalRequestBuilder.Create() + .SetSegment("route", "viewArtist") + .AddQueryParam("id", artist.ItunesId.ToString()) + .Build(); + httpRequest.Headers.Add("X-Apple-Store-Front", "143459-2,32 t:music3"); + httpRequest.Headers.ContentType = "application/json"; + var httpResponse = _httpClient.Get(httpRequest); + + if (!httpResponse.HasHttpError) + { + artist.Overview = httpResponse.Resource.StorePlatformData.Artist.Results[artist.ItunesId].artistBio; + } + + return artist; + } + private Artist MapArtistInfo(ArtistInfoResource resource) { // This expects ArtistInfoResource, thus just need to populate one artist diff --git a/src/NzbDrone.Core/Music/AddArtistService.cs b/src/NzbDrone.Core/Music/AddArtistService.cs index 072a67754..3ca636d0b 100644 --- a/src/NzbDrone.Core/Music/AddArtistService.cs +++ b/src/NzbDrone.Core/Music/AddArtistService.cs @@ -79,18 +79,17 @@ namespace NzbDrone.Core.Music } catch (SeriesNotFoundException) { - _logger.Error("tvdbid {1} was not found, it may have been removed from TheTVDB.", newArtist.ItunesId); + _logger.Error("iTunesId {1} was not found, it may have been removed from iTunes.", newArtist.ItunesId); throw new ValidationException(new List { - new ValidationFailure("TvdbId", "A series with this ID was not found", newArtist.ItunesId) + new ValidationFailure("iTunesId", "An artist with this ID was not found", newArtist.ItunesId) }); } var artist = tuple.Item1; - // If seasons were passed in on the new series use them, otherwise use the seasons from Skyhook - // TODO: Refactor for albums + // If albums were passed in on the new artist use them, otherwise use the albums from Skyhook newArtist.Albums = newArtist.Albums != null && newArtist.Albums.Any() ? newArtist.Albums : artist.Albums; artist.ApplyChanges(newArtist); diff --git a/src/UI/Handlebars/Helpers/Series.js b/src/UI/Handlebars/Helpers/Series.js index ecade70eb..4003a7e5b 100644 --- a/src/UI/Handlebars/Helpers/Series.js +++ b/src/UI/Handlebars/Helpers/Series.js @@ -71,6 +71,18 @@ Handlebars.registerHelper('seasonCountHelper', function() { return new Handlebars.SafeString('{0} Seasons'.format(seasonCount)); }); +Handlebars.registerHelper ('truncate', function (str, len) { + if (str && str.length > len && str.length > 0) { + var new_str = str + " "; + new_str = str.substr (0, len); + new_str = str.substr (0, new_str.lastIndexOf(" ")); + new_str = (new_str.length > 0) ? new_str : str.substr (0, len); + + return new Handlebars.SafeString ( new_str +'...' ); + } + return str; +}); + Handlebars.registerHelper('albumCountHelper', function() { var albumCount = this.albumCount; diff --git a/src/UI/Series/Index/Overview/SeriesOverviewItemViewTemplate.hbs b/src/UI/Series/Index/Overview/SeriesOverviewItemViewTemplate.hbs index 4e9785b50..f562800fc 100644 --- a/src/UI/Series/Index/Overview/SeriesOverviewItemViewTemplate.hbs +++ b/src/UI/Series/Index/Overview/SeriesOverviewItemViewTemplate.hbs @@ -20,12 +20,10 @@
-
- -
- {{overview}} -
-
+
+
+ {{truncate overview 600}} +
diff --git a/src/UI/Series/Index/SeriesIndexLayout.js b/src/UI/Series/Index/SeriesIndexLayout.js index 049bd267b..a8ae3d61c 100644 --- a/src/UI/Series/Index/SeriesIndexLayout.js +++ b/src/UI/Series/Index/SeriesIndexLayout.js @@ -20,6 +20,7 @@ require('../../Mixins/backbone.signalr.mixin'); module.exports = Marionette.Layout.extend({ template : 'Series/Index/SeriesIndexLayoutTemplate', + regions : { seriesRegion : '#x-series', toolbar : '#x-toolbar', diff --git a/src/UI/Series/series.less b/src/UI/Series/series.less index c023a7da5..f17229f6f 100644 --- a/src/UI/Series/series.less +++ b/src/UI/Series/series.less @@ -8,6 +8,12 @@ max-width: 100%; } +.truncate { + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; +} + .edit-series-modal, .delete-series-modal { overflow : visible;