From 5b0f11b19ad05e8750055fb0cbdf9724aa6afd3b Mon Sep 17 00:00:00 2001 From: Joseph Milazzo Date: Sun, 30 Apr 2017 11:34:53 -0500 Subject: [PATCH] Albums can now be seen per artist from search. --- src/NzbDrone.Api/Music/AlbumResource.cs | 12 +++- .../SkyHook/Resource/ArtistResource.cs | 8 +++ .../MetadataSource/SkyHook/SkyHookProxy.cs | 44 +++--------- src/NzbDrone.Core/Music/Album.cs | 3 + src/NzbDrone.Core/Music/Artist.cs | 15 ----- src/UI/AddSeries/AddSeriesCollection.js | 3 +- src/UI/AddSeries/SearchResultView.js | 24 ++++--- src/UI/AddSeries/SearchResultViewTemplate.hbs | 67 +++++++++++++++---- src/UI/AddSeries/addSeries.less | 8 +++ src/UI/Series/Index/EmptyTemplate.hbs | 4 +- 10 files changed, 108 insertions(+), 80 deletions(-) diff --git a/src/NzbDrone.Api/Music/AlbumResource.cs b/src/NzbDrone.Api/Music/AlbumResource.cs index ee9a66564..a6d49d3bd 100644 --- a/src/NzbDrone.Api/Music/AlbumResource.cs +++ b/src/NzbDrone.Api/Music/AlbumResource.cs @@ -12,7 +12,9 @@ namespace NzbDrone.Api.Music public string AlbumName { get; set; } public bool Monitored { get; set; } public int Year { get; set; } - public List Genre { get; set; } + public List Genres { get; set; } + public string ArtworkUrl { get; set; } + } public static class AlbumResourceMapper @@ -26,7 +28,9 @@ namespace NzbDrone.Api.Music AlbumId = model.AlbumId, Monitored = model.Monitored, Year = model.Year, - AlbumName = model.Title + AlbumName = model.Title, + Genres = model.Genres, + ArtworkUrl = model.ArtworkUrl }; } @@ -39,7 +43,9 @@ namespace NzbDrone.Api.Music AlbumId = resource.AlbumId, Monitored = resource.Monitored, Year = resource.Year, - Title = resource.AlbumName + Title = resource.AlbumName, + Genres = resource.Genres, + ArtworkUrl = resource.ArtworkUrl }; } diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistResource.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistResource.cs index b7d8eff01..88ad6eae6 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistResource.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/Resource/ArtistResource.cs @@ -16,6 +16,14 @@ namespace NzbDrone.Core.MetadataSource.SkyHook.Resource public int ArtistId { get; set; } public string CollectionName { get; set; } public int CollectionId { get; set; } + public string PrimaryGenreName { get; set; } + public string ArtworkUrl100 { get; set; } + public string Country { get; set; } + public string CollectionExplicitness { get; set; } + public int TrackCount { get; set; } + public string Copyright { get; set; } + public DateTime ReleaseDate { get; set; } + } public class ArtistResource diff --git a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs index c2292b271..d11b60107 100644 --- a/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs +++ b/src/NzbDrone.Core/MetadataSource/SkyHook/SkyHookProxy.cs @@ -163,32 +163,12 @@ namespace NzbDrone.Core.MetadataSource.SkyHook var httpResponse = _httpClient.Get(httpRequest); - - //Console.WriteLine("Response: ", httpResponse.GetType()); - //_logger.Info("Response: ", httpResponse.Resource.ResultCount); - - //_logger.Info("HTTP Response: ", httpResponse.Resource.ResultCount); - //var tempList = new List(); - //var tempSeries = new Artist(); - //tempSeries.ArtistName = "AFI"; - //tempList.Add(tempSeries); - //return tempList; - - - Album tempAlbum; List artists = new List(); - ArtistComparer artistComparer = new ArtistComparer(); foreach (var album in httpResponse.Resource.Results) { - tempAlbum = new Album(); - // TODO: Perform MapAlbum call here - tempAlbum.AlbumId = album.CollectionId; - tempAlbum.Title = album.CollectionName; - - int index = artists.FindIndex(a => a.ItunesId == album.ArtistId); - + tempAlbum = MapAlbum(album); if (index >= 0) { @@ -200,6 +180,7 @@ namespace NzbDrone.Core.MetadataSource.SkyHook // TODO: Perform the MapArtist call here tempArtist.ItunesId = album.ArtistId; tempArtist.ArtistName = album.ArtistName; + tempArtist.Genres.Add(album.PrimaryGenreName); tempArtist.Albums.Add(tempAlbum); artists.Add(tempArtist); } @@ -207,10 +188,6 @@ namespace NzbDrone.Core.MetadataSource.SkyHook } return artists; - - // I need to return a list of mapped artists. - - //return httpResponse.Resource.Results.SelectList(MapArtist); } catch (HttpException) { @@ -223,15 +200,16 @@ namespace NzbDrone.Core.MetadataSource.SkyHook } } - private static Artist MapArtist(ArtistResource artistQuery) + private Album MapAlbum(AlbumResource albumQuery) { - var artist = new Artist(); - //artist.ItunesId = artistQuery.ItunesId; ; - - // artist.ArtistName = artistQuery.ArtistName; - - - return artist; + Album album = new Album(); + + album.AlbumId = albumQuery.CollectionId; + album.Title = albumQuery.CollectionName; + album.Year = albumQuery.ReleaseDate.Year; + album.ArtworkUrl = albumQuery.ArtworkUrl100; + album.Explicitness = albumQuery.CollectionExplicitness; + return album; } private static Series MapSeries(ShowResource show) diff --git a/src/NzbDrone.Core/Music/Album.cs b/src/NzbDrone.Core/Music/Album.cs index aa7923aef..c0c7fc19e 100644 --- a/src/NzbDrone.Core/Music/Album.cs +++ b/src/NzbDrone.Core/Music/Album.cs @@ -22,5 +22,8 @@ namespace NzbDrone.Core.Music public bool Monitored { get; set; } public List Images { get; set; } public List Actors { get; set; } // These are band members. TODO: Refactor + public List Genres { get; set; } + public string ArtworkUrl { get; set; } + public string Explicitness { get; set; } } } diff --git a/src/NzbDrone.Core/Music/Artist.cs b/src/NzbDrone.Core/Music/Artist.cs index 6cf856efe..6a8ccf959 100644 --- a/src/NzbDrone.Core/Music/Artist.cs +++ b/src/NzbDrone.Core/Music/Artist.cs @@ -9,20 +9,6 @@ using System.Text; namespace NzbDrone.Core.Music { - - public class ArtistComparer : IEqualityComparer - { - public bool Equals(Artist x, Artist y) - { - return x.ItunesId == y.ItunesId; - } - - public int GetHashCode(Artist obj) - { - throw new NotImplementedException(); - } - } - public class Artist : ModelBase { public Artist() @@ -46,7 +32,6 @@ namespace NzbDrone.Core.Music //public SeriesStatusType Status { get; set; } public string Overview { get; set; } public bool Monitored { get; set; } - //public int ProfileId { get; set; } public bool AlbumFolder { get; set; } public DateTime? LastInfoSync { get; set; } //public int Runtime { get; set; } diff --git a/src/UI/AddSeries/AddSeriesCollection.js b/src/UI/AddSeries/AddSeriesCollection.js index d81094eca..a243649f4 100644 --- a/src/UI/AddSeries/AddSeriesCollection.js +++ b/src/UI/AddSeries/AddSeriesCollection.js @@ -15,9 +15,8 @@ module.exports = Backbone.Collection.extend({ if (self.unmappedFolderModel) { model.path = self.unmappedFolderModel.get('folder').path; } - console.log('model: ', model); }); - console.log('response: ', response); // Note: this gets called after api responds with artist model + console.log('response: ', response); return response; } diff --git a/src/UI/AddSeries/SearchResultView.js b/src/UI/AddSeries/SearchResultView.js index 348413a35..7e7f60f47 100644 --- a/src/UI/AddSeries/SearchResultView.js +++ b/src/UI/AddSeries/SearchResultView.js @@ -6,8 +6,7 @@ var Marionette = require('marionette'); var Profiles = require('../Profile/ProfileCollection'); var RootFolders = require('./RootFolders/RootFolderCollection'); var RootFolderLayout = require('./RootFolders/RootFolderLayout'); -//var SeriesCollection = require('../Series/SeriesCollection'); -var SeriesCollection = require('../Artist/ArtistCollection'); +var ArtistCollection = require('../Artist/ArtistCollection'); var Config = require('../Config'); var Messenger = require('../Shared/Messenger'); var AsValidatedView = require('../Mixins/AsValidatedView'); @@ -94,7 +93,7 @@ var view = Marionette.ItemView.extend({ }, _configureTemplateHelpers : function() { - var existingSeries = SeriesCollection.where({ tvdbId : this.model.get('tvdbId') }); + var existingSeries = ArtistCollection.where({ iTunesId : this.model.get('itunesId') }); if (existingSeries.length > 0) { this.templateHelpers.existing = existingSeries[0].toJSON(); @@ -170,20 +169,22 @@ var view = Marionette.ItemView.extend({ this._addSeries(true); }, - _addSeries : function(searchForMissingEpisodes) { - var addButton = this.ui.addButton; - var addSearchButton = this.ui.addSearchButton; + _addSeries : function(searchForMissing) { + // TODO: Refactor to handle multiple add buttons/albums + var addButton = this.ui.addButton[0]; + var addSearchButton = this.ui.addSearchButton[0]; + console.log('_addSeries, searchForMissing=', searchForMissing); addButton.addClass('disabled'); addSearchButton.addClass('disabled'); var profile = this.ui.profile.val(); var rootFolderPath = this.ui.rootFolder.children(':selected').text(); - var seriesType = this.ui.seriesType.val(); + var seriesType = this.ui.seriesType.val(); // Perhaps make this a differnitator between artist or Album? var seasonFolder = this.ui.seasonFolder.prop('checked'); var options = this._getAddSeriesOptions(); - options.searchForMissingEpisodes = searchForMissingEpisodes; + options.searchForMissing = searchForMissing; this.model.set({ profileId : profile, @@ -197,7 +198,7 @@ var view = Marionette.ItemView.extend({ var self = this; var promise = this.model.save(); - if (searchForMissingEpisodes) { + if (searchForMissing) { this.ui.addSearchButton.spinForPromise(promise); } @@ -212,7 +213,7 @@ var view = Marionette.ItemView.extend({ promise.done(function() { console.log('[SearchResultView] _addSeries promise resolve:', self.model); - SeriesCollection.add(self.model); + ArtistCollection.add(self.model); self.close(); @@ -222,7 +223,7 @@ var view = Marionette.ItemView.extend({ goToSeries : { label : 'Go to Series', action : function() { - Backbone.history.navigate('/series/' + self.model.get('titleSlug'), { trigger : true }); + Backbone.history.navigate('/artist/' + self.model.get('titleSlug'), { trigger : true }); } } }, @@ -241,6 +242,7 @@ var view = Marionette.ItemView.extend({ _getAddSeriesOptions : function() { var monitor = this.ui.monitor.val(); + //[TODO]: Refactor for albums var lastSeason = _.max(this.model.get('seasons'), 'seasonNumber'); var firstSeason = _.min(_.reject(this.model.get('seasons'), { seasonNumber : 0 }), 'seasonNumber'); diff --git a/src/UI/AddSeries/SearchResultViewTemplate.hbs b/src/UI/AddSeries/SearchResultViewTemplate.hbs index bccef713d..12e4f9d44 100644 --- a/src/UI/AddSeries/SearchResultViewTemplate.hbs +++ b/src/UI/AddSeries/SearchResultViewTemplate.hbs @@ -1,31 +1,26 @@
-

