diff --git a/PlexRequests.Api.Models/Music/MusicBrainzCoverArt.cs b/PlexRequests.Api.Models/Music/MusicBrainzCoverArt.cs new file mode 100644 index 000000000..40cecba94 --- /dev/null +++ b/PlexRequests.Api.Models/Music/MusicBrainzCoverArt.cs @@ -0,0 +1,55 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: MusicBrainzCoverArt.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion +using System.Collections.Generic; + +namespace PlexRequests.Api.Models.Music +{ + public class Thumbnails + { + public string large { get; set; } + public string small { get; set; } + } + + public class Image + { + public List types { get; set; } + public bool front { get; set; } + public bool back { get; set; } + public int edit { get; set; } + public string image { get; set; } + public string comment { get; set; } + public bool approved { get; set; } + public string id { get; set; } + public Thumbnails thumbnails { get; set; } + } + + public class MusicBrainzCoverArt + { + public List images { get; set; } + public string release { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj index 61a33d5e5..978171662 100644 --- a/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj +++ b/PlexRequests.Api.Models/PlexRequests.Api.Models.csproj @@ -50,6 +50,7 @@ + diff --git a/PlexRequests.Api/MusicBrainzApi.cs b/PlexRequests.Api/MusicBrainzApi.cs index f419fe851..8331e8a0d 100644 --- a/PlexRequests.Api/MusicBrainzApi.cs +++ b/PlexRequests.Api/MusicBrainzApi.cs @@ -66,5 +66,27 @@ namespace PlexRequests.Api return new MusicBrainzSearchResults(); // If there is no matching result we do not get returned a JSON string, it just returns "false". } } + + public MusicBrainzCoverArt GetCoverArt(string releaseId) + { + Log.Trace("Getting cover art for release: {0}", releaseId); + var request = new RestRequest + { + Resource = "release/{releaseId}", + Method = Method.GET + }; + request.AddUrlSegment("releaseId", releaseId); + + try + { + return Api.Execute(request, new Uri("http://coverartarchive.org/")); + } + catch (Exception e) + { + Log.Warn(e); + return new MusicBrainzCoverArt(); // If there is no matching result we do not get returned a JSON string, it just returns "false". + } + } + } } \ No newline at end of file diff --git a/PlexRequests.Core/Setup.cs b/PlexRequests.Core/Setup.cs index 4dea3a27a..93d8003e7 100644 --- a/PlexRequests.Core/Setup.cs +++ b/PlexRequests.Core/Setup.cs @@ -72,7 +72,7 @@ namespace PlexRequests.Core s.SaveSettings(defaultSettings); } - private void MigrateDb() // TODO: Remove when no longer needed + private void MigrateDb() // TODO: Remove in v1.7 { var result = new List(); RequestedModel[] requestedModels; diff --git a/PlexRequests.UI/Content/search.js b/PlexRequests.UI/Content/search.js index 2d9d65d50..b21b6f409 100644 --- a/PlexRequests.UI/Content/search.js +++ b/PlexRequests.UI/Content/search.js @@ -201,8 +201,8 @@ function getMusic(url) { $("#musicList").html(""); $.ajax(url).success(function (results) { - if (results.count > 0) { - results.releases.forEach(function (result) { + if (results.length > 0) { + results.forEach(function (result) { var context = buildMusicContext(result); var html = musicTemplate(context); @@ -254,9 +254,14 @@ function buildMusicContext(result) { var context = { id: result.id, title: result.title, - overview: result.disambiguation, - year: result.date, - type: "music" + overview: result.overview, + year: result.releaseDate, + type: "album", + trackCount: result.trackCount, + coverArtUrl: result.coverArtUrl, + artist: result.artist, + releaseType: result.releaseType, + country: result.country }; return context; diff --git a/PlexRequests.UI/Models/SearchMusicViewModel.cs b/PlexRequests.UI/Models/SearchMusicViewModel.cs new file mode 100644 index 000000000..94d3e6d1e --- /dev/null +++ b/PlexRequests.UI/Models/SearchMusicViewModel.cs @@ -0,0 +1,41 @@ +#region Copyright +// /************************************************************************ +// Copyright (c) 2016 Jamie Rees +// File: SearchMusicViewModel.cs +// Created By: Jamie Rees +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// ************************************************************************/ +#endregion +namespace PlexRequests.UI.Models +{ + public class SearchMusicViewModel + { + public string Id { get; set; } + public string Overview { get; set; } + public string CoverArtUrl { get; set; } + public string Title { get; set; } + public string Artist { get; set; } + public string ReleaseDate { get; set; } + public int TrackCount { get; set; } + public string ReleaseType { get; set; } + public string Country { get; set; } + } +} \ No newline at end of file diff --git a/PlexRequests.UI/Modules/SearchModule.cs b/PlexRequests.UI/Modules/SearchModule.cs index 3cf44c370..ed18a89a3 100644 --- a/PlexRequests.UI/Modules/SearchModule.cs +++ b/PlexRequests.UI/Modules/SearchModule.cs @@ -36,6 +36,7 @@ using NLog; using PlexRequests.Api; using PlexRequests.Api.Interfaces; +using PlexRequests.Api.Models.Music; using PlexRequests.Core; using PlexRequests.Core.SettingModels; using PlexRequests.Helpers; @@ -81,6 +82,7 @@ namespace PlexRequests.UI.Modules Post["request/movie"] = parameters => RequestMovie((int)Request.Form.movieId); Post["request/tv"] = parameters => RequestTvShow((int)Request.Form.tvId, (string)Request.Form.seasons); + Post["request/album"] = parameters => RequestTvShow((int)Request.Form.tvId, (string)Request.Form.seasons); } private TheMovieDbApi MovieApi { get; } private INotificationService NotificationService { get; } @@ -157,7 +159,32 @@ namespace PlexRequests.UI.Modules { var api = new MusicBrainsApi(); var albums = api.SearchAlbum(searchTerm); - return Response.AsJson(albums); + var releases = albums.releases ?? new List(); + var model = new List(); + foreach (var a in releases) + { + var coverArt = api.GetCoverArt(a.id); + var firstImage = coverArt?.images?.FirstOrDefault(); + var img = string.Empty; + + if (firstImage != null) + { + img = firstImage.thumbnails?.small ?? firstImage.image; + } + model.Add(new SearchMusicViewModel + { + Title = a.title, + Id = a.id, + Artist = a.ArtistCredit?.Select(x => x.artist?.name).FirstOrDefault(), + Overview = a.disambiguation, + ReleaseDate = a.date, + TrackCount = a.TrackCount, + CoverArtUrl = img, + ReleaseType = a.status, + Country = a.country + }); + } + return Response.AsJson(model); } private Response UpcomingMovies() // TODO : Not used @@ -448,5 +475,12 @@ namespace PlexRequests.UI.Modules var result = Checker.IsAvailable(title, year); return result; } + + private Response RequestAlbum(string releaseId) + { + // TODO need to send to Headphones + + return Response.AsJson(""); + } } } \ No newline at end of file diff --git a/PlexRequests.UI/PlexRequests.UI.csproj b/PlexRequests.UI/PlexRequests.UI.csproj index 9a32ef2b3..6d08abb12 100644 --- a/PlexRequests.UI/PlexRequests.UI.csproj +++ b/PlexRequests.UI/PlexRequests.UI.csproj @@ -171,6 +171,7 @@ + diff --git a/PlexRequests.UI/Views/Search/Index.cshtml b/PlexRequests.UI/Views/Search/Index.cshtml index 42d4d30a1..aea09d6ac 100644 --- a/PlexRequests.UI/Views/Search/Index.cshtml +++ b/PlexRequests.UI/Views/Search/Index.cshtml @@ -14,7 +14,7 @@ } @if (Model.SearchForMusic) { -
  • Music
  • +
  • Albums
  • } @@ -73,7 +73,7 @@
    - +
    @@ -160,17 +160,21 @@