mirror of
https://github.com/revenz/FileFlowsPlugins.git
synced 2026-05-08 20:59:13 -05:00
added mapping to emby and plex nodes
added ability to override server/token/mapping for emby/plex nodes
This commit is contained in:
Binary file not shown.
+17
-2
@@ -7,7 +7,11 @@
|
||||
"ServerUrl-Placeholder": "http://localhost:8096/",
|
||||
"ServerUrl-Help": "The URL of the Emby server",
|
||||
"AccessToken": "Access Token",
|
||||
"AccessToken-Help": "An Emby API access token"
|
||||
"AccessToken-Help": "An Emby API access token",
|
||||
"Mapping": "Mapping",
|
||||
"Mapping-Help": "A list of mapping replacement used to paths in FileFlows with the paths that are used in Emby.",
|
||||
"MappingKey": "FileFlows",
|
||||
"MappingValue": "Emby"
|
||||
}
|
||||
}
|
||||
},
|
||||
@@ -18,7 +22,18 @@
|
||||
"1": "Emby update request sent",
|
||||
"2": "Emby update request failed to send"
|
||||
},
|
||||
"Description": "Sends a message to a Emby server to update the library."
|
||||
"Description": "Sends a message to a Emby server to update the library.",
|
||||
"Fields": {
|
||||
"ServerUrl": "Server",
|
||||
"ServerUrl-Placeholder": "http://localhost:8096/",
|
||||
"ServerUrl-Help": "The URL of the Emby server.\nNote: Only set this if you want to override the plugin settings Server URL.",
|
||||
"AccessToken": "Access Token",
|
||||
"AccessToken-Help": "An Emby API access 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 Emby.\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": "Emby"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text.RegularExpressions;
|
||||
using FileFlows.Plugin.Attributes;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace FileFlows.Emby.MediaManagement;
|
||||
|
||||
@@ -9,16 +10,30 @@ public class EmbyUpdater: 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;
|
||||
@@ -27,6 +42,14 @@ public class EmbyUpdater: Node
|
||||
// get the path
|
||||
string path = args.WorkingFile;
|
||||
path = args.UnMapPath(path);
|
||||
|
||||
foreach (var map in mapping)
|
||||
{
|
||||
if (string.IsNullOrEmpty(map.Key))
|
||||
continue;
|
||||
path = path.Replace(map.Key, map.Value ?? string.Empty);
|
||||
}
|
||||
|
||||
if (args.IsDirectory == false)
|
||||
{
|
||||
bool windows = path.StartsWith("\\") || Regex.IsMatch(path, @"^[a-zA-Z]:\\");
|
||||
@@ -34,7 +57,8 @@ public class EmbyUpdater: Node
|
||||
path = path.Substring(0, path.LastIndexOf(pathSeparator));
|
||||
}
|
||||
|
||||
string url = settings.ServerUrl;
|
||||
|
||||
string url = serverUrl;
|
||||
if (url.EndsWith("/") == false)
|
||||
url += "/";
|
||||
url += "Library/Media/Updated";
|
||||
@@ -45,7 +69,7 @@ public class EmbyUpdater: Node
|
||||
|
||||
using var httpClient = new HttpClient();
|
||||
|
||||
var updateResponse = GetWebRequest(httpClient, url, settings.AccessToken, body);
|
||||
var updateResponse = GetWebRequest(httpClient, url, accessToken, body);
|
||||
if (updateResponse.success == false)
|
||||
{
|
||||
if(string.IsNullOrWhiteSpace(updateResponse.body) == false)
|
||||
|
||||
@@ -13,5 +13,8 @@
|
||||
[Text(2)]
|
||||
[Required]
|
||||
public string AccessToken { get; set; }
|
||||
|
||||
[KeyValue(3)]
|
||||
public List<KeyValuePair<string, string>> Mapping { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,6 +33,19 @@ public class EmbyTests
|
||||
var node = new EmbyUpdater();
|
||||
Assert.AreEqual(2, node.Execute(args));
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Emby_Mapped()
|
||||
{
|
||||
var args = new NodeParameters(@"/mnt/movies/Citizen Kane (1941)/Citizen Kane (1941).mp4", new TestLogger(), false, string.Empty);
|
||||
args.GetPluginSettingsJson = (string input) =>
|
||||
{
|
||||
return File.ReadAllText("../../../settings.json");
|
||||
};
|
||||
|
||||
var node = new EmbyUpdater();
|
||||
Assert.AreEqual(1, node.Execute(args));
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user