- {{titleWithYear}} + {{artistName}} - +

-
+
{{#unless existing}} {{#unless path}} @@ -56,7 +51,7 @@
-->
- +
{{#unless existing}} - {{#if title}} + {{#if artistName}}
@@ -82,13 +77,56 @@ - +
+
+ {{else}} +
+ +
+ {{/if}} + {{else}} + + {{/unless}} +
+
+
+
+ {{#each albums}} +
+ +
+

{{albumName}} ({{year}})

+ {{#unless existing}} + {{#if albumName}} +
+ + +
+ + +
{{else}} -
+
@@ -103,5 +141,6 @@ {{/unless}}
+ {{/each}}
diff --git a/src/UI/AddSeries/addSeries.less b/src/UI/AddSeries/addSeries.less index 2ca8090f9..f958e01a3 100644 --- a/src/UI/AddSeries/addSeries.less +++ b/src/UI/AddSeries/addSeries.less @@ -75,6 +75,14 @@ margin : 10px; } + .album-poster { + min-width : 100px; + min-height : 100px; + max-width : 138px; + max-height : 203px; + margin : 10px; + } + a { color : #343434; } diff --git a/src/UI/Series/Index/EmptyTemplate.hbs b/src/UI/Series/Index/EmptyTemplate.hbs index abca7f764..16c5258ab 100644 --- a/src/UI/Series/Index/EmptyTemplate.hbs +++ b/src/UI/Series/Index/EmptyTemplate.hbs @@ -2,14 +2,14 @@
- You must be new around here, You should add some series. + You must be new around here, You should add some music.