added mapping to emby and plex nodes

added ability to override server/token/mapping for emby/plex nodes
This commit is contained in:
John Andrews
2022-04-22 14:10:57 +12:00
parent aa8b988182
commit 419fc66af2
29 changed files with 126 additions and 13 deletions

View File

@@ -10,16 +10,30 @@ public class PlexUpdater: Node
public override FlowElementType Type => FlowElementType.Process;
public override string Icon => "fas fa-paper-plane";
public override bool NoEditorOnAdd => true;
[Text(1)]
public string ServerUrl { get; set; }
[Text(2)]
public string AccessToken { get; set; }
[KeyValue(3)]
public List<KeyValuePair<string, string>> Mapping { get; set; }
public override int Execute(NodeParameters args)
{
var settings = args.GetPluginSettings<PluginSettings>();
string serverUrl = ServerUrl?.EmptyAsNull() ?? settings.ServerUrl;
string accessToken = AccessToken?.EmptyAsNull() ?? settings.AccessToken;
var mapping = (string.IsNullOrWhiteSpace(ServerUrl) ? settings.Mapping : Mapping) ?? new List<KeyValuePair<string, string>>();
if (string.IsNullOrWhiteSpace(settings?.AccessToken))
if (string.IsNullOrWhiteSpace(accessToken))
{
args.Logger?.WLog("No access token set");
return 2;
}
if (string.IsNullOrWhiteSpace(settings?.ServerUrl))
if (string.IsNullOrWhiteSpace(serverUrl))
{
args.Logger?.WLog("No server URL set");
return 2;
@@ -35,14 +49,14 @@ public class PlexUpdater: Node
path = path.Substring(0, path.LastIndexOf(pathSeparator));
}
string url = settings.ServerUrl;
string url = serverUrl;
if (url.EndsWith("/") == false)
url += "/";
url += "library/sections";
using var httpClient = new HttpClient();
var sectionsResponse= GetWebRequest(httpClient, url + "?X-Plex-Token=" + settings.AccessToken);
var sectionsResponse= GetWebRequest(httpClient, url + "?X-Plex-Token=" + accessToken);
if (sectionsResponse.success == false)
{
args.Logger?.WLog("Failed to retrieve sections" + (string.IsNullOrWhiteSpace(sectionsResponse.body) ? "" : ": " + sectionsResponse.body));
@@ -61,6 +75,14 @@ public class PlexUpdater: Node
args.Logger?.ELog("Failed deserializing sections json: " + ex.Message);
return 2;
}
foreach(var map in mapping)
{
if (string.IsNullOrEmpty(map.Key))
continue;
path = path.Replace(map.Key, map.Value ?? string.Empty);
}
string pathLower = path.ToLower();
var section = sections?.MediaContainer?.Directory?.Where(x => {
if (x.Location?.Any() != true)

Binary file not shown.

View File

@@ -7,7 +7,11 @@
"ServerUrl-Placeholder": "http://localhost:32400/",
"ServerUrl-Help": "The URL of the Plex server",
"AccessToken": "Access Token",
"AccessToken-Help": "The access token used to communicate with the Plex server.\nhttps://github.com/revenz/Fenrus/wiki/Plex-Token"
"AccessToken-Help": "The access token used to communicate with the Plex server.\nhttps://github.com/revenz/Fenrus/wiki/Plex-Token",
"Mapping": "Mapping",
"Mapping-Help": "A list of mapping replacement used to paths in FileFlows with the paths that are used in Plex.",
"MappingKey": "FileFlows",
"MappingValue": "Plex"
}
}
},
@@ -18,7 +22,18 @@
"1": "Plex update request sent",
"2": "Plex update request failed to send"
},
"Description": "Sends a message to a Plex server to update the library."
"Description": "Sends a message to a Plex server to update the library.",
"Fields": {
"ServerUrl": "Server",
"ServerUrl-Placeholder": "http://localhost:32400/",
"ServerUrl-Help": "The URL of the Plex server. If blank will use the Server defined in the Plugin settings.\nNote: Only set this if you want to override the plugin settings server URL.",
"AccessToken": "Access Token",
"AccessToken-Help": "The access token used to communicate with the Plex server.\nhttps://github.com/revenz/Fenrus/wiki/Plex-Token\nNote: Only set this if you want to override the plugin settings access token.",
"Mapping": "Mapping",
"Mapping-Help": "A list of mapping replacement used to paths in FileFlows with the paths that are used in Plex.\nNote: This will not be used unless the Server URL is also set here, otherwise the plugin settings mappings will be used.",
"MappingKey": "FileFlows",
"MappingValue": "Plex"
}
}
}
}

View File

@@ -14,5 +14,8 @@
[Text(2)]
[Required]
public string AccessToken { get; set; }
[KeyValue(3)]
public List<KeyValuePair<string, string>> Mapping { get; set; }
}
}

View File

@@ -33,6 +33,24 @@ public class PlexTests
var node = new PlexUpdater();
Assert.AreEqual(2, node.Execute(args));
}
[TestMethod]
public void Plex_Mapping()
{
var args = new NodeParameters(@"/mnt/movies/Citizen Kane (1941)/Citizen Kane (1941).mp4", new TestLogger(), false, string.Empty);
var settings = new PluginSettings();
settings.Mapping = new List<KeyValuePair<string, string>>();
settings.Mapping.Add(new KeyValuePair<string, string>("/mnt/movies", "/media/movies"));
args.GetPluginSettingsJson = (string input) =>
{
return File.ReadAllText("../../../settings.json");
};
var node = new PlexUpdater();
Assert.AreEqual(1, node.Execute(args));
}
}
#endif