|
|
@ -1,6 +1,9 @@
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
using NLog;
|
|
|
|
using NLog;
|
|
|
|
using NzbDrone.Common.Http;
|
|
|
|
using NzbDrone.Common.Http;
|
|
|
|
using NzbDrone.Common.Serializer;
|
|
|
|
using NzbDrone.Common.Serializer;
|
|
|
|
|
|
|
|
using NzbDrone.Core.Notifications.MediaBrowser.Model;
|
|
|
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Core.Notifications.Emby
|
|
|
|
namespace NzbDrone.Core.Notifications.Emby
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -20,22 +23,52 @@ namespace NzbDrone.Core.Notifications.Emby
|
|
|
|
var path = "/Notifications/Admin";
|
|
|
|
var path = "/Notifications/Admin";
|
|
|
|
var request = BuildRequest(path, settings);
|
|
|
|
var request = BuildRequest(path, settings);
|
|
|
|
request.Headers.ContentType = "application/json";
|
|
|
|
request.Headers.ContentType = "application/json";
|
|
|
|
|
|
|
|
request.Method = HttpMethod.POST;
|
|
|
|
|
|
|
|
|
|
|
|
request.SetContent(new
|
|
|
|
request.SetContent(new
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Name = title,
|
|
|
|
Name = title,
|
|
|
|
Description = message,
|
|
|
|
Description = message,
|
|
|
|
ImageUrl = "https://raw.github.com/lidarr/Lidarr/develop/Logo/64.png"
|
|
|
|
ImageUrl = "https://raw.github.com/lidarr/Lidarr/develop/Logo/64.png"
|
|
|
|
}.ToJson());
|
|
|
|
}.ToJson());
|
|
|
|
|
|
|
|
|
|
|
|
ProcessRequest(request, settings);
|
|
|
|
ProcessRequest(request, settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Update(MediaBrowserSettings settings, string mbId)
|
|
|
|
public void Update(MediaBrowserSettings settings, List<string> musicCollectionPaths)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var path = string.Format("/Library/Artist/Updated?tvdbid={0}", mbId); //TODO: Get Emby to add a new Library Route
|
|
|
|
string path;
|
|
|
|
var request = BuildRequest(path, settings);
|
|
|
|
HttpRequest request;
|
|
|
|
request.Headers.Add("Content-Length", "0");
|
|
|
|
|
|
|
|
|
|
|
|
if (musicCollectionPaths.Any())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
path = "/Library/Media/Updated";
|
|
|
|
|
|
|
|
request = BuildRequest(path, settings);
|
|
|
|
|
|
|
|
request.Headers.ContentType = "application/json";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var updateInfo = new List<EmbyMediaUpdateInfo>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var colPath in musicCollectionPaths)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
updateInfo.Add(new EmbyMediaUpdateInfo
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Path = colPath,
|
|
|
|
|
|
|
|
UpdateType = "Created"
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
request.SetContent(new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Updates = updateInfo
|
|
|
|
|
|
|
|
}.ToJson());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
path = "/Library/Refresh";
|
|
|
|
|
|
|
|
request = BuildRequest(path, settings);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
request.Method = HttpMethod.POST;
|
|
|
|
|
|
|
|
|
|
|
|
ProcessRequest(request, settings);
|
|
|
|
ProcessRequest(request, settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -44,7 +77,8 @@ namespace NzbDrone.Core.Notifications.Emby
|
|
|
|
{
|
|
|
|
{
|
|
|
|
request.Headers.Add("X-MediaBrowser-Token", settings.ApiKey);
|
|
|
|
request.Headers.Add("X-MediaBrowser-Token", settings.ApiKey);
|
|
|
|
|
|
|
|
|
|
|
|
var response = _httpClient.Post(request);
|
|
|
|
var response = _httpClient.Execute(request);
|
|
|
|
|
|
|
|
|
|
|
|
_logger.Trace("Response: {0}", response.Content);
|
|
|
|
_logger.Trace("Response: {0}", response.Content);
|
|
|
|
|
|
|
|
|
|
|
|
CheckForError(response);
|
|
|
|
CheckForError(response);
|
|
|
@ -55,7 +89,7 @@ namespace NzbDrone.Core.Notifications.Emby
|
|
|
|
private HttpRequest BuildRequest(string path, MediaBrowserSettings settings)
|
|
|
|
private HttpRequest BuildRequest(string path, MediaBrowserSettings settings)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var url = string.Format(@"http://{0}/mediabrowser", settings.Address);
|
|
|
|
var url = string.Format(@"http://{0}/mediabrowser", settings.Address);
|
|
|
|
|
|
|
|
|
|
|
|
return new HttpRequestBuilder(url).Resource(path).Build();
|
|
|
|
return new HttpRequestBuilder(url).Resource(path).Build();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -65,5 +99,16 @@ namespace NzbDrone.Core.Notifications.Emby
|
|
|
|
|
|
|
|
|
|
|
|
//TODO: actually check for the error
|
|
|
|
//TODO: actually check for the error
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public List<EmbyMediaFolder> GetArtist(MediaBrowserSettings settings)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var path = "/Library/MediaFolders";
|
|
|
|
|
|
|
|
var request = BuildRequest(path, settings);
|
|
|
|
|
|
|
|
request.Method = HttpMethod.GET;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var response = ProcessRequest(request, settings);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Json.Deserialize<EmbyMediaFoldersResponse>(response).Items;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|