mirror of
https://github.com/Ombi-app/Ombi.git
synced 2025-07-13 00:32:57 -07:00
Started adding the api part for headphones #32
This commit is contained in:
parent
1332cc6d40
commit
e9d0ccd5c0
5 changed files with 184 additions and 0 deletions
45
PlexRequests.Api.Models/Music/HeadphonesAlbumSearchResult.cs
Normal file
45
PlexRequests.Api.Models/Music/HeadphonesAlbumSearchResult.cs
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: HeadphonesAlbumSearchResult.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 HeadphonesAlbumSearchResult
|
||||||
|
{
|
||||||
|
public string rgid { get; set; }
|
||||||
|
public string albumurl { get; set; }
|
||||||
|
public string tracks { get; set; }
|
||||||
|
public string date { get; set; }
|
||||||
|
public string id { get; set; } // Artist ID
|
||||||
|
public string rgtype { get; set; }
|
||||||
|
public string title { get; set; }
|
||||||
|
public string url { get; set; }
|
||||||
|
public string country { get; set; }
|
||||||
|
public string albumid { get; set; } // AlbumId
|
||||||
|
public int score { get; set; }
|
||||||
|
public string uniquename { get; set; }
|
||||||
|
public string formats { get; set; }
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,37 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: HeadphonesSearchResult.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 HeadphonesArtistSearchResult
|
||||||
|
{
|
||||||
|
public string url { get; set; } // MusicBrainz url
|
||||||
|
public int score { get; set; } // Search Match score?
|
||||||
|
public string name { get; set; } // Artist Name
|
||||||
|
public string uniquename { get; set; } // Artist Unique Name
|
||||||
|
public string id { get; set; } // Artist Unique ID for MusicBrainz
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,6 +48,8 @@
|
||||||
<Compile Include="Movie\CouchPotatoAdd.cs" />
|
<Compile Include="Movie\CouchPotatoAdd.cs" />
|
||||||
<Compile Include="Movie\CouchPotatoProfiles.cs" />
|
<Compile Include="Movie\CouchPotatoProfiles.cs" />
|
||||||
<Compile Include="Movie\CouchPotatoStatus.cs" />
|
<Compile Include="Movie\CouchPotatoStatus.cs" />
|
||||||
|
<Compile Include="Music\HeadphonesAlbumSearchResult.cs" />
|
||||||
|
<Compile Include="Music\HeadphonesArtistSearchResult.cs" />
|
||||||
<Compile Include="Notifications\PushbulletPush.cs" />
|
<Compile Include="Notifications\PushbulletPush.cs" />
|
||||||
<Compile Include="Notifications\PushbulletResponse.cs" />
|
<Compile Include="Notifications\PushbulletResponse.cs" />
|
||||||
<Compile Include="Notifications\PushoverResponse.cs" />
|
<Compile Include="Notifications\PushoverResponse.cs" />
|
||||||
|
|
99
PlexRequests.Api/HeadphonesApi.cs
Normal file
99
PlexRequests.Api/HeadphonesApi.cs
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
#region Copyright
|
||||||
|
// /************************************************************************
|
||||||
|
// Copyright (c) 2016 Jamie Rees
|
||||||
|
// File: CouchPotatoApi.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;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
using NLog;
|
||||||
|
using PlexRequests.Api.Interfaces;
|
||||||
|
using PlexRequests.Api.Models.Music;
|
||||||
|
using PlexRequests.Api.Models.Sonarr;
|
||||||
|
using PlexRequests.Helpers;
|
||||||
|
|
||||||
|
using RestSharp;
|
||||||
|
|
||||||
|
namespace PlexRequests.Api
|
||||||
|
{
|
||||||
|
public class HeadphonesApi
|
||||||
|
{
|
||||||
|
public HeadphonesApi()
|
||||||
|
{
|
||||||
|
Api = new ApiRequest();
|
||||||
|
}
|
||||||
|
private ApiRequest Api { get; }
|
||||||
|
private static Logger Log = LogManager.GetCurrentClassLogger();
|
||||||
|
|
||||||
|
public List<HeadphonesAlbumSearchResult> SearchAlbum(string apiKey, Uri baseUrl, string searchTerm)
|
||||||
|
{
|
||||||
|
Log.Trace("Searching for album: {0}", searchTerm);
|
||||||
|
var request = new RestRequest
|
||||||
|
{
|
||||||
|
Resource = "/api?cmd=findAlbum&name={searchTerm}",
|
||||||
|
Method = Method.GET
|
||||||
|
};
|
||||||
|
|
||||||
|
request.AddQueryParameter("apikey", apiKey);
|
||||||
|
request.AddUrlSegment("searchTerm", searchTerm);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return Api.ExecuteJson<List<HeadphonesAlbumSearchResult>>(request, baseUrl);
|
||||||
|
}
|
||||||
|
catch (JsonSerializationException jse)
|
||||||
|
{
|
||||||
|
Log.Warn(jse);
|
||||||
|
return new List<HeadphonesAlbumSearchResult>(); // If there is no matching result we do not get returned a JSON string, it just returns "false".
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool AddAlbum(string apiKey, Uri baseUrl, string albumId)
|
||||||
|
{
|
||||||
|
Log.Trace("Adding album: {0}", albumId);
|
||||||
|
var request = new RestRequest
|
||||||
|
{
|
||||||
|
Resource = "/api?cmd=addAlbum&id={albumId}",
|
||||||
|
Method = Method.GET
|
||||||
|
};
|
||||||
|
|
||||||
|
request.AddQueryParameter("apikey", apiKey);
|
||||||
|
request.AddUrlSegment("albumId", albumId);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
//var result = Api.Execute<string>(request, baseUrl);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
catch (JsonSerializationException jse)
|
||||||
|
{
|
||||||
|
Log.Warn(jse);
|
||||||
|
return false; // If there is no matching result we do not get returned a JSON string, it just returns "false".
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -75,6 +75,7 @@
|
||||||
<Compile Include="PushoverApi.cs" />
|
<Compile Include="PushoverApi.cs" />
|
||||||
<Compile Include="PushbulletApi.cs" />
|
<Compile Include="PushbulletApi.cs" />
|
||||||
<Compile Include="SickrageApi.cs" />
|
<Compile Include="SickrageApi.cs" />
|
||||||
|
<Compile Include="HeadphonesApi.cs" />
|
||||||
<Compile Include="SonarrApi.cs" />
|
<Compile Include="SonarrApi.cs" />
|
||||||
<Compile Include="CouchPotatoApi.cs" />
|
<Compile Include="CouchPotatoApi.cs" />
|
||||||
<Compile Include="MovieBase.cs" />
|
<Compile Include="MovieBase.cs" />
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue