pull/140/head
tidusjar 9 years ago
parent 8bd0464bef
commit acb39b56f8

@ -25,11 +25,13 @@
// ************************************************************************/
#endregion
using System;
using PlexRequests.Api.Models.Music;
namespace PlexRequests.Api.Interfaces
{
public interface IHeadphonesApi
{
bool AddAlbum(string apiKey, Uri baseUrl, string albumId);
HeadphonesVersion GetVersion(string apiKey, Uri baseUrl);
}
}

@ -0,0 +1,37 @@
#region Copyright
// /************************************************************************
// Copyright (c) 2016 Jamie Rees
// File: HeadphonesVersion.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.Api.Models.Music
{
public class HeadphonesVersion
{
public string install_type { get; set; }
public object current_version { get; set; }
public string git_path { get; set; }
public string latest_version { get; set; }
public int commits_behind { get; set; }
}
}

@ -59,7 +59,7 @@ namespace PlexRequests.Api.Models.Music
public string disambiguation { get; set; }
[JsonProperty(PropertyName = "release-events")]
public List<ReleaseEvent> ReleaseRvents { get; set; }
public List<ReleaseEvent> ReleaseEvents { get; set; }
public string id { get; set; }
}

@ -50,6 +50,7 @@
<Compile Include="Movie\CouchPotatoStatus.cs" />
<Compile Include="Music\HeadphonesAlbumSearchResult.cs" />
<Compile Include="Music\HeadphonesArtistSearchResult.cs" />
<Compile Include="Music\HeadphonesVersion.cs" />
<Compile Include="Music\MusicBrainzCoverArt.cs" />
<Compile Include="Music\MusicBrainzReleaseInfo.cs" />
<Compile Include="Music\MusicBrainzSearchResults.cs" />

@ -70,5 +70,27 @@ namespace PlexRequests.Api
return false; // If there is no matching result we do not get returned a JSON string, it just returns "false".
}
}
public HeadphonesVersion GetVersion(string apiKey, Uri baseUrl)
{
var request = new RestRequest
{
Resource = "/api",
Method = Method.GET
};
request.AddQueryParameter("apikey", apiKey);
request.AddQueryParameter("cmd", "getVersion");
try
{
return Api.ExecuteJson<HeadphonesVersion>(request, baseUrl);
}
catch (JsonSerializationException jse)
{
Log.Warn(jse);
return new HeadphonesVersion(); // If there is no matching result we do not get returned a JSON string, it just returns "false".
}
}
}
}

@ -1,4 +1,5 @@
using System;
using System.Globalization;
using System.Linq;
namespace PlexRequests.Helpers
@ -17,6 +18,21 @@ namespace PlexRequests.Helpers
return new DateTimeOffset(newDate.Ticks, utcOffset);
}
public static void CustomParse(string date, out DateTime dt)
{
// Try and parse it
if (DateTime.TryParse(date, out dt))
{
return;
}
// Maybe it's only a year?
if (DateTime.TryParseExact(date, "yyyy", CultureInfo.CurrentCulture, DateTimeStyles.None, out dt))
{
return;
}
}
private static TimeZoneInfo FindTimeZoneFromOffset(int minuteOffset)
{
var tzc = TimeZoneInfo.GetSystemTimeZones();

@ -38,6 +38,7 @@ namespace PlexRequests.Store
public string SeasonsRequested { get; set; }
public string MusicBrainzId { get; set; }
public List<string> RequestedUsers { get; set; }
public string Artist { get; set; }
[JsonIgnore]
public List<string> AllUsers

@ -447,7 +447,7 @@ function albumLoad() {
if (results.length > 0) {
results.forEach(function (result) {
var context = buildRequestContext(result, "album");
var html = searchTemplate(context);
var html = albumTemplate(context);
$albumL.append(html);
});
}
@ -482,7 +482,7 @@ function buildRequestContext(result, type) {
adminNote: result.adminNotes,
imdb: result.imdbId,
seriesRequested: result.tvSeriesRequestType,
coverArtUrl: result.coverArtUrl,
artist:
};

@ -43,7 +43,7 @@ namespace PlexRequests.UI.Modules
{
public ApplicationTesterModule(ICouchPotatoApi cpApi, ISonarrApi sonarrApi, IPlexApi plexApi,
ISettingsService<AuthenticationSettings> authSettings, ISickRageApi srApi) : base("test")
ISettingsService<AuthenticationSettings> authSettings, ISickRageApi srApi, IHeadphonesApi hpApi) : base("test")
{
this.RequiresAuthentication();
@ -52,6 +52,7 @@ namespace PlexRequests.UI.Modules
PlexApi = plexApi;
AuthSettings = authSettings;
SickRageApi = srApi;
HeadphonesApi = hpApi;
Post["/cp"] = _ => CouchPotatoTest();
Post["/sonarr"] = _ => SonarrTest();
@ -66,6 +67,7 @@ namespace PlexRequests.UI.Modules
private ICouchPotatoApi CpApi { get; }
private IPlexApi PlexApi { get; }
private ISickRageApi SickRageApi { get; }
private IHeadphonesApi HeadphonesApi { get; }
private ISettingsService<AuthenticationSettings> AuthSettings { get; }
private Response CouchPotatoTest()
@ -172,7 +174,32 @@ namespace PlexRequests.UI.Modules
private Response HeadphonesTest()
{
throw new NotImplementedException(); //TODO
var settings = this.Bind<HeadphonesSettings>();
try
{
var result = HeadphonesApi.GetVersion(settings.ApiKey, settings.FullUri);
if (!string.IsNullOrEmpty(result.latest_version))
{
return
Response.AsJson(new JsonResponseModel
{
Result = true,
Message = "Connected to Headphones successfully!"
});
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = "Could not connect to Headphones, please check your settings." });
}
catch (ApplicationException e)
{
Log.Warn("Exception thrown when attempting to get Headphones's status: ");
Log.Warn(e);
var message = $"Could not connect to Headphones, please check your settings. <strong>Exception Message:</strong> {e.Message}";
if (e.InnerException != null)
{
message = $"Could not connect to Headphones, please check your settings. <strong>Exception Message:</strong> {e.InnerException.Message}";
}
return Response.AsJson(new JsonResponseModel { Result = false, Message = message }); ;
}
}
}
}

