Most of the UI work done for #32

pull/130/head
tidusjar 9 years ago
parent 1596dce629
commit c43f70a0e0

@ -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<string> 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<Image> images { get; set; }
public string release { get; set; }
}
}

@ -50,6 +50,7 @@
<Compile Include="Movie\CouchPotatoStatus.cs" /> <Compile Include="Movie\CouchPotatoStatus.cs" />
<Compile Include="Music\HeadphonesAlbumSearchResult.cs" /> <Compile Include="Music\HeadphonesAlbumSearchResult.cs" />
<Compile Include="Music\HeadphonesArtistSearchResult.cs" /> <Compile Include="Music\HeadphonesArtistSearchResult.cs" />
<Compile Include="Music\MusicBrainzCoverArt.cs" />
<Compile Include="Music\MusicBrainzSearchResults.cs" /> <Compile Include="Music\MusicBrainzSearchResults.cs" />
<Compile Include="Notifications\PushbulletPush.cs" /> <Compile Include="Notifications\PushbulletPush.cs" />
<Compile Include="Notifications\PushbulletResponse.cs" /> <Compile Include="Notifications\PushbulletResponse.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". 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<MusicBrainzCoverArt>(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".
}
}
} }
} }

@ -72,7 +72,7 @@ namespace PlexRequests.Core
s.SaveSettings(defaultSettings); s.SaveSettings(defaultSettings);
} }
private void MigrateDb() // TODO: Remove when no longer needed private void MigrateDb() // TODO: Remove in v1.7
{ {
var result = new List<long>(); var result = new List<long>();
RequestedModel[] requestedModels; RequestedModel[] requestedModels;

@ -201,8 +201,8 @@ function getMusic(url) {
$("#musicList").html(""); $("#musicList").html("");
$.ajax(url).success(function (results) { $.ajax(url).success(function (results) {
if (results.count > 0) { if (results.length > 0) {
results.releases.forEach(function (result) { results.forEach(function (result) {
var context = buildMusicContext(result); var context = buildMusicContext(result);
var html = musicTemplate(context); var html = musicTemplate(context);
@ -254,9 +254,14 @@ function buildMusicContext(result) {
var context = { var context = {
id: result.id, id: result.id,
title: result.title, title: result.title,
overview: result.disambiguation, overview: result.overview,
year: result.date, year: result.releaseDate,
type: "music" type: "album",
trackCount: result.trackCount,
coverArtUrl: result.coverArtUrl,
artist: result.artist,
releaseType: result.releaseType,
country: result.country
}; };
return context; return context;

@ -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; }
}
}

@ -36,6 +36,7 @@ using NLog;
using PlexRequests.Api; using PlexRequests.Api;
using PlexRequests.Api.Interfaces; using PlexRequests.Api.Interfaces;
using PlexRequests.Api.Models.Music;
using PlexRequests.Core; using PlexRequests.Core;
using PlexRequests.Core.SettingModels; using PlexRequests.Core.SettingModels;
using PlexRequests.Helpers; using PlexRequests.Helpers;
@ -81,6 +82,7 @@ namespace PlexRequests.UI.Modules
Post["request/movie"] = parameters => RequestMovie((int)Request.Form.movieId); Post["request/movie"] = parameters => RequestMovie((int)Request.Form.movieId);
Post["request/tv"] = parameters => RequestTvShow((int)Request.Form.tvId, (string)Request.Form.seasons); 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 TheMovieDbApi MovieApi { get; }
private INotificationService NotificationService { get; } private INotificationService NotificationService { get; }
@ -157,7 +159,32 @@ namespace PlexRequests.UI.Modules
{ {
var api = new MusicBrainsApi(); var api = new MusicBrainsApi();
var albums = api.SearchAlbum(searchTerm); var albums = api.SearchAlbum(searchTerm);
return Response.AsJson(albums); var releases = albums.releases ?? new List<Release>();
var model = new List<SearchMusicViewModel>();
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 private Response UpcomingMovies() // TODO : Not used
@ -448,5 +475,12 @@ namespace PlexRequests.UI.Modules
var result = Checker.IsAvailable(title, year); var result = Checker.IsAvailable(title, year);
return result; return result;
} }
private Response RequestAlbum(string releaseId)
{
// TODO need to send to Headphones
return Response.AsJson("");
}
} }
} }

@ -171,6 +171,7 @@
<Compile Include="Helpers\TvSender.cs" /> <Compile Include="Helpers\TvSender.cs" />
<Compile Include="Helpers\ValidationHelper.cs" /> <Compile Include="Helpers\ValidationHelper.cs" />
<Compile Include="Models\DatatablesModel.cs" /> <Compile Include="Models\DatatablesModel.cs" />
<Compile Include="Models\SearchMusicViewModel.cs" />
<Compile Include="Validators\PushoverSettingsValidator.cs" /> <Compile Include="Validators\PushoverSettingsValidator.cs" />
<Compile Include="Validators\PushbulletSettingsValidator.cs" /> <Compile Include="Validators\PushbulletSettingsValidator.cs" />
<Compile Include="Validators\EmailNotificationSettingsValidator.cs" /> <Compile Include="Validators\EmailNotificationSettingsValidator.cs" />

@ -14,7 +14,7 @@
} }
@if (Model.SearchForMusic) @if (Model.SearchForMusic)
{ {
<li role="presentation"><a href="#MusicTab" aria-controls="profile" role="tab" data-toggle="tab">Music</a></li> <li role="presentation"><a href="#MusicTab" aria-controls="profile" role="tab" data-toggle="tab">Albums</a></li>
} }
</ul> </ul>
@ -73,7 +73,7 @@
<!-- Music tab --> <!-- Music tab -->
<div role="tabpanel" class="tab-pane" id="MusicTab"> <div role="tabpanel" class="tab-pane" id="MusicTab">
<div class="input-group"> <div class="input-group">
<input id="musicSearchContent" type="text" class="form-control form-control-custom"> <input id="musicSearchContent" type="text" class="form-control form-control-custom form-control-search">
<div class="input-group-addon"> <div class="input-group-addon">
<i id="musicSearchButton" class="fa fa-search"></i> <i id="musicSearchButton" class="fa fa-search"></i>
</div> </div>
@ -160,17 +160,21 @@
<script id="music-template" type="text/x-handlebars-template"> <script id="music-template" type="text/x-handlebars-template">
<div class="row"> <div class="row">
<div class="col-sm-2"> <div class="col-sm-2">
{{#if coverArtUrl}}
@*<img class="img-responsive" src="http://image.tmdb.org/t/p/w150/{{posterPath}}" alt="poster">*@ <img class="img-responsive" src="{{coverArtUrl}}" width="150" alt="poster">
{{/if}}
</div> </div>
<div class="col-sm-5 "> <div class="col-sm-5 ">
<div> <div>
<a href="https://musicbrainz.org/release/{{id}}" target="_blank">
<h4>
{{artist}} - {{title}}
{{#if year}}
({{year}})
{{/if}}
</h4>
</a>
@*<a href="http://www.imdb.com/title/{{imdb}}/" target="_blank">*@
<h4>{{title}} ({{year}})</h4>
@*</a>*@
</div> </div>
<p>{{overview}}</p> <p>{{overview}}</p>
</div> </div>
@ -179,10 +183,9 @@
<input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" /> <input name="{{type}}Id" type="text" value="{{id}}" hidden="hidden" />
<button id="{{id}}" style="text-align: right" class="btn btn-primary-outline requestMusic" type="submit"><i class="fa fa-plus"></i> Request</button> <button id="{{id}}" style="text-align: right" class="btn btn-primary-outline requestMusic" type="submit"><i class="fa fa-plus"></i> Request</button>
<br />
<br />
<br /> <br />
<small class="row">Track Count: {{trackCount}}</small>
<small class="row">Country: {{country}}</small>
</form> </form>
</div> </div>

Loading…
Cancel
Save