Fixed: Update Emby Notification (#284)

pull/288/head
Qstick 7 years ago committed by GitHub
parent af090c7a3a
commit 1937a8e27c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -32,6 +32,11 @@ namespace NzbDrone.Core.Notifications.Emby
{
_mediaBrowserService.Notify(Settings, ALBUM_DOWNLOADED_TITLE_BRANDED, message.Message);
}
if (Settings.UpdateLibrary)
{
_mediaBrowserService.Update(Settings, message.Artist);
}
}
public override void OnDownload(TrackDownloadMessage message)
@ -40,11 +45,6 @@ namespace NzbDrone.Core.Notifications.Emby
{
_mediaBrowserService.Notify(Settings, TRACK_DOWNLOADED_TITLE_BRANDED, message.Message);
}
if (Settings.UpdateLibrary)
{
_mediaBrowserService.Update(Settings, message.Artist);
}
}
public override void OnRename(Artist artist)

@ -1,6 +1,9 @@
using System.Collections.Generic;
using System.Linq;
using NLog;
using NzbDrone.Common.Http;
using NzbDrone.Common.Serializer;
using NzbDrone.Core.Notifications.MediaBrowser.Model;
namespace NzbDrone.Core.Notifications.Emby
{
@ -20,6 +23,7 @@ namespace NzbDrone.Core.Notifications.Emby
var path = "/Notifications/Admin";
var request = BuildRequest(path, settings);
request.Headers.ContentType = "application/json";
request.Method = HttpMethod.POST;
request.SetContent(new
{
@ -31,11 +35,40 @@ namespace NzbDrone.Core.Notifications.Emby
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
var request = BuildRequest(path, settings);
request.Headers.Add("Content-Length", "0");
string path;
HttpRequest request;
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);
}
@ -44,7 +77,8 @@ namespace NzbDrone.Core.Notifications.Emby
{
request.Headers.Add("X-MediaBrowser-Token", settings.ApiKey);
var response = _httpClient.Post(request);
var response = _httpClient.Execute(request);
_logger.Trace("Response: {0}", response.Content);
CheckForError(response);
@ -65,5 +99,16 @@ namespace NzbDrone.Core.Notifications.Emby
//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;
}
}
}

@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Net;
using FluentValidation.Results;
using NLog;
@ -32,7 +33,11 @@ namespace NzbDrone.Core.Notifications.Emby
public void Update(MediaBrowserSettings settings, Artist artist)
{
_proxy.Update(settings, artist.ForeignArtistId);
var folders = _proxy.GetArtist(settings);
var musicPaths = folders.Select(e => e.CollectionType = "music").ToList();
_proxy.Update(settings, musicPaths);
}
public ValidationFailure Test(MediaBrowserSettings settings)

@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace NzbDrone.Core.Notifications.MediaBrowser.Model
{
public class EmbyMediaFolder
{
public string Path { get; set; }
public string CollectionType { get; set; }
}
}

@ -0,0 +1,9 @@
using System.Collections.Generic;
namespace NzbDrone.Core.Notifications.MediaBrowser.Model
{
public class EmbyMediaFoldersResponse
{
public List<EmbyMediaFolder> Items { get; set; }
}
}

@ -0,0 +1,10 @@
using System.Collections.Generic;
namespace NzbDrone.Core.Notifications.MediaBrowser.Model
{
public class EmbyMediaUpdateInfo
{
public string Path { get; set; }
public string UpdateType { get; set; }
}
}

@ -873,6 +873,9 @@
<Compile Include="Notifications\Boxcar\BoxcarProxy.cs" />
<Compile Include="Notifications\Boxcar\BoxcarSettings.cs" />
<Compile Include="Notifications\GrabMessage.cs" />
<Compile Include="Notifications\MediaBrowser\Model\EmbyMediaFolder.cs" />
<Compile Include="Notifications\MediaBrowser\Model\EmbyMediaFoldersResponse.cs" />
<Compile Include="Notifications\MediaBrowser\Model\EmbyMediaUpdateInfo.cs" />
<Compile Include="Notifications\Plex\Models\PlexIdentity.cs" />
<Compile Include="Notifications\Plex\Models\PlexResponse.cs" />
<Compile Include="Notifications\Plex\Models\PlexPreferences.cs" />

Loading…
Cancel
Save