@ -503,6 +503,9 @@ namespace PlexRequests.UI.Modules
Log.Trace("CoverArt Details:");
Log.Trace(img.DumpJson());
DateTime release;
DateTimeHelper.CustomParse(albumInfo.ReleaseEvents?.FirstOrDefault()?.date, out release);
var model = new RequestedModel
{
Title = albumInfo.title,
@ -513,7 +516,10 @@ namespace PlexRequests.UI.Modules
ProviderId = 0,
RequestedUsers = new List<string>() { Username },
Status = albumInfo.status,
Issues = IssueState.None
Issues = IssueState.None,
RequestedDate = DateTime.UtcNow,
ReleaseDate = release,
Artist = albumInfo.
};

@ -3,7 +3,7 @@
int port;
if (Model.Port == 0)
{
port = 8081;
port = 8181;
}
else
{
@ -72,13 +72,6 @@
</div>
<div class="form-group">
<div>
<button type="submit" id="getProfiles" class="btn btn-primary-outline">Get Quality Profiles</button>
</div>
</div>
<div class="form-group">
<div>
<button id="testHeadphones" type="submit" class="btn btn-primary-outline">Test Connectivity</button>
@ -86,8 +79,6 @@
</div>
<div class="form-group">
<div>
<button id="save" type="submit" class="btn btn-primary-outline">Submit</button>
@ -115,7 +106,6 @@
console.log(response);
if (response.result === true) {
generateNotify(response.message, "success");
$('#authToken').val(response.authToken);
} else {
generateNotify(response.message, "warning");
}

@ -237,8 +237,8 @@
<div id="{{requestId}}Template" class="mix available-{{available}} approved-{{approved}}" data-requestorder="{{requestedDateTicks}}" data-releaseorder="{{releaseDateTicks}}">
<div class="row">
<div class="col-sm-2">
{{#if coverArtUrl}}
<img class="img-responsive" src="{{coverArtUrl}}" width="150" alt="poster">
{{#if posterPath}}
<img class="img-responsive" src="{{posterPath}}" width="150" alt="poster">
{{/if}}
</div>
<div class="col-sm-5 ">

@ -17,7 +17,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
ProjectSection(SolutionItems) = preProject
.travis.yml = .travis.yml
appveyor.yml = appveyor.yml
.github\ISSUE_TEMPLATE.md = .github\ISSUE_TEMPLATE.md
LICENSE = LICENSE
README.md = README.md
EndProjectSection
@ -32,10 +31,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.Services", "Pl
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.Api.Models", "PlexRequests.Api.Models\PlexRequests.Api.Models.csproj", "{CB37A5F8-6DFC-4554-99D3-A42B502E4591}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.Services.Tests", "PlexRequests.Services.Tests\PlexRequests.Services.Tests.csproj", "{EAADB4AC-064F-4D3A-AFF9-64A33131A9A7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PlexRequests.Helpers.Tests", "PlexRequests.Helpers.Tests\PlexRequests.Helpers.Tests.csproj", "{0E6395D3-B074-49E8-898D-0EB99E507E0E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -82,14 +77,6 @@ Global
{CB37A5F8-6DFC-4554-99D3-A42B502E4591}.Debug|Any CPU.Build.0 = Debug|Any CPU
{CB37A5F8-6DFC-4554-99D3-A42B502E4591}.Release|Any CPU.ActiveCfg = Release|Any CPU
{CB37A5F8-6DFC-4554-99D3-A42B502E4591}.Release|Any CPU.Build.0 = Release|Any CPU
{EAADB4AC-064F-4D3A-AFF9-64A33131A9A7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EAADB4AC-064F-4D3A-AFF9-64A33131A9A7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EAADB4AC-064F-4D3A-AFF9-64A33131A9A7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EAADB4AC-064F-4D3A-AFF9-64A33131A9A7}.Release|Any CPU.Build.0 = Release|Any CPU
{0E6395D3-B074-49E8-898D-0EB99E507E0E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E6395D3-B074-49E8-898D-0EB99E507E0E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E6395D3-B074-49E8-898D-0EB99E507E0E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E6395D3-B074-49E8-898D-0EB99E507E0E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

Loading…
Cancel
